al_premul_rgba(3alleg5)
π 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
- debian trixie: allegro5-doc 2:5.2.10.1+dfsg-1 Β· Zlib
- ubuntu questing: allegro5-doc 2:5.2.10.1+dfsg-1build1
- ubuntu resolute: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- ubuntu stonking: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms