al_premul_rgba(3)
π al_premul_rgba(3) π
okay so this is the Library Functions Manual page for al_premul_rgba, and she is genuinely a shortcut queen. Welcome to the Allegro 5 API tea, bestie. π«Ά
πΈ NAME πΈ
al_premul_rgba β Allegro 5 API. Periodt.
β¨ SYNOPSIS β¨
#include <allegro5/allegro.h>
ALLEGRO_COLOR al_premul_rgba(
unsigned char r, unsigned char g, unsigned char b, unsigned char a)
π¦ DESCRIPTION π¦
So this function is a shortcut for:
al_map_rgba(3)(r * a / 255, g * a / 255, b * a / 255, a)
That's the whole vibe. π
By default Allegro uses pre-multiplied alpha for transparent blending of bitmaps and primitives β see al_load_bitmap_flags(3) for a discussion of that feature, iykyk.
This means that if you want to tint a bitmap or primitive to be transparent, you need to multiply the color components by the alpha components when you pass them to this function. Like, do the math before the glow-up, bestie. 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);
And yes: this function can be called before Allegro is initialized. No cap. β¨
π SINCE π
5.1.12 β she's been iconic since then. π
π SEE ALSO π
source: the Allegro reference manual, page al_premul_rgba(3) β mwah π
π¦ where this page comes from
- arch rolling: allegro 5.2.11.3-2 Β· Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms