Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: glDrawElements does not uses per index uv/normal!

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    7

    glDrawElements does not uses per index uv/normal!

    I'm trying to draw a textured triangulated indexed quad using glDrawElements but failed with distortion. My verts,norms and uv data all worked correctly with glBegin/glEnd. Upon tweaking, I found that it only worked if input uvs/norms array are poly based(4 pts) instead of per indices of 2 triangles(6 pts). Did i missed something? Here's my failed python code.

    Code :
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glTexCoordPointer(2,GL_FLOAT,0,self.uvRef);
     
        glEnableClientState(GL_NORMAL_ARRAY);
        glNormalPointerf(self.normsRef);
     
        glEnableClientState(GL_VERTEX_ARRAY);
        glVertexPointerf(self.vertsRef);
     
     
        #glDrawElementsus(GL_TRIANGLES,self.indicesRef); Both not working
        glDrawElements(GL_TRIANGLES,self.indicesSize,GL_UNSIGNED_SHORT,self.indicesRef);

    Heres my working glBegin/End inserted before hack:
    Code :
        glBegin(GL_TRIANGLES);
        for i in range(self.indicesSize):
          index=self.indicesRef[i];
          glTexCoord2f(self.uvRef[i][0],self.uvRef[i][1]);
          glNormal3f(self.normsRef[i][0],self.normsRef[i][1],self.normsRef[i][2]);       
          glVertex3f(self.vertsRef[index][0],self.vertsRef[index][1],self.vertsRef[index][2]);
        glEnd();

    Any ideas?
    Thanks.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    802

    Re: glDrawElements does not uses per index uv/normal!

    Hi,
    The second parameter is the total number of indices for the whole mesh you are drawing. If the total number of triangles in your mesh are N then this will be 3*N since every triangle has 3 indices. Could u double check the size of the array.

    Moreover, could u try to use the same functions for assigning the Vertex and Normals as you are using for texture coord.
    Code :
     
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(2,GL_FLOAT,0,self.uvRef);
     
    glEnableClientState(GL_NORMAL_ARRAY);
    glNormalPointer(3, GL_FLOAT,0,self.normsRef);
     
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_FLOAT,0,self.vertsRef);
    glDrawElements(GL_TRIANGLES,self.indicesSize,GL_UNSIGNED_SHORT,self.indicesRef);
    See if this helps,
    Mobeen
    Regards,
    Mobeen

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    7

    Re: glDrawElements does not uses per index uv/normal!

    Just realized that my indices are vertex array relative thus normals/uvs that are not shared will not work. My fault, sorry
    Hmm.. does this mean that basic opengl array drawing does not support shared vertices with unwrapped uv?

Posting Permissions

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