al_set_shader_sampler(3alleg5)
al_set_shader_sampler π β¨
okay bestie, we're in the Allegro 5 API manual, page al_set_shader_sampler(3alleg5), and honestly? this one is short but it's giving powerful. π
β¨ SYNOPSIS β¨
#include <allegro5/allegro.h>
bool al_set_shader_sampler(const char *name,
ALLEGRO_BITMAP *bitmap, int unit)
π¦ DESCRIPTION π¦
So basically: this function sets a texture sampler uniform and a texture unit for the shader that's currently on your target bitmap. π
β οΈ Heads up queen: the bitmap you pass in must be a video bitmap. No exceptions, no shortcuts, no "but it worked that one time". π
Now for the part that actually matters β different samplers should use different units. That's the rule. And here's why, because it's lowkey crucial:
The bitmap that gets passed to Allegro's drawing functions uses the 0th unit. So if you're planning on using the al_tex variable in your pixel shader and you've got another sampler in the mix, you gotta set that other sampler to use a unit different from 0. Periodt. π«Ά
But wait, there's more (there's always more, and it's kinda iconic):
With the primitives addon, you can actually free up the 0th unit by passing NULL as the texture argument to the relevant drawing functions. π And in that case? You may set a sampler to use the 0th unit, and thus not use al_tex β because the al_use_tex variable will be set to false. Easy math, bestie. π
π What it returns
Returns true on success. Otherwise it returns false β for example, if the uniform by that name does not exist in the shader. Not me getting a false back and spiralling... π
β SINCE β
5.1.0 β she's been here a minute, respect her legacy π
π SEE ALSO π
al_use_shader(3alleg5)β go read that one too, it's her bestie fr fr
okay so that's the whole page, you ate it, I'm obsessed π
β¨ this was page al_set_shader_sampler(3alleg5) from the Allegro reference manual, and if you ever forget where you read it... that's the source, that's the version, that's the date on the tin, no cap ππ¦ bye bestie, go write some shaders π
π¦ 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