load_dat_font(3alleg4)

πŸ’– load_dat_font β€” the Allegro manual, but make it cute πŸ’–

okay bestie, so this is a page from the Allegro manual (yes, that Allegro, the 4.x era legend), and today's main character is load_dat_font. Sit down, grab a strawberry πŸ“, we're loading fonts out of datafiles and it's gonna be slay.


✨ NAME ✨

load_dat_font β€” loads a FONT out of an Allegro datafile. that's it, that's the whole vibe πŸŽ€


🌸 SYNOPSIS 🌸

#include <allegro.h>

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

like, one function, three args, zero drama (well... mostly) πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so basically πŸ’– β€” this function loads a FONT from an Allegro datafile.

Here's the fun part: you can point that param parameter at an array holding two strings that name the font and the palette inside the datafile, by name. Let's break it down because it's giving ✨organized✨:

  • The first string in this list is the name of the font. You can pass NULL here and it'll just load the first font it finds in the datafile. lowkey convenient ngl.
  • The second string can specify the name of the palette associated with the font. Important: this is only returned if the pal parameter is not NULL. Don't forget that, bestie, or you'll be staring at an empty palette like 😭.
  • If you pass NULL for the name of the palette, the last palette found before the font was found is returned. yes, the last one. not the first. keep up πŸ’€
  • You can also pass NULL for param entirely, which is treated exactly as if you'd passed NULL for both strings separately. In that case, the function just loads the first font it finds in the datafile, plus the palette that precedes it. no notes, iconic behavior πŸ‘‘

πŸ“ example time, because we love a visual πŸ“

Say you've got a datafile named fonts.dat and it looks like this:

FONT  FONT_1_DATA
FONT  FONT_2_DATA
FONT  FONT_3_DATA
PAL   FONT_1_PALETTE
PAL   FONT_2_PALETTE

Then this code will load FONT_1_DATA as a FONT and return FONT_1_PALETTE as the palette:

FONT *f;
PALETTE pal;
char *names[] = { "FONT_1_DATA", "FONT_1_PALETTE" }

f = load_dat_font("fonts.dat", pal, names);

If instead you want to load the second font, FONT_2, from the datafile, you'd use:

FONT *f;
PALETTE pal;
char *names[] = { "FONT_2_DATA", "FONT_2_PALETTE" }

f = load_dat_font("fonts.dat", pal, names);

And if you want to load the third font but honestly could not care less about a palette, use:

FONT *f;
char *names[] = { "FONT_3_DATA", NULL }

f = load_dat_font("fonts.dat", NULL, names);

see? the NULL palette name + NULL pal combo is giving minimal effort, maximum results 🌈


πŸ’œ RETURN VALUE πŸ’œ

Returns a pointer to the font β€” or NULL on error 😭.

BESTIE, LISTEN TO ME: you are responsible for destroying the font when you're finished with it, to avoid memory leaks. that's your job, not Allegro's. don't ghost your fonts, free them 🫢

πŸ‘‘ SEE ALSO πŸ‘‘

go read those too, they're part of the friend group πŸ’•


and that's the whole page, babes ✨ this was Allegro, version 4.4.3, and the page itself is load_dat_font(3alleg4). mwah, bye πŸ’…πŸŽ€πŸ¦‹