create_light_table(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

✨ create_light_table(3) ✨

okay so bestie, we're deep in the Allegro manual today and this one is a banger. it's create_light_table, and it fills a color mapping table so you can do lighting effects. that's the whole vibe. Allegro game programming library, periodt. πŸ’–


🌸 SYNOPSIS 🌸

#include <allegro.h>

void create_light_table(COLOR_MAP *table, const PALETTE pal, int r, g,
b, void (*callback)(int pos));

πŸ’… DESCRIPTION πŸ’…

So what this does: it fills the color mapping table you hand it (table) with lookup data for doing lighting effects using the palette you give it (pal). πŸŽ€

Now here's the tea about how the combining works. When you combine the colors c1 and c2 with this table, c1 gets treated as a light level from 0-255. and like:

  • at light level 255, the table outputs color c2 totally unchanged (no cap, it's untouched πŸ’―)
  • at light level 0, it outputs the r, g, b value you passed in to this function
  • at intermediate light levels, it outputs a color that's somewhere between those two extremes

and the r, g, and b values? those live in the range 0-63. yeah, 0-63, not 0-255, don't get it twisted. πŸ‘‘

Also, this function is lowkey an overachiever: it'll take advantage of the global rgb_ap variable to speed up color conversions. glow up ✨

And if the callback function is not NULL, it gets called 256 times during the calculation, so you can show a progress indicator and let everyone know you're working. iconic behaviour honestly. 🫢

Example, because we love a demonstration:

COLOR_MAP light_table;
...
/* Build a color lookup table for lighting effects. */
create_light_table(&light_table, pal, 0, 0, 0, NULL);

πŸ¦‹ SEE ALSO πŸ¦‹


okay that's the whole page, mwah πŸ’‹ this came from the Allegro manual, and the version we're repping is version 4.4.3 β€” go forth and light up those sprites bestie, you ate πŸ’…πŸŒˆβ­

πŸ“¦ where this page comes from