Problems applying texture to a triangle strip using glTexCoordPointer
- by Alexey
Hi,
I'm writing a pretty simple piece of code which should draw a plane. The plane must have two different textures on its sides, like if it was a book page.
I'm trying to achieve this by doing this:
glFrontFace(GL_CCW);
glBindTexture(GL_TEXTURE_2D, textures[kActiveSideLeft]);
glVertexPointer(3, GL_FLOAT, 0, vertexCoordinates);
glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates);
glDrawArrays(GL_TRIANGLE_STRIP, 0, (2 * kHorizontalSegmentsCount + 4) * kVerticalSegmentsCount);
glFrontFace(GL_CW);
glBindTexture(GL_TEXTURE_2D, textures[kActiveSideRight]);
glVertexPointer(3, GL_FLOAT, 0, vertexCoordinates);
glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates);
glDrawArrays(GL_TRIANGLE_STRIP, 0, (2 * kHorizontalSegmentsCount + 4) * kVerticalSegmentsCount);
textures[] array contains 2 GLuint textures which specify appropriate textures.
vertexCoordinates and textureCoordinates contain vertexes and texture coordinates respectively
((2 * kHorizontalSegmentsCount + 4) * kVerticalSegmentsCount) equals 15 and that's exactly how many elements I have in the arrays
I set up opengl like this:
glEnable(GL_DEPTH_TEST);
glClearDepthf(1.0f);
glDepthFunc(GL_LEQUAL);
glClearColor(0.0, 1.0, 1.0, 1.0);
glEnable(GL_TEXTURE_2D);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
What happens is when I run it front side of the plane looks Ok, but it appears like if texture coordinates weren't applied to the back side.
It appears like texture on the back side is just tiled and not connected to vertexes by any means.
Any idea what am I doing wrong?
Or any idea about what can I do to debug this problem?
Thanks.