Basically I can render the geometry perfectly, and its textured too, but the texture is just badly applied to it. It was working fine before I switched to vertex arrays, so I assume that im just loading the textureArray in a wrong way.
This is what I do :
I load the md2 header and get the number of st’s from that.
Then create a “buffer” to the texture info in the file.
stIndex_t stPtr;
stPtr = (stIndex_t)&buffer[modelHeader->offsetST];
texVB= new float[2*m_numST];
and load up the st’s into my array which is the array i pass
to glTexCoordPointer(2, GL_FLOAT, 0, texVB);
for (t = 0; t < m_numST; t++)
{
texVB[2t+0]= (float)stPtr[t].s / (float)m_modelTex->width;
texVB[2t+1]= (float)stPtr[t].t / (float)m_modelTex->height;
}
And after that I just render using
glTexCoordPointer(2, GL_FLOAT, 0, texVB);
and
glDrawElements… which works since my mesh shows up fine
Any help is greatly appreciated, ive been stuck on this problem for a few days
OK, the problem I think is that the geomtric vertices and the number of texture coordinates don’t match one for one in MD2 files. Also, their indices don’t either. Vertex arrays require a one to one mapping for all vertex attributes.
Basically, your DrawElements() takes a pointer to some indices, and those indices are used for both geometry and texture coordinate lookups - but with MD2s the geometry indices aren’t the same as the texture coordinate indices, hence your problem.
A solution that might be viable is to duplicate coordinates where the indices don’t match.
ok i figure something out, mostly that I will have 6 indices per triangle (1 st value per vertice).
So after I load up my triangle and texture index, which I know is right because when I was doing the rendering vertex per vertex it worked fine, I load up the array like such:
Originally posted by dopeflow: yup i fixed that, doesnt work more though
The detail is mind boggling.
What do you mean it doesn’t work? Can you supply a screen shot? Are you getting any errors from OpenGL? (glGetError()) Is it simply that the textures are not displaying correctly (ie. Is this an Opengl problem at all or are you just unable to load and display MD2 models)?
Since you said it works OK when using immediate mode, I’m fairly confident the one-one mapping of texture/geometric coordinates is your problem. As I said, duplication of vertices is a solution.
Yes, you would do this during initialisation, when you load in your MD2.
A simple way to do this is to run through your face index arrays and just lift the geometric/texture coordinates they point at and put them in two new arrays. You wind up with a lot of duplication )probably where you don’t need it), but it’ll get it working for you quickly, and you can always implement a smarter algorithm later.
Ah… (clunk) That’s your problem. TexPointer expects 2 values per vertex - It’s not linked to the triangles, it’s the vertices that count. So if you have 8 vertices and 12 triangles you need 8 st’s.
Also in the md2 format, in the header theres an offset to the St’s. So I load up the whole file in a buffer and then get to the beginning of the st’s using the offset.
But the number of st’s is different than the number of vertices. I dont know why they made it complicated like that in their format
First thing you should do is go off, find a copy of the Red book and read up on DrawElements(), VertexPointer(), TexPointer() etc. as you are showing a lack of knowledge of how these work at their basic level.
Second thing you should get clear in your mind is the difference between indices and vertices. DrawElements takes a list of indices and you seem to be stuck on the idea that if you have a triangle then you will have texture coords for each of the indices (not each of the vertices).
Triangles do NOT have texture coords, vertices have texture coords. The number of elements in the array supplied in glVertexPointer() is the same as the number in glTexPointer() and is (most likely) different to the number in glDrawElements().
Yea i know pretty much all that. The only thing im wondering about is that obviously you have to take the st’s you load from the file and put them in the right order in your texture array. But Im just not sure how to do that.