glyphy
glyphy copied to clipboard
Demo Programm, changing text size and position
There is a way in your library to set the display coordinates to render a text at a specific position, or to set the font size directly (without scaling the projection matrix)?.
On the file glyphs-demo.cc I tried to change the coordinates of glyphy_point_t top_left for example to:
glyphy_point_t top_left = {100, 50}; demo_buffer_move_to (buffer, &top_left);
But the text is still render in the same position.
At the function demo_buffer_add_text
the fourth parameter should be the font size, but f.e. if you change the size from 1 to f.e.:
demo_buffer_add_text (buffer, text, font, 100);
there is no any difference with demo_buffer_add_text (buffer, text, font, 1);
Of course if I scale the projection matrix it grows.
Is this a bug, or what is the purpose for both parameter ?
I think what you are observing is that the viewpoint is always scaled to contain the whole text, no matter what font size you use. Then again, I haven't looked at this code in many years.
Yes, you are right, the viewport scaled the whole text.
How should I to use the library in order to render the text (or more than one text fragment) at the correct position? I tried with the following equation: (extents.max_y/content_scale)/extents.max_x;
, but the result is not accurate, if I change the Window Width or height or if I change the font size(this works now perfectly) the constant 0.72 doesn't works anymore, I have to change it manually. For example:
glyphy_point_t top_left = {100,50};
buff.move_to(&top_left);
buff.add_text(text, &font, 50);
projection = glm::ortho(0.f, (float)width, 0.f,(float)height, -1.f, 1.f);
projection = glm::scale(projection, glm::vec3(1.1f, -1.1f, 1.f));//If I don't do this the glyphs appear inverted
glyphy_extents_t extents;
buff.extents(nullptr, &extents);
double content_scale = 0.72 * std::min (width / (extents.max_x - extents.min_x), height / (extents.max_y - extents.min_y));
double y_div = (extents.max_y/content_scale)/extents.max_x;
projection = glm::translate(projection, glm::vec3(-(extents.max_x + extents.min_x) / 12000.0f, -(extents.max_y + extents.min_y) / y_div, 0.f));//I don't know exactly why 12000 works
i get this too