al_attach_shader_source(3alleg5)
π al_attach_shader_source π
okay bestie, you found the Allegro 5 API manual page for al_attach_shader_source, and honestly? this one is a whole journey. shaders, uniforms, macros, the entire vibe. let's get into it β¨
β¨ SYNOPSIS β¨
like, here's the summoning circle:
#include <allegro5/allegro.h>
bool al_attach_shader_source(ALLEGRO_SHADER *shader, ALLEGRO_SHADER_TYPE type,
const char *source)
πΈ DESCRIPTION πΈ
so what this does is it attaches the shader's source code to the shader object and compiles it. that's it, that's the job. iconic behavior honestly.
Passing NULL deletes the underlying (OpenGL or DirectX) shader. poof. gone. no notes.
oh and if you'd rather pull your shader source out of an external file instead of a string, go look at al_attach_shader_source_file(3alleg5) β she's got you covered π«Ά
now, the important lore: if you do not use ALLEGRO_PROGRAMMABLE_PIPELINE, Allegro's graphics functions will not use any shader specific functions themselves. and on a system with no fixed function pipeline (think OpenGL ES 2, or OpenGL 3 or 4), that means Allegro's drawing functions literally cannot be used. π
TODO: Is ALLEGRO_PROGRAMMABLE_PIPELINE set automatically in this case?
(yeah, that's straight from the source, even the manual is unsure. we love a mystery π)
π the uniforms Allegro gives you π
when ALLEGRO_PROGRAMMABLE_PIPELINE is used, Allegro hands you these shader uniforms and you can access them in your shaders. free real estate:
al_projview_matrixβ the matrix for Allegro's orthographic projection multiplied by theal_use_transform(3alleg5)matrix. the type ismat4in GLSL, andfloat4x4in HLSL.al_use_texβ whether or not to use the bound texture. the type isboolin both GLSL and HLSL.al_texβ the texture if one is bound. the type issampler2Din GLSL andtexturein HLSL.al_use_tex_matrixβ whether or not to use a texture matrix (used by the primitives addon). the type isboolin both GLSL and HLSL.al_tex_matrixβ the texture matrix (used by the primitives addon). your shader should multiply the texture coordinates by this matrix. the type ismat4in GLSL, andfloat4x4in HLSL.
π¦ GLSL alpha testing uniforms π¦
with GLSL, alpha testing is done in the shader and uses these additional uniforms:
al_alpha_testβ whether to do any alpha testing. iffalse, the shader should render the pixel, otherwise it should interpret the values ofal_alpha_funcandal_alpha_test_val.al_alpha_funcβ the alpha testing function used. one of theALLEGRO_RENDER_FUNCTION(3alleg5)values. the default isALLEGRO_RENDER_ALWAYSwhich means all pixels (even completely transparent ones) are rendered. the type isint. seeALLEGRO_RENDER_STATE(3alleg5).al_alpha_test_valβ if alpha testing is notALLEGRO_RENDER_NEVERorALLEGRO_RENDER_ALWAYS, the alpha value to compare to for alpha testing. the type isfloat.
π GLSL vertex attributes π
for GLSL shaders the vertex attributes are passed using these variables:
al_posβ vertex position attribute. type isvec4.al_texcoordβ vertex texture coordinate attribute. type isvec2.al_colorβ vertex color attribute. type isvec4.al_user_attr_0β the vertex attribute declared asALLEGRO_PRIM_USER_ATTR.al_user_attr_1, ...,al_user_attr_9β the vertex attribute declared asALLEGRO_PRIM_USER_ATTR + Xwhere X is an integer from 1 to 9.
β HLSL vertex attribute semantics β
for HLSL shaders the vertex attributes are passed using these semantics:
POSITION0β vertex position attribute. type isfloat4.TEXCOORD0β vertex texture coordinate attribute. type isfloat2.TEXCOORD1β vertex color attribute. type isfloat4.
π the macro girlies π
also, each shader variable has a corresponding macro name that can be used when defining the shaders using string literals. don't use these macros with the other shader functions, bestie, that will lead to undefined behavior. like, seriously. π
ALLEGRO_SHADER_VAR_PROJVIEW_MATRIXfor "al_projview_matrix"ALLEGRO_SHADER_VAR_POSfor "al_pos"ALLEGRO_SHADER_VAR_COLORfor "al_color"ALLEGRO_SHADER_VAR_TEXCOORDfor "al_texcoord"ALLEGRO_SHADER_VAR_USE_TEXfor "al_use_tex"ALLEGRO_SHADER_VAR_TEXfor "al_tex"ALLEGRO_SHADER_VAR_USE_TEX_MATRIXfor "al_use_tex_matrix"ALLEGRO_SHADER_VAR_TEX_MATRIXfor "al_tex_matrix"ALLEGRO_SHADER_VAR_ALPHA_FUNCTIONfor "al_alpha_func"ALLEGRO_SHADER_VAR_ALPHA_TEST_VALUEfor "al_alpha_test_val"
π how to actually learn this π
go examine the output of al_get_default_shader_source(3alleg5) β that's your example of how to use all the above uniforms and attributes. it's giving study guide, no cap.
π return value π
returns true on success and false on error, in which case the error log is updated. you can grab that error log with al_get_shader_log(3alleg5). so if things go sideways, check the log, she will tell you everything π
πΈ SINCE πΈ
5.1.0 β she's been here a minute, and she ate.
β¨ SEE ALSO β¨
al_attach_shader_source_file(3alleg5)al_build_shader(3alleg5)al_get_default_shader_source(3alleg5)al_get_shader_log(3alleg5)ALLEGRO_PRIM_ATTR(3alleg5)
and that's the whole page, bestie π this one came from the Allegro reference manual β you know, the one and only. go compile something gorgeous, and remember: NULL deletes the shader, so don't do it by accident β¨π§π
π¦ 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