al_premul_rgba(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸŽ€ NAME πŸŽ€

al_premul_rgba β€” bestie, this is the Allegro 5 API page for it πŸ’–


✨ SYNOPSIS ✨

Okay so here's literally what you type to get it:

#include <allegro5/allegro.h>

ALLEGRO_COLOR al_premul_rgba(
   unsigned char r, unsigned char g, unsigned char b, unsigned char a)

πŸ’… DESCRIPTION πŸ’…

So like, this function is the shortcut for:

al_map_rgba(3alleg5)(r * a / 255, g * a / 255, b * a / 255, a)

That's it. That's the whole thing. It's giving "I did the math so you don't have to" 🧚

Now the tea: by default Allegro uses pre-multiplied alpha for transparent blending of bitmaps and primitives β€” and if you wanna read the whole discussion about that feature, go peek at al_load_bitmap_flags(3alleg5). πŸ‘€

What that means for you: if you want to tint a bitmap or a primitive so it's transparent, you have to multiply the color components by the alpha components when you pass them in here. No cap. For example:

int r = 255;
int g = 0;
int b = 0;
int a = 127;
ALLEGRO_COLOR c = al_premul_rgba(r, g, b, a);
/* Draw the bitmap tinted red and half-transparent. */
al_draw_tinted_bitmap(bmp, c, 0, 0, 0);
🫢 Fun fact that's actually important: this function can be called before Allegro is initialized. So you can go ahead and call it early, bestie, it's not gonna be mad at you.

⭐ SINCE ⭐

5.1.12 β€” so she's been iconic for a minute πŸ’œ


🌈 SEE ALSO 🌈


And that's the whole page, periodt. This came from the Allegro reference manual β€” page al_premul_rgba(3alleg5) β€” and the footer didn't hand me a date to pass along, so no invented dates here, we stay honest in this group chat πŸ’–βœ¨πŸ¦‹πŸŽ€

πŸ“¦ where this page comes from