ALLEGRO_VERTEX_ELEMENT(3alleg5)
β¨ ALLEGRO_VERTEX_ELEMENT β¨
okay bestie, welcome to the Allegro 5 API β yes, that Allegro, the one from 3alleg5, we're doing graphics today π
π SYNOPSIS π
#include <allegro5/allegro_primitives.h>
typedef struct ALLEGRO_VERTEX_ELEMENT ALLEGRO_VERTEX_ELEMENT;
π¦ DESCRIPTION π¦
so like, imagine a vertex right? it's not just one thing. it's a whole little bundle of vibes β where it is, what color it is, etc. and ALLEGRO_VERTEX_ELEMENT is the tiny lil struct that describes one of those pieces. one single element. the position? maybe. the color? could be. it's giving "I contain multitudes but only one attribute at a time" π«Ά
these structs get used by al_create_vertex_decl(3alleg5) to build the vertex declaration, and because a vertex has several elements, you basically always see them hanging out in an array. and here's the iconic part: the last element of that array needs its attribute field set to 0, which is the code for "that's it, we're done here, no more elements, periodt." π
and now, the example β this one creates a declaration describing the ALLEGRO_VERTEX(3alleg5) structure. and ngl, passing this as a vertex declaration to al_draw_prim would be identical to passing NULL. same energy, fr fr.
/* On compilers without the offsetof keyword you need to obtain the
* offset with sizeof and make sure to account for packing.
*/
ALLEGRO_VERTEX_ELEMENT elems[] = {
{ALLEGRO_PRIM_POSITION, ALLEGRO_PRIM_FLOAT_3, offsetof(ALLEGRO_VERTEX, x)},
{ALLEGRO_PRIM_TEX_COORD_PIXEL, ALLEGRO_PRIM_FLOAT_2, offsetof(ALLEGRO_VERTEX, u)},
{ALLEGRO_PRIM_COLOR_ATTR, 0, offsetof(ALLEGRO_VERTEX, color)},
{0, 0, 0}
};
ALLEGRO_VERTEX_DECL* decl = al_create_vertex_decl(elems, sizeof(ALLEGRO_VERTEX));
πΈ Fields πΈ
attributeβ a member of theALLEGRO_PRIM_ATTR(3alleg5)enumeration, and it's the one that says what this attribute actually signifies πstorageβ a member of theALLEGRO_PRIM_STORAGE(3alleg5)enumeration, telling you how this attribute is stored πΎoffsetβ the offset in bytes from the beginning of your custom vertex structure. and bestie, the C functionoffsetofis so useful here, use it, trust π§
π SEE ALSO π
al_create_vertex_decl(3alleg5)ALLEGRO_VERTEX_DECL(3alleg5)ALLEGRO_PRIM_ATTR(3alleg5)ALLEGRO_PRIM_STORAGE(3alleg5)
lowkey important reminder: that trailing {0, 0, 0} is not decorative, it's load-bearing. no cap. π
and that's the whole page, you ate it π
this was the Allegro reference manual, brought to you by the ALLEGRO_VERTEX_ELEMENT(3alleg5) of the 3alleg5 manual set. go forth and declare your vertices, queen ππβ¨
π¦ 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