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);

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?
Santiago Robles

2. 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.

4. 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

5. Originally Posted by srobles
My problem is that I want to draw always the same figure like what happends with GL_QUADS.
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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•