al_triangulate_polygon(3alleg5)
π al_triangulate_polygon β Allegro 5 API π
okay bestie, welcome to the 3alleg5 page for al_triangulate_polygon β¨ this is the Allegro 5 API and she is ready to slice your polygons into lil triangle confetti π
β¨ SYNOPSIS β¨
#include <allegro5/allegro_primitives.h>
bool al_triangulate_polygon(
const float* vertices, size_t vertex_stride, const int* vertex_counts,
void (*emit_triangle)(int, int, int, void*), void* userdata)
π¦ DESCRIPTION π¦
So here's the vibe: this function takes one simple polygon and chops it up into triangles πΊπΊπΊ β and you can also subtract zero or more other simple polygons from it, and those subtracted ones are the holes. The holes are like, "not me being a void in your shape π" and the main polygon is like "periodt".
β οΈ real talk though: the holes cannot touch or intersect with the outline of the main polygon. Like, zero contact. Don't even try it π
And when we say simple, we mean the polygon does not have to be convex (she can be as lumpy as she wants, we love her for that π ), but it must not be self-overlapping. Self-overlapping is giving chaos and we don't do that here.
πΈ Parameters πΈ
verticesβ an interleaved array of(x, y)vertex coordinates, for every single one of the polygons, holes included. Everybody's in the same array, no cap π«Άvertex_strideβ the distance, in bytes, between successive pairs of vertices in that array. It's giving "how far apart are your besties standing" π«vertex_countsβ how many vertices each polygon has. The main polygon's vertex count lives atvertex_counts[0]and it must be at least three (a triangle is the bare minimum, you can't have a shape with two points, bestie π). Every element after that says how many vertices each hole has. And the whole array must be terminated with an element with valuezeroβ that zero is the little "k that's it, we're done here" πemit_triangleβ a function that gets called for every set of three points that form a triangle. She receives the indices of the points invertices, plususerdata. Iconic callback energy πuserdataβ arbitrary data that gets passed straight through toemit_triangle. Whatever you want, it's yours, she won't judge π
β SINCE β
5.1.0 β yes she's been around, she's a legend π
π SEE ALSO π
al_draw_filled_polygon_with_holes(3alleg5)β the sister function, she draws the thing you just triangulated π¦β¨
mwah π that's the whole page! This was the Allegro reference manual, page al_triangulate_polygon(3alleg5) β go forth and triangulate, bestie, you're gonna slay π₯ππ
π¦ 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