al_draw_prim(3alleg5)
π 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. passNULLand 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 toNULL, the vertices are assumed to be of theALLEGRO_VERTEX(3alleg5)type. so like,NULLis 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 theALLEGRO_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:
ALLEGRO_VERTEX(3alleg5)ALLEGRO_PRIM_TYPE(3alleg5)ALLEGRO_VERTEX_DECL(3alleg5)al_draw_indexed_prim(3alleg5)
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
- 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