ALLEGRO_VERTEX_ELEMENT(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ 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 the ALLEGRO_PRIM_ATTR(3alleg5) enumeration, and it's the one that says what this attribute actually signifies πŸ‘‘
  • storage β€” a member of the ALLEGRO_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 function offsetof is so useful here, use it, trust 🧚

πŸ’– SEE ALSO πŸ’–


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