Fixing fl_complex_polygon() compilation for WIN32 (#571)

This commit is contained in:
Matthias Melcher 2022-12-05 19:57:30 +01:00 committed by GitHub
parent 9f92972729
commit 0d485b34a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 10 deletions

View File

@ -26,6 +26,8 @@
#include <FL/gl.h>
#include <FL/math.h>
#include <stdlib.h>
// OpenGL does not support rednering non-convex polygons. Calling
// glBegin(GL_POLYGON); witha complex outline will create rather random
// errors, often overwrinting gaps and holes.
@ -137,23 +139,28 @@ void Fl_OpenGL_Graphics_Driver::end_complex_polygon()
// find the bounding box for this polygon
v0 = xpoint;
float xMin = v0->x, xMax = xMin;
int yMin = v0->y, yMax = yMin;
int yMin = (int)v0->y, yMax = yMin;
for (i = 1; i < n; i++) {
v0++;
if (v0->x == GAP) continue;
if (v0->x <= xMin) xMin = v0->x;
if (v0->x >= xMax) xMax = v0->x;
if (v0->y <= yMin) yMin = v0->y;
if (v0->y >= yMax) yMax = v0->y;
float v0x = v0->x;
int v0y = (int)v0->y;
if (v0x == GAP) continue;
if (v0x <= xMin) xMin = v0x;
if (v0x >= xMax) xMax = v0x;
if (v0y <= yMin) yMin = v0y;
if (v0y >= yMax) yMax = v0y;
}
int nNodes, j;
float nodeX[n-1], pixelX, swap;
float *nodeX = (float*)malloc((n-1)*sizeof(float)), swap;
if (!nodeX)
return;
// loop through the rows of the image
for (y = yMin; y < yMax; y++) {
// Build a list of all crossing points with this y axis
XPOINT *v0 = xpoint + 0, *v1 = xpoint + 1;
v0 = xpoint + 0;
v1 = xpoint + 1;
nNodes = 0;
for (i = 1; i < n; i++) {
j = i-1;
@ -199,12 +206,14 @@ void Fl_OpenGL_Graphics_Driver::end_complex_polygon()
x0 = xMin;
if (x1 > xMax)
x1 = xMax;
glVertex2f(x0, y);
glVertex2f(x1, y);
glVertex2f((GLfloat)x0, (GLfloat)y);
glVertex2f((GLfloat)x1, (GLfloat)y);
}
}
glEnd();
}
::free(nodeX);
}
#else