Fixes OpenGL complex polygons when scaling (#576)

Also fixes gap()
This commit is contained in:
Matthias Melcher
2022-12-10 13:10:36 +01:00
committed by GitHub
parent df059de37e
commit 5673072271
@@ -138,10 +138,12 @@ void Fl_OpenGL_Graphics_Driver::end_complex_polygon()
// find the bounding box for this polygon // find the bounding box for this polygon
v0 = xpoint; v0 = xpoint;
v0->y -= 0.1f;
float xMin = v0->x, xMax = xMin; float xMin = v0->x, xMax = xMin;
int yMin = (int)v0->y, yMax = yMin; int yMin = (int)v0->y, yMax = yMin;
for (i = 1; i < n; i++) { for (i = 1; i < n; i++) {
v0++; v0++;
v0->y -= 0.1f;
float v0x = v0->x; float v0x = v0->x;
int v0y = (int)v0->y; int v0y = (int)v0->y;
if (v0x == GAP) continue; if (v0x == GAP) continue;
@@ -157,14 +159,14 @@ void Fl_OpenGL_Graphics_Driver::end_complex_polygon()
return; return;
// loop through the rows of the image // loop through the rows of the image
for (y = yMin; y < yMax; y++) { for (y = yMin; y <= yMax; y++) {
// Build a list of all crossing points with this y axis // Build a list of all crossing points with this y axis
v0 = xpoint + 0; v0 = xpoint + 0;
v1 = xpoint + 1; v1 = xpoint + 1;
nNodes = 0; nNodes = 0;
for (i = 1; i < n; i++) { for (i = 1; i < n; i++) {
if (v1->x==GAP) { // skip the gap if (v1->x==GAP) { // skip the gap
i++; v0++; v1++; i++; v0++; v1++; v0++; v1++;
continue; continue;
} }
if ( (v1->y < y && v0->y >= y) if ( (v1->y < y && v0->y >= y)
@@ -194,7 +196,7 @@ void Fl_OpenGL_Graphics_Driver::end_complex_polygon()
} }
// fill the pixels between node pairs // fill the pixels between node pairs
glBegin(GL_LINES); // glBegin(GL_LINES);
for (i = 0; i < nNodes; i += 2) { for (i = 0; i < nNodes; i += 2) {
float x0 = nodeX[i]; float x0 = nodeX[i];
if (x0 >= xMax) if (x0 >= xMax)
@@ -205,11 +207,12 @@ void Fl_OpenGL_Graphics_Driver::end_complex_polygon()
x0 = xMin; x0 = xMin;
if (x1 > xMax) if (x1 > xMax)
x1 = xMax; x1 = xMax;
glVertex2f((GLfloat)x0, (GLfloat)y); glRectf(x0-0.25f, y, x1+0.25f, y+1.0f);
glVertex2f((GLfloat)x1, (GLfloat)y); // glVertex2f((GLfloat)x0, (GLfloat)y);
// glVertex2f((GLfloat)x1, (GLfloat)y);
} }
} }
glEnd(); // glEnd();
} }
::free(nodeX); ::free(nodeX);