GML Does scaling text involve loss?

O

Occupant

Guest
If text is being dynamically generated and drawn to some confined space, there seems to be two ways to deal with sizing the font correctly:

1. use draw_text_transformed to draw a scaled version of the string, after string_width_ext and _string_height_ext so that you can compare it to the constraints of the confined space know how much to scale it up or down.

Does the above approach involve any kind of pixel loss or distortion? I'm guessing it must, since it probably isn't as pixel-perfect as just choosing a different font size to begin with? Which brings me to the second way to solve the problem:

2. Create numerous versions of the desired font, each at different sizes. When drawing the text, try the largest font size, and if it doesn't fit, try a smaller font size, until the text fits the constraints.

Assuming this is calculated only once per display of text (and not every step), this seems like a viable alternative, though much harder to implement.

So my question is: does using draw_text_transformed cause pixel distortions? And if so, how bad are they at big jumps in scale?
 

TsukaYuriko

☄️
Forum Staff
Moderator
Font resources are pre-rendered as sprites. Scaling text therefore involves the same degree of loss as scaling graphics, so yes. Try drawing text using a small font at x4 scale to get an idea of how it will scale.

The only way to ensure text looks correct is to either pre-render it at multiple sizes, or to dynamically add more pre-rendered fonts at sizes at run-time.
 
O

Occupant

Guest
or to dynamically add more pre-rendered fonts at sizes at run-time.
Actually, one more question, @TsukaYuriko - how might one go about adding more pre-rendered fonts at the desired sizes at runtime? The only way I know of adding fonts at specific sizes is at design time, using the Fonts collection in the IDE. Is there another way?
 

FrostyCat

Redemption Seeker
The other way is adding a TTF file as an Included File, then using font_add(), then drawing with the result of that.
On all other (non Web) targets, you can use this function to add a font from a file. The file must be included in the game bundle using the Included Files functionality of GameMaker Studio 2, and must be a *.ttf format font file, useful for adding non-standard fonts like Asian or Arabic.

WARNING!: If you include a font in *.ttf format with a game, it must be licensed for distribution with the game.
 
Top