Results 1 to 5 of 5

Thread: Problem using GL_TRIANGLES instead of GL_QUADS

  1. #1
    Junior Member
    Join Date
    Mar 2008
    Posts
    9

    Problem using GL_TRIANGLES instead of GL_QUADS

    Hi List, Im 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

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

  3. #3
    Senior Member
    Join Date
    May 2006
    Posts
    353

    Re: Problem using GL_TRIANGLES instead of GL_QUADS

    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.
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  4. #4
    Junior Member
    Join Date
    Mar 2008
    Posts
    9
    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. #5
    Senior Member
    Join Date
    May 2006
    Posts
    353
    Quote 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.
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

Similar Threads

  1. GL_TRIANGLES Vertices problem when attempting to draw quads
    By kris in forum Developers Coding:Beginner
    Replies: 1
    Last Post: 07-27-2011, 03:25 AM
  2. OpenGL ES code for GL_Quads
    By parul in forum OpenGL ES general technical discussions
    Replies: 4
    Last Post: 10-03-2008, 01:52 AM

Posting Permissions

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