REGISTER_FONT_FILE_TYPE(3alleg4)

πŸ’– register_font_file_type β€” Allegro manual (3alleg4) πŸ’–

okay bestie, welcome to the Allegro game programming library docs, and today's main character is register_font_file_type β€” she registers a new font loading function. that's the whole vibe. let's go πŸ¦‹


✨ SYNOPSIS ✨

#include <allegro.h>

void register_font_file_type(const char *ext, FONT *(*load)(const char *filename, RGB *pal, void *param));

like yes, that second argument is a function pointer and yes she's a little intimidating at first glance, but she's serving, not scary 🫢


🌸 DESCRIPTION 🌸

so what she does is: she tells the load_font() functions about a brand new file type, and hands over a routine that knows how to read fonts in that format. you bring the reader, she handles the rest. iconic behavior honestly πŸ‘‘

the function you hand over has to follow this exact prototype, no cap:

FONT *load_my_font(const char *filename, RGB *pal, void *param)
{
   ...
}

now let's talk params because this is where it gets juicy πŸ“

  • the pal parameter can optionally be used to return a palette for the FONT.
  • the param parameter can be literally anything you want β€” it's your little mystery bag. you can use it to pass info into your loading routine, like for instance:
    • the font height
    • the character range to load
    • or the index number of a font in a datafile
⚠️ okay this part matters, listen up: if you choose to write your own font loading code, your function should be prepared to deal with a value of NULL for either of these parameters. like, don't just assume they're there. handle the NULL, bestie. it's giving "defensive programming" and it's giving "self care" πŸ’…

πŸ‘€ SEE ALSO πŸ‘€


and that's the tea β˜• go forth and register those font types, you absolute legend πŸ’œ

Allegro β€” version 4.4.3 Β· register_font_file_type(3alleg4) Β· mwah, stan the Allegro manual for me, bye bestie πŸŽ€βœ¨