create_trans_table(3)

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

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

ok so this is a page from the Allegro manual, section 3, and it's all about create_trans_table. it's giving game-programming-glow-up energy and honestly? we're obsessed. ✨


🌸 NAME 🌸

create_trans_table β€” fills a color mapping table for translucency effects. yep, it's the Allegro game programming library, and yes she's iconic for this one πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <allegro.h>

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

like, that's the whole signature. short. sweet. main character. πŸ‘‘


✨ DESCRIPTION ✨

okay so here's the vibe: create_trans_table fills the color mapping table you hand it (table) with lookup data for doing translucency effects with the palette you give it (pal). 🌈

when you combine the colors c1 and c2 using this table, the result is gonna be a color somewhere between the two. not one, not the other, a little secret third thing. no cap.

the r, g, and b parameters specify the solidity of each color component, ranging from 0 (totally transparent) to 255 (totally solid). so like:

  • 0 = ghost mode, fully see-through πŸ‘»
  • 255 = fully there, no notes
  • and for 50% solidity, you pass 128. remember that number, bestie, it's the moment. πŸ’–

now for the special-case lore: this function treats source color #0 as a special case, leaving the destination unchanged whenever a zero source pixel is encountered β€” that way masked sprites draw correctly. it's the little detail that saves your whole render. 🫢

also, this function will take advantage of the global rgb_map variable to speed up color conversions. efficiency queen. ⚑

and if the callback function is not NULL, it will be called 256 times during the calculation, which means you can totally show off a progress indicator while it chugs along. 😭 so thoughtful.

example time, look at her:

COLOR_MAP trans_table;
...
/* Build a color lookup table for translucent drawing. */
create_trans_table(&trans_table, pal, 128, 128, 128, NULL);

πŸ‘€ SEE ALSO πŸ‘€

go read those too, they're all in the same friend group fr fr πŸŽ€


and that's the page!! this was Allegro, version 4.4.3, and the date on this one was the create_trans_table(3) era β€” so go forth and blend your sprites beautifully, bestie. you ate. πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from