When I parse out 3d model info from almost any format, I get 6 different arrays like so.
Vector* vertArray;
int* vertIndicies;
Vector* normalArray;
int* normalIndicies;
Vector* uvArray;
int* uvIndicies;
When I first set off to making my 3D engine, I used OpenGL’s immediate mode (SLOW). I am drawing my objects like so.
//Psuedo Code
for each face
for each vert in face
glTexCoord2dv(getUV( face,vert))
glNormal3dv( getNorm(face,vert))
glVertex3dv( getVert(face,vert))
Just for clarity, here is an example of how the getUV()
function will get the UV. I have an array of faces (aka polygons), The face knows what index its first vert is, and then I offest by the index of the vert in that face (usually 0-3).
getUV(int faceIndex, int vertIndex) {
return uvArray[ uvIndicies[ faceArray[faceIndex].startIndex + vertIndex ] ];
}
Long story short, this works. But only because I have separate index arrays from my verts, UVs and Normals. As we all know a single vertex can have different UVs or normals, depending on which face we are associating it with.
My problem is when I switched over to vertex arrays I have code like this:
glVertexPointer(3, GL_DOUBLE, sizeof(Vector), vertArray);
glNormalPointer(GL_DOUBLE, sizeof(Vector), normalsArray);
glTexCoordPointer(2, GL_INT, sizeof(Vector), uvArray);
glDrawElements(GL_QUADS, numVertIndices, GL_UNSIGNED_INT, vertIndicies);
Oh, great, my model draws corrrectly, but the UVs, and normals are all wrong.
Is OpenGL using the vertIndices to index into my normal and uv array?! How can I tell OpenGL to use used my other index arrays to get UV and normal data?
Thanks All,
~GameQ