opcon / QuickFont

A Modern OpenGL Font Rendering Library for OpenTK
https://github.com/opcon/QuickFont
MIT License
83 stars 25 forks source link

How are fonts scaled #33

Closed HouseOfFinwe closed 7 years ago

HouseOfFinwe commented 7 years ago

How are fonts scaled? I don't see a mechanism for scaling the font size. When I added some scaling to the modelView matrix of a primitive, it translated as well as scaled the font. I'm not really sure why, there doesn't to be anything funky going on in the vertex shader. I can't modify the texture coordinates, as this obviously messes up the entire scheme, since all of the bimaps are located in one giant texture.

opcon commented 7 years ago

Scaling the font via the modelView matrix is the way to do it.

Try centering your text at the origin, then scaling it and translating it with the modelView matrix, e.g.:

dp.Print(text, Vector3.Zero, QFontAlignment.Left);
dp.ModelViewMatrix =  Matrix4.CreateScale(2) * Matrix4.CreateTranslation(pos);

Otherwise the scale matrix will be applied assuming the origin is at 0, so the whole font will be scaled away from the origin (assuming a positive scale factor)

HouseOfFinwe commented 7 years ago

Thanks. My issue ended up being the position argument to the print method was also being scaled by the ModelView matrix. It might be useful to add a Print overload that takes a transformation matrix as an argument instead of Vector3 for the position (to apply translation, rotation, and scaling all at once).