In my project, I have some static array contain the vertex, the texture coordinate, and normal. When I set all the array point with glVertexPointer, glNormalPointer and glTexCoordPointer and use glDrawArrays to render the object, the polygons are correct, but the texture is messed up. I do not understand why. After that, I apply glTexCoord2fv and glNormal3fv glVertex3fv to the same array, that gives me the correct texture mapping. Can anyone help me?
First of all it’s simplier to help u looking at some code.
The only thing that comes to my mind (strange) is to check for the data format passed to the glTexCoordPointer…
If you do 2D texturing, the number of components is 2, not 3 as in the vertex and normal array. I have done this error a few times myself…
well, guess what, I change the glTexCoordPointer(2, GL_FLOAT, 4*sizeof(GLfloat), count, pointer) to glTexCoordPointer (3, …) or glTexCoordPointer (4, …), that gives me the correct texture mapping. Although I use 4 components for each element in the array, only the first 2(s & t) is used, I do not understand why change the “size” in glTexCoordPointer will give the correct result.
> well, guess what, I change the glTexCoordPointer(2, GL_FLOAT, 4*sizeof(GLfloat), count, pointer) to glTexCoordPointer (3, …)
The stride looks rather strange. Unless you are using an interleaved format, shouldn’t it be glTexCoordPointer(2, GL_FLOAT, 2*sizeof(GLfloat),count,pointer) ?
I use a float for each texture coordinate, so I use a stride equal to 4sizeof(float), but I only use float, float to store the s and t, r and q are not used. I tested my code on a friend’s computer, he has a rage128(much better than my old G200), and the program works fine with glTexCoordPointer(2, GL_FLOAT, 4sizeof(GLfloat), count, pointer). I think it is a driver problem that cause the wrong texture mapping. Is it so? I am not sure. And another problem I’ve noticed, on my G200, whenever the model is clipped by view frustum, there are a few triangles appear between two seperate vertex(two vertex that are not connected), just like when I combine two triangle strip vertex list in a single glBegin(GL_TRIANGLE_STRIP)&glEnd(), there will be a few wrong triangle between the last two vertex of the first list and the first two vertex of the second list. The wrong triangles only appear at the first time the model is clipped, when it moves on, those triangles will disappear. That does not happen on my friend’s rage128, so is it another driver bug?