PDA

View Full Version : glDrawElements does not uses per index uv/normal!



standy
02-06-2011, 03:28 PM
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.



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_UN SIGNED_SHORT,self.indicesRef);


Heres my working glBegin/End inserted before hack:


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.

mobeen
02-06-2011, 04:56 PM
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.



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_UN SIGNED_SHORT,self.indicesRef);

See if this helps,
Mobeen

standy
02-07-2011, 03:15 AM
Just realized that my indices are vertex array relative thus normals/uvs that are not shared will not work. My fault, sorry :o
Hmm.. does this mean that basic opengl array drawing does not support shared vertices with unwrapped uv?