From b802e8edef68937e3ab00fb9b2e74b03ff5195bc Mon Sep 17 00:00:00 2001 From: Sylvain PILLOT Date: Thu, 29 Feb 2024 21:34:42 +0100 Subject: [PATCH] added dpoly() rendering method --- src/render/dpoly.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/render/dpoly.c diff --git a/src/render/dpoly.c b/src/render/dpoly.c new file mode 100644 index 0000000..5d317be --- /dev/null +++ b/src/render/dpoly.c @@ -0,0 +1,67 @@ +#include +#include + +void dpoly(int *polyX, int *polyY, int polyCorners, int fill_color, int border_color){ + + if (polyCorners<=2) return; + + if (fill_color == C_NONE && border_color == C_NONE) + return; + + if (fill_color != C_NONE) { + + float *nodeX, pixelX, pixelY, swap ; + int i, j, nodes; + + nodeX = malloc( polyCorners * sizeof(float)); + + // Loop through the rows of the image. + for (pixelY=0; pixelY=(float) pixelY) + || (polyY[j]<(float) pixelY && polyY[i]>=(float) pixelY)) { + nodeX[nodes++]=(int) (polyX[i]+(pixelY-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])); + } + j=i; + } + + // Sort the nodes, via a simple “Bubble” sort. + i=0; + while (inodeX[i+1]) { + swap=nodeX[i]; nodeX[i]=nodeX[i+1]; nodeX[i+1]=swap; if (i) i--; + } + else { + i++; + } + } + + // Fill the pixels between node pairs. + for (i=0; i=DWIDTH) break; + if (nodeX[i+1]<= 0 ) break; + if (nodeX[i ]< 0 ) nodeX[i ]=0 ; + if (nodeX[i+1]> DWIDTH) nodeX[i+1]=DWIDTH; + //for (pixelX=nodeX[i]; pixelX