0
\$\begingroup\$

I have quads positioned in <0, 1> x <0, 1> coordinates. I use this system for font rendering.

In vertex shader I have:

gl_Position.xy = 2.0 * POSITION.xy - 1.0;

that brings the position to the screen space <-1, 1> x <-1, 1>.

My quads are created from two triangles ABD, BCD

D-C
|\|
A-B

Now, I want to scale the quad by a scale factor. Can I achieve this with this data?

I have tried to change geometry and store quad center and half-sizes, then calculate the final position as

gl_Position.xy = 2.0 * (CENTER_POSITION.xy + HALF_SIZE.xy) - 1.0;

This way, I can translate points to origin, scale them and translate them back. However, this scale single quad correctly, but the two closely neigboring quads are no longer closely neigboring, since the space between them is constant.

So the final question. How can I scale quads used for font rendering, so that the text is still readable without large gaps between glyphs?

\$\endgroup\$
0
\$\begingroup\$

It sounds like you've already answered this for yourself:

this scales a single quad correctly, but the two closely neigboring quads are no longer closely neigboring, since the space between them is constant.

So, to scale the whole string of text, you need to scale the spaces between them too. That means the centers of each quad aren't fixed.

Instead of translating each quad to the origin then back, you'll want to translate a group of quads that are meant to scale together to the origin then back.

Pick a scaling/pivot point somewhere in your block of text (popular choices are the top-left or bottom-left corner of the whole block, the center of the block, or the start of the first line), and subtract that point from all your quads before scaling, then add it back to the result.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.