ALLEGRO_VERTEX_ELEMENT(3)
π ALLEGRO_VERTEX_ELEMENT(3) π
okay so this is the ALLEGRO_VERTEX_ELEMENT page from the Library Functions Manual β Allegro 5 API, bestie, and it's genuinely not scary, promise π«Ά
β¨ SYNOPSIS β¨
#include <allegro5/allegro_primitives.h>
typedef struct ALLEGRO_VERTEX_ELEMENT ALLEGRO_VERTEX_ELEMENT;
πΈ DESCRIPTION πΈ
okay so picture this: it's a tiny little structure that describes one certain element of a vertex π. like, the position of the vertex, or its color. that's it. that's the whole vibe. it's giving "small but iconic" β¨
these structures get used by the al_create_vertex_decl(3) function to create the vertex declaration β and for that, they generally show up in an array π¦. and here's the part you cannot skip, bestie: the last element of such an array should have the attribute field equal to 0, to signify that it's the end of the array. it's the "k bye" of the array. the terminator. no cap π
here's example code that would create a declaration describing the ALLEGRO_VERTEX(3) structure (and passing this as vertex declaration to al_draw_prim would be identical to passing NULL, iykyk):
/* 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(3)enumeration, specifying what this attribute signifies πstorageβ a member of theALLEGRO_PRIM_STORAGE(3)enumeration, specifying how this attribute is stored πoffsetβ offset in bytes from the beginning of the custom vertex structure. the C functionoffsetofis very useful here, fr fr β
lowkey the offsetof thing is the whole magic trick, bestie β it's how you tell Allegro where in your struct each thing lives π
π SEE ALSO π
al_create_vertex_decl(3), ALLEGRO_VERTEX_DECL(3), ALLEGRO_PRIM_ATTR(3), ALLEGRO_PRIM_STORAGE(3)
and that's the whole page, bestie, you ate that π go forth and declare your vertices slay π
this has been the Allegro reference manual, ALLEGRO_VERTEX_ELEMENT(3) β mwah, ily, go build something cute π§
π¦ 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