View Full Version : Texture failure with glTexCoord2f but not glTexCoordPointer

08-24-2006, 07:49 PM
I'm learning how to parse and render a particular model format and have unfortunately hit a brick wall when attempting to apply a texture map to my model. It appears as if the texture map coordinates for each of my triangles is causing the texture map to rotate 90 degrees.

When comparing my code to the source code for an open source model viewer designed for this model file format I cannot find any differences save one: I do not use any of the gl*Pointer calls to render.

After experimenting with the model viewer's code I found that I could recreate my graphical glitch if I forced their code to render "the old fashioned way" like my program does. However, I do not understand what causes my glitch.

I'm wondering if anyone can take a look at this code snippet and provide some insight as to what could cause the texture mapping glitch.


u16 indexCount;
u16 indexStart;
u16* indices;

GLfloat* verticesf;
GLfloat* texcoordsf;

glVertexPointer(3, GL_FLOAT, 0, verticesf);
glTexCoordPointer(2, GL_FLOAT, 0, texcoordsf);

glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, indices + indexStart);
The model viewer draws corretly. However, the glitch shows up if I replace the glDrawElements call with:

glBegin( GL_TRIANGLES );
for( int k = 0; k < indexCount; ++k )
u16 a = indices[indexStart + k];
glVertex3f( verticesf[(a*3)], verticesf[(a*3)+1], verticesf[(a*3)+2] );
glTexCoord2f( texcoordsf[a*2], texcoordsf[(a*2)+1] );
glEnd( );
Am I wrong in thinking the for loop is equivalent to the glDrawElements call? Does something effect the data in glTexCoordPointer values that doesn't effect the data in glTexCoord2f?

I'd appreciate any feedback as this is driving me crazy.

08-24-2006, 10:03 PM
You need to put the gltexcoord call before the glvertex call. Remember, OpenGL is a state machine and the glvertex call provokes a vertex using the current color/texcoords/etc.

08-26-2006, 10:48 PM
Thank you masked, anonymous hero! My misordering of glVertex and glTexCoord was indeed the culprit. I'm fairly certain I would never have noticed this problem. Thanks again!