al_draw_prim(3alleg5)

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

πŸ’– al_draw_prim πŸ’–

okay bestie, welcome to the al_draw_prim(3alleg5) page from the Allegro reference manual β€” yes that Allegro, the 5 API one, and yes we are about to make triangles happen together. grab a snack, this is gonna be cute. πŸ¦‹


✨ NAME ✨

al_draw_prim β€” Allegro 5 API. that's it, that's the name, she's simple and she's iconic. πŸ‘‘


🌸 SYNOPSIS 🌸

#include <allegro5/allegro_primitives.h>

int al_draw_prim(const void* vtxs, const ALLEGRO_VERTEX_DECL* decl,
   ALLEGRO_BITMAP* texture, int start, int end, int type)

like look at her. six args, one int coming back. no cap. πŸ’…


πŸŽ€ DESCRIPTION πŸŽ€

so what she does is draw a subset of the vertex array you hand her. not the whole thing β€” a subset, a lil slice, the part you actually asked for. obsessed.

here are the parameters, bestie, one by one, no skipping:

  • texture β€” the texture to use. pass NULL and you get only color shaded primitives, which is lowkey a whole aesthetic.
  • vtxs β€” pointer to an array of vertices.
  • decl β€” pointer to a [vertex declaration]al_create_vertex_decl(3alleg5). if you set it to NULL, the vertices are assumed to be of the ALLEGRO_VERTEX(3alleg5) type. so like, NULL is the "trust me, they're normal vertices" move.
  • start β€” start index of the subset of the vertex array to draw.
  • end β€” one past the last index of the subset of the vertex array to draw. ONE PAST, bestie, don't forget, this is the classic off-by-one trap and she will not warn you twice. 🫢
  • type β€” a member of the ALLEGRO_PRIM_TYPE(3alleg5) enumeration, specifying what kind of primitive to draw. triangles? lines? she's flexible.

Returns: the number of primitives drawn. so you literally get receipts. πŸ’―


🧚 example: a textured triangle, fr fr

for example, to draw a textured triangle you could use:

ALLEGRO_COLOR white = al_map_rgb_f(1, 1, 1);
ALLEGRO_VERTEX v[] = {
   {.x = 128, .y = 0, .z = 0, .color = white, .u = 128, .v = 0},
   {.x = 0, .y = 256, .z = 0, .color = white, .u = 0, .v = 256},
   {.x = 256, .y = 256, .z = 0, .color = white, .u = 256, .v = 256}};
al_draw_prim(v, NULL, texture, 0, 3, ALLEGRO_PRIM_TRIANGLE_LIST);

see how start is 0 and end is 3? three vertices, indices 0, 1, 2, and end is one past the last one. the math is mathing. 🌈


πŸ’œ SEE ALSO πŸ’œ

go read these next, bestie, they're all part of the same friend group:


and that's the whole page!! πŸŽ€ this was the Allegro reference manual version of al_draw_prim(3alleg5) β€” source: Allegro reference manual, and yeah the footer says the same thing twice because manpages are just like that sometimes. go draw something gorgeous, you've got this. mwah. πŸ’‹βœ¨

πŸ“¦ where this page comes from