create_color_table(3alleg4)

πŸ’– create_color_table β€” the Allegro glow-up table builder πŸ’–

okay bestie, welcome to the Allegro manual, page create_color_table(3alleg4). this one is a lil function from the Allegro game programming library and it's literally the girlboss behind every custom colour effect you've ever gasped at. sit down, hydrate, let's go 🫢


✨ NAME ✨

create_color_table β€” fills a color mapping table for customised effects.

(it lives in the Allegro game programming library, in case that wasn't obvious πŸ’…)


🌸 SYNOPSIS 🌸

#include <allegro.h>

void create_color_table(COLOR_MAP *table, const PALETTE pal, void
(*blend)(PALETTE pal, int x, int y, RGB *rgb), void (*callback)(int pos));

πŸ¦‹ DESCRIPTION πŸ¦‹

so what this cutie actually does: it fills the color mapping table you hand it (that's the table bestie) with all the lookup data you need to do customised effects using the palette you give it. it does this by calling your blend function to figure out the result of every single colour combination. every. single. one. no skips, no shortcuts. πŸŽ€

your blend routine gets handed a pointer to the palette plus the two indices of the colors that are being combined, and it's your job to fill in the RGB structure with the result you want β€” in 0-63 format (not 0-255, bestie, this is the old-school format, don't @ me). then Allegro takes over and searches the palette for the closest match to the RGB color you asked for. which means it's totally fine if your palette has no exact match for that color β€” Allegro will find the nearest vibe. iconic behaviour, honestly. ✨

now, about that callback β€” if it's not NULL, it will be called 256 times while the calculation is running. why would you want that? so you can show a lil progress indicator and keep your user from thinking the game froze 😭 main character energy for your loading bar.

example time, look at this:

COLOR_MAP greyscale_table;
...
void return_grey_color(const PALETTE pal,
                       int x, int y, RGB *rgb)
{
   ...
}
...
   /* Build a color lookup table for greyscale effect. */
   create_color_table(&greyscale_table, pal,
                      return_grey_color, NULL);

see how the callback is just NULL there? no progress bar for greyscale girlies, we trust the process. πŸ’œ


πŸ‘‘ SEE ALSO πŸ‘‘

go read these next, they're all in the same friend group:


ngl, one thing to keep in your heart: that RGB result is 0-63 format. say it with me. 0-63. not 255. Allegro does the closest-match search for you, but it can only do that if you speak the right dialect. 🫢

and that's the whole page, babe! this was brought to you by Allegro version 4.4.3, and yes, the manual really does just sign off as Allegro ... version 4.4.3 ... create_color_table(3alleg4) like that's a normal way to say goodbye. slay, i guess. go build your greyscale table and text me when it works πŸ’…πŸŽ€πŸ’–