Open GL can't draw some triangles

I drawed a triangle {(0,0), (1,0), (0,1)}. Now i want to draw a second one. But for some reason not any triangle draws. For example triangle: {(1.5654, 1.2), (1.1, 1.4564), (1.5, 1.15)} is drawn normal, but triangle {(1,1), (1,0), (0, 1)} doesn't appear. Hear the code i use to draw:

glBegin(GL_TRIANGLES);
   invers_sh.setAttributeValue(b_colorLoc, colors[0]);
   glVertex2d(1.5654, 1.2);

   invers_sh.setAttributeValue(b_colorLoc, colors[1]);
   glVertex2d(1.1, 1.4564);

   invers_sh.setAttributeValue(b_colorLoc, colors[2]);
   glVertex2d(1.5, 1.15);
glEnd();

For first triangle it's the same code (but coordinates are different). I tryed to unite both drawings (in one glBegin/glEnd) - same result. What i do wrong?

Upvotes: 0

Views: 207

Answers (2)

user1781290
user1781290

Reputation: 2874

As pointed out in the other answer, you need to draw the vertices for all triangles in the same order, clockwise or counter-clockwise (OpenGL default). To correct the ordering, just swap out the first and last vertex.

You can control this behaviour (called FaceCulling) with OpenGL-commands like glCullFace, glFrontFace and glEnable/glDisable with GL_CULL_FACE.

Upvotes: 0

Andrew Luo
Andrew Luo

Reputation: 927

you need to draw all vertices in a clockwise or counter clockwise order depending on frontface setting, you can google it for more details.

Upvotes: 1

Related Questions