al_draw_fille...gon_with_holes(3alleg5)

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

πŸ’– al_draw_filled_polygon_with_holes β€” the Allegro 5 API page, but make it cute πŸ’–

okay so bestie, you opened the 3alleg5 manual (that's the Allegro 5 reference manual, in case the vibe check needed clarifying) and landed on al_draw_filled_polygon_with_holes. Sit down, hydrate, we're drawing shapes with ✨holes✨ in them.


✨ NAME ✨

al_draw_filled_polygon_with_holes β€” it's the Allegro 5 API, and it's giving "filled polygon but make it hollow" πŸ“


🌸 SYNOPSIS 🌸

#include <allegro5/allegro_primitives.h>

void al_draw_filled_polygon_with_holes(const float *vertices,
   const int *vertex_counts, ALLEGRO_COLOR color)

πŸ’… DESCRIPTION πŸ’…

So basically it draws a filled simple polygon, and then it subtracts zero or more other simple polygons from it β€” those subtracted ones are the holes. Iconic. But listen: the holes cannot touch or intersect with the outline of the filled polygon. Not even a little. Not even a pinky toe. 🫢

Here's the tea on the three args:

  • vertices β€” an interleaved array of (x, y) vertex coordinates, covering every one of the polygons, holes included. Interleaved means x, y, x, y, x, y, no cap.
  • vertex_counts β€” how many vertices each polygon has. The count for the filled polygon lives at vertex_counts[0] and must be at least three. Everything after that tells you how many vertices each hole has. And the array must be terminated with an element whose value is zero. That zero is the little "we're done here" bow πŸŽ€.
  • color β€” the color of the filled polygon. Obviously. πŸ’œ

Now the geometry rules, and bestie these matter:

When the y-axis is facing downwards (which is the usual case), the filled polygon's coordinates must be ordered anti-clockwise. All the hole vertices must use the opposite order β€” that's clockwise when y is down. Also every hole vertex must be inside the main polygon, and no hole may overlap the main polygon. Rules are rules. πŸ‘‘

For example:

float vertices[] = {
      0,   0, // filled polygon, upper left corner
      0, 100, // filled polygon, lower left corner
    100, 100, // filled polygon, lower right corner
    100,   0, // filled polygon, upper right corner
     10,  10, // hole, upper left
     90,  10, // hole, upper right
     90,  90  // hole, lower right
};
int vertex_counts[] = {
   4, // number of vertices for filled polygon
   3, // number of vertices for hole
   0  // terminator
};

So there are 7 vertices total: four of them make an outer square going from (0, 0) to (100, 100) in anti-clockwise order, and the other three make an inner triangle in clockwise order. The outer main polygon uses vertices 0 to 3 (inclusive), and the hole uses vertices 4 to 6 (inclusive). Math ate and left no crumbs πŸ”₯


⭐ SINCE ⭐

5.1.0 β€” vintage but still slaying πŸ’«


πŸ¦‹ SEE ALSO πŸ¦‹

not this page recommending itself in SEE ALSO 😭 honestly? self-love. we support it. πŸ’€

and that's the whole page, bestie β€” straight from the Allegro reference manual, page al_draw_fille...gon_with_holes(3alleg5), 3alleg5 era. go forth and punch some holes in your polygons πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά

πŸ“¦ where this page comes from