Search code examples
c++allegro5

Is it possible to use system font in Allegro5?


I wonder if it is possible to just load a font from user's system resources, e.g Arial - right now, I have to copy the .ttf file into my program's directory; otherwise, the font won't load. I tried to find functions allowing this behaviour in official documentation of Allegro5, but with no success. Am I not understanding something, or do I have to distribute my program along with the font file? Below I include code line I use for loading the font, if it is of any help:

font=al_load_font("arial.ttf",24,0);

Solution

  • Remember that Allegro is a cross-platform library, and there is no cross-platform way to access system fonts.

    An option you can use is to #include the allegro windows (maybe its winalleg.h) header and then access that functionality (Windows API calls) to provide system fonts to the program. But that would limit your portability.

    Additionaly, you can acces fonts from a hardcoded path, such as c:/windows/fonts/ the system fonts but there are some problems with that:

    1. How do you know the user installed windows on C:/Windows?
    2. What do you do if a font is not there?
    3. Is that even the correct way to access system fonts?

    TL:DR

    Allegro wa not designed to load fonts from a common font repo. It expects everything to be where you tell it and nowhere else. Go and do it on a platform-case basis.