Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Changing font size

This thread is locked; no one can reply to it. rss feed Print
Changing font size
trictonicmp
Member #16,611
December 2016

Hi people, I know I always make weird questions about allegro but, it is possible to change the font size without loading the font again?
I mean, I know I can just re-load the same font with a new value for the size but I don't like the idea of re-loading a font file, it´s ok if there ar no answers to this question I only want to know if there is an alternative to reload the font file.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Because allegro does not draw fonts on demand, but caches the glyphs, you cannot resize the font without reloading it.

That said, there's nothing stopping you from loading the font at a larger size and then using transformations to downscale or upscale your fonts.

EDIT
You could use memfiles. Load your fonts into memfiles, and then have allegro load the fonts from memory instead of from disk. ;)

trictonicmp
Member #16,611
December 2016

I guess there are downsides on each method, I mean, transformations will pixelate the text and I have never used memfiles :'( i'm gonna look for it but I guess my best bet is to reload the font to change its size ;D

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

jmasterx
Member #11,410
October 2009

I made a system that loaded them as needed and picked the best one for the res
https://github.com/jmasterx/StemwaterSpades/blob/master/Spades%20Game/Game/UI/GuiFontManager.hpp
https://github.com/jmasterx/StemwaterSpades/blob/master/Spades%20Game/Game/UI/LobbyChatWidget.cpp#L250

Loading fonts does not take that much vram. I think allegro prerenders them as monochrome bitmaps...

codetricity
Member #17,059
March 2019

After seeing this thread, I too implemented font scaling using transform. I load the font in at a base size of 32. For me, it was a win/win because now I get a good balance. They look good in windowed mode and also look better in fullscreen (I scale to keep the same ratio). I did have to change my bitmap flag to the following:

al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR or ALLEGRO_MAG_LINEAR or ALLEGRO_MIPMAP or ALLEGRO_VIDEO_BITMAP);

Thanks for making the suggestion.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

You might not want ALLEGRO_MAG_LINEAR - it will blur graphics as they get larger. If you prefer crisp edges, don't use it. ALLEGRO_MIN_LINEAR is good though, and makes shrinking bitmaps look better. MIPMAP pre-renders smaller versions, which isn't strictly necessary for fonts. Scaling is more than fast enough.

Go to: