al_premul_rgba_f(3alleg5)

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

πŸ’– al_premul_rgba_f β€” Allegro 5 API πŸ’–

okay bestie, welcome to the Allegro 5 API and to one of the most lowkey iconic little helpers in the whole color situation. this is al_premul_rgba_f, and she's here to do math for you so you don't have to. periodt. πŸ’…


✨ SYNOPSIS ✨

#include <allegro5/allegro.h>

ALLEGRO_COLOR al_premul_rgba_f(float r, float g, float b, float a)

🌸 DESCRIPTION 🌸

okay so real talk: this function is literally just a shortcut for al_map_rgba_f(3alleg5)(r * a, g * a, b * a, a). that's it. that's the whole vibe. she's the friend who does the multiplication for you and hands you a perfectly good ALLEGRO_COLOR back. 🫢

by default, Allegro uses pre-multiplied alpha for transparent blending of bitmaps and primitives (if you wanna go read the whole lore on that feature, check out al_load_bitmap_flags(3alleg5)). what does that mean for you, bestie? it means that if you want to tint a bitmap or a primitive and have it be transparent, you need to multiply the color components by the alpha components when you pass them into this function. that's the whole assignment. no cap.

for example:

float r = 1;
float g = 0;
float b = 0;
float a = 0.5;
ALLEGRO_COLOR c = al_premul_rgba_f(r, g, b, a);
/* Draw the bitmap tinted red and half-transparent. */
al_draw_tinted_bitmap(bmp, c, 0, 0, 0);

and the slayest part?? this function can be called before Allegro is initialized. yes fr fr, she doesn't need the whole engine booted up first. she's that independent. πŸ‘‘


⭐ SINCE ⭐

5.1.12


πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page, bestie!! πŸ’– this was pulled straight from the Allegro reference manual, and yeah, the footer is out here trying to be all al_premul_rgba_f(3alleg5) again like a lil echo β€” but you already know her name by now. go forth and premultiply your alphas. mwah. πŸŽ€βœ¨πŸŒˆ

πŸ“¦ where this page comes from