Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo Programm, changing text size and position #27

Open
Wah0airo opened this issue Jan 20, 2018 · 3 comments
Open

Demo Programm, changing text size and position #27

Wah0airo opened this issue Jan 20, 2018 · 3 comments

Comments

@Wah0airo
Copy link

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 ?

@behdad
Copy link
Owner

behdad commented Jan 21, 2018

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.

@Wah0airo
Copy link
Author

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

@mgood7123
Copy link

i get this too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants