load_font(3alleg4)

πŸ’– load_font β€” bestie, let's get you a FONT πŸ’–

okay so this is load_font(3alleg4), and it lives in the Allegro manual, aka the Allegro game programming library. it does exactly one thing and it does it iconically: it loads a font from a file. that's the whole vibe. πŸ’…


✨ SYNOPSIS ✨

#include <allegro.h>

FONT *load_font(const char *filename, RGB *pal, void *param);

like. three args. you got this. 🫢


🌸 DESCRIPTION 🌸

So load_font loads a font from a file, periodt. Right now it supports pulling fonts out of:

  • a GRX format .fnt file πŸŽ€
  • an 8x8 or 8x16 BIOS format .fnt file πŸ‘‘
  • a datafile
  • literally any bitmap format that load_bitmap() can handle 🌈

Now, if the font has palette information in it, that palette gets handed back to you in the second parameter β€” and that param should be an array of 256 RGB structures, aka a PALETTE. πŸ’–

But here's the thing: the pal argument can be NULL. and if you do that, the palette data β€” if there even is any β€” just… doesn't come back to you. no drama, it's simply not returned. 😌

The third parameter is for passing specific info along to a custom loader routine. ngl, normally you just leave this as NULL and move on with your life. πŸ™ˆ

Also, lowkey important: another way of loading fonts is embedding them into a datafile and then using the datafile related functions. just so you know. iykyk. ✨


πŸ’« Example (the moment you've been waiting for) πŸ’«

FONT *myfont;
PALETTE palette;
...
myfont = load_font("my_font.pcx", palette, NULL);
if (!myfont)
   abort_on_error("Couldn't load font!");
...
textout_centre_ex(screen, myfont, "This is my own pretty font!",
                  SCREEN_W / 2, SCREEN_H / 2, white, black);
...
destroy_font(myfont);

see how we checked for !myfont?? that's the self-care. never skip the check bestie. 🧚


⭐ RETURN VALUE ⭐

Returns a pointer to the font, or NULL on error. that's it, that's the deal. πŸ’€

🚨 BUT LISTEN. you are responsible for destroying the font when you're finished with it, to avoid memory leaks. the font does not clean itself up. nobody is coming to save you. call destroy_font(). slay responsibly. πŸ‘‘

πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page!! this was Allegro version 4.4.3, and the page itself is load_font(3alleg4). go forth and load ur fonts, bestie, you absolutely ate this one πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ«Ά