Problem using GL_TRIANGLES instead of GL_QUADS

Hi List, I´m having a problem using GL_TRIANGLES to replace GL_QUADS.
Suposse you have this vertices:
v0=0,1,1
v1=-1,0,0
v2=0,1,-1
v3=1,0,0

If I want to draw a quad (in OpenGL) I have to do something like this:
GLfloat vertices[] = {v0,v1,v2,v3};

glVertexPointer(3, GL_FLOAT, 0, vertices);
glDrawArrays(GL_QUADS, 0, 4);

If you change the vertices position the result is the same. The vertices {v0,v1,v2,v3}, {v1,v2,v3,v0}, {v2,v3,v0,v1}, {v3,v0,v1,v2} make the same result.

Now I want to make this quad in OpenGLES. I read in some forums, including this (http://www.khronos.org/message_boards/v … ight=quads), that if you want to draw a quad in OpenGLES you have to use GL_TRIANGLES.
So I made something like this:
GLfloat vertices1[] = {v0,v1,v2};

glVertexPointer(3, GL_FLOAT, 0, vertices1);
glDrawArrays(GL_TRIANGLES, 0, 3);

GLfloat vertices2[] = {v1,v2,v3};

glVertexPointer(3, GL_FLOAT, 0, vertices2);
glDrawArrays(GL_TRIANGLES, 0, 3);

and the result is the same like if I do it with GL_QUADS.

My problem is that if I use other vertices order( eg: {v1,v2,v3} and {v3,v0,v1}) I have a different result.

So, using GL_TRIANGLES is not the same that using GL_QUADS.
Do you know if there is any other way to do this? or is the only way?
Thanks in advance,
Santiago Robles

You have to take in count the triangle order… since it use the order to calculate the triangle normal.
Be sure to always the triangle have the same normal of the quad.

You should split a quad in two triangles, (v0, v1, v2) and (v0, v2, v3). These have the same winding order as the quad so backface culling will work the same. You don’t need separate draw calls for each triangle.

Thanks for all your help.
I realized that I have an error in the example that I wrote.
Here I upload an image that have the correction and a draw of what the example makes.

The (1) is the original code with openGL.((v0,v1,v2,v3) or (v1,v2,v3,v0))
The (2) is the modified code that runs with GL_TRIANGLES. ((v0, v1, v2), (v2, v3,v0))
The (3) is another order of the vertices and openGL draw a different figure. (( v1, v2,v3), (v3,v0,v1))
My problem is that I want to draw always the same figure like what happends with GL_QUADS.
Thanks,
Santiago Robles

The problem is that both ways are valid ways of implementing GL_QUADS. There is no “right” way of rendering a quad if the vertices do not lie on a plane.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.