Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with glPolygonMode - GL_FILL "skipping" vertices
    text
    copied!<p>I'm having a weird issue when trying to draw a polygon and filling it with a particular color:</p> <p>If I set the polygon mode as:</p> <p><code>glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);</code></p> <p>The polygon renders just fine:</p> <p><img src="https://i.stack.imgur.com/mPeC4.png" alt="Polygon rendered after setting the polygon fill mode to GL_LINE"></p> <p>However, as soon as I replace that line with the following:</p> <p><code>glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);</code></p> <p>The polygon doesn't fill right, but it seems like most lines get projected towards its first vertex, or something along those lines:</p> <p><img src="https://i.stack.imgur.com/BosyO.png" alt="enter image description here"></p> <p>I'm obviously doing something wrong. What I want to do is keep the color inside the polygon, however it seems to be ignoring several vertices. What might be wrong?</p> <p>Here's some selected parts of my code that might be of interest. I'm skipping over some data structures loading and other stuff that might not be very relevant:</p> <pre><code>int main(int argc, char **argv) { glutInit(&amp;argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowSize(640, 480); glutInitWindowPosition(150, 100); glutCreateWindow("CR-View GL"); glutDisplayFunc(display); glutMainLoop(); return 0; } void display(void) { glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); /* Set drawing color */ glColor3f(1, 0, 1); drawPolys(currentDrawingMode); /* Clear screen and draw */ glutSwapBuffers(); } // Draws the polygons void drawPolys (int id) { int poly, vertex; // set wireframe mode (if an empty polygon is required) if (id == 0) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } //Sets color fill mode if (id == 1) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } // Draw each polygon... for (poly = 0; poly &lt; polyCount; poly++) { glBegin(GL_POLYGON); // Draw each vertex... for (vertex = 0; vertex &lt; Polygons[poly].vertexCount; vertex++) { glVertex2f((float)Polygons[poly].vertices[vertex].x, (float)Polygons[poly].vertices[vertex].y); } glEnd(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload