al_color_linear(3)
π al_color_linear β the Allegro 5 API glow-up
okay bestie, so this one lives in the Allegro 5 API and it's genuinely such a slay little function. It's the one that lets you hand over linear sRGB values and get a real ALLEGRO_COLOR(3) back. β¨
π SYNOPSIS
#include <allegro5/allegro_color.h>
ALLEGRO_COLOR al_color_linear(float r, float g, float b)
π DESCRIPTION
So al_color_linear returns an ALLEGRO_COLOR(3) structure built from linear sRGB values. π
Here's the lore: Allegro RGB values are assumed to be sRGB, and sRGB is literally everywhere β it's in wide use by all kinds of display devices. What makes sRGB special is that it accounts for a standard gamma correction that gets applied to RGB colors before they ever show up on your screen. no cap. π¦
And gamma correction means... okay imagine this: say you've got a medium gray color specified with al_map_rgb_f(0.5,0.5,0.5). You do not want your monitor to set that pixel to exactly half the physical maximum intensity. That would be lowkey a lie to your eyes π β instead you want an intensity that appears half as bright as the maximum to the person looking at it. In this case, that's closer to 21% of maximum intensity rather than to 50% intensity. The way math is humbling us fr fr.
For some applications it may be useful to specify a color in linear sRGB components β and that's exactly when you reach for this function. π«Ά For example:
ALLEGRO_COLOR gray = al_color_linear(0.216, 0.216, 0.216);
char html[8];
al_color_rgb_to_html(gray.r, gray.g, gray.b, html); // "#808080"
iconic. it ate. π
β SINCE
5.2.8 β a vintage, your honor. π
πΈ SEE ALSO
the little conversion besties, go say hi π
Allegro reference manual β that's the whole vibe check for this page, and it's brought to you by the Allegro reference manual itself. 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