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
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    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?

Similar Threads

  1. glDrawElements - multiple calls, one index array?
    By Robbie in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 11-29-2011, 10:17 AM
  2. Sending UV/Normal index info to glDrawElements
    By GameQ in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-24-2009, 12:48 PM
  3. Normals index with glDrawElements !
    By golgoth13 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-08-2006, 12:41 AM
  4. glDrawElements index bias parameter (like in d3d9)
    By Nitrogenycs in forum OpenGL: General
    Replies: 0
    Last Post: 12-21-2004, 09:08 AM
  5. vertexdata per index in glDrawElements
    By jabe in forum OpenGL: General
    Replies: 2
    Last Post: 02-03-2001, 03:08 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
  •  
Proudly hosted by Digital Ocean