PDA

View Full Version : Vertex array skews texture coordinates???



xpnctoc1
10-19-2014, 05:56 PM
I'm not a complete newbie to OpenGL programming, but I've hit a wall I'm hoping someone can help me with. Seems like a pretty basic question. Maybe I just need another pair of eyes...

I have the following code to try to draw a rectangle using vertex arrays:



glEnableClientState( GL_NORMAL_ARRAY );
glNormalPointer( GL_FLOAT, 0, &mNorms[ 0 ] );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glTexCoordPointer( 2, GL_FLOAT, 0, &mTexCrds[ 0 ] );
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 3, GL_FLOAT, 0, &mVtxs[ 0 ] );
glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );


The intent is to draw a simple rectangle via triangle strip using the corner pattern Far Left, Near Left, Far Right, Near Right. The variable values are as follows:



/* far left near left far right near right */
mNorms { 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0 }
mTexCrds { 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0 }
mVtxs { -25.0, 0.0, -100.0, -25.0, 0.0, -50.0, 25.0, 0.0, -100.0, 25.0, 0.0, -50.0 }


My texture is a black tile with a thin blue border around all edges. When the rectangle is drawn using the above instructions, it is completely blue:

1491

Obviously, given the above texture coordinates I am expecting my 2D texture to be completely visible.

If I replace glDrawArrays() with a manually invocation using the same array data like this...



glBegin( GL_TRIANGLE_STRIP );
{
for( int i = 0; i < 4; ++i )
{
glNormal3fv( &mNorms[ i * 3 ] );
glTexCoord2fv( &mTexCrds[ i * 2 ] );
glVertex3fv( &mVtxs[ i * 3 ] );
}
}
glEnd();


... then the rectangle is drawn with the full texture map image visible as I expect:

1492

Any idea why glDrawArrays() would skew my texture so badly? Thanks for your help in advance!