palette_color(3alleg4)

πŸ’– palette_color β€” bestie edition πŸ’–

okay so this is a page from the Allegro manual, section 3alleg4, and it's literally about one lil array that does SO much heavy lifting. come sit with me 🫢


✨ NAME ✨

palette_color β€” maps palette indexes into the current pixel format colors. it's part of the Allegro game programming library, and it's giving quiet-overachiever energy fr fr πŸ‘‘


🌈 SYNOPSIS 🌈

#include <allegro.h>

extern int palette_color[256];

like. that's it. one extern. one array. 256 slots. iconic πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

okay bestie so palette_color is a table that maps palette index colors, specifically the range 0-255, into whatever pixel format your current display mode happens to be using. the way it just adapts to the vibe? obsessed. ✨

here's the tea on how it behaves depending on the mode:

  • in a 256-color mode, it just maps onto the array index. simple. no notes. πŸŽ€
  • in truecolor modes, it looks up the specified entry in the current palette, and converts that RGB value into the appropriate packed pixel format. yes, it's out here doing conversions for you while you do nothing. main character energy honestly.

example, because you know I got you:

set_color_depth(32);
...
set_palette(desktop_palette);
/* Put a pixel with the color 2 (green) of the palette */
putpixel(screen, 100, 100, palette_color[2]);

see how palette_color[2] just knows what to do?? slay. put a pixel, pick the palette color, let the table handle the drama. πŸ”₯

ngl this is one of those things you don't think about until it breaks and then you're like "wait how did this ever work" 😭

πŸ‘‘ SEE ALSO πŸ‘‘

go read those too, they're all in the same friend group πŸ’œ


and that's the whole page!! this came from the Allegro manual, version 4.4.3, so if you're quoting it anywhere, that's the source and the version, periodt. now go make some pixels, bestie, you got this πŸŒΈπŸ¦‹πŸ’–