al_draw_soft_triangle(3alleg5)
π NAME π
al_draw_soft_triangle β it's the Allegro 5 API function that lets you be the rasterizer, bestie. Yes fr. This is from the al_draw_soft_triangle(3alleg5) manual page and we're gonna get into it.
β¨ SYNOPSIS β¨
#include <allegro5/allegro_primitives.h>
void al_draw_soft_triangle(
ALLEGRO_VERTEX* v1, ALLEGRO_VERTEX* v2, ALLEGRO_VERTEX* v3, uintptr_t state,
void (*init)(uintptr_t, ALLEGRO_VERTEX*, ALLEGRO_VERTEX*, ALLEGRO_VERTEX*),
void (*first)(uintptr_t, int, int, int, int),
void (*step)(uintptr_t, int),
void (*draw)(uintptr_t, int, int, int))
Like, look at all those function pointers. It's giving "callback girlboss energy" and honestly? We love her. π
π¦ DESCRIPTION π¦
Okay so al_draw_soft_triangle draws a triangle using the software rasterizer plus pixel functions that you supply. It's not doing the shading for you, babes β it's handing you the wheel. πβ¨
If you wanna understand what all these functions are actually doing, go peek at the implementation of the various shading routines in addons/primitives/tri_soft.c. That's the homework, no cap. π
The triangle gets drawn in two segments, top to bottom. Those segments are deliniated by the vertically middle vertex of the triangle. And heads up: one of the two segments may be absent if two vertices are horizontally collinear. So sometimes it's a two-for-one and sometimes it's just one, it's giving flexible. π
πΈ Parameters πΈ
v1,v2,v3β The three vertices of the triangle. The whole cast, the main characters. πstateβ A pointer to a user supplied struct. This struct will be passed to all the pixel functions. It's basically the group chat everyone's invited to. π¬initβ Called once per call before any drawing is done. Lowkey important: the three points passed to it may be altered by clipping. So don't be shocked when they come back different, that's the clipping doing its thing. βοΈfirstβ Called twice per call, once per triangle segment. It gets passed 4 parameters: the first two are the coordinates of the initial pixel drawn in the segment, and the second two are the left minor and the left major steps, respectively. Those two represent the sizes of two steps taken by the rasterizer as it walks on the left side of the triangle. From then on, every single step gets classified as either a minor or a major step, matching those values. Periodt. πΆβοΈstepβ Called once per scanline. The last parameter is set to1if the step is a minor step, and0if it is a major step. Binary queen. 0οΈβ£1οΈβ£drawβ Called once per scanline. This function is expected to draw the scanline starting with a point specified by the first two parameters (those correspond to the x and y values) and going to the right until it reaches the value of the third parameter (that's the x value of the end point). And listen β all coordinates are inclusive. Inclusive!! We love an inclusive icon. π«Ά
Fr fr, this is a low-level one. If you're not ready to write your own pixel functions, maybe start somewhere friendlier. But if you are ready? Ate. π₯
π SEE ALSO π
al_draw_triangle(3alleg5)β the regular one, for when you don't feel like writing four callback functions before breakfast. π
And that's the whole page, bestie!! π This was the al_draw_soft_triangle(3alleg5) manual, straight out of the Allegro reference manual β¨ β so like, credit to the Allegro gang for all of it, we just added the sparkle. Mwah, go draw some triangles, you've got this. ππ¦π
π¦ 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