I got interested in Shamino's perpetual plight to implement a central data format. Subsequently, I implemented a mechanism for my 'own' basic layout that can be rendered using vertex arrays.
Now, as far as I can see I've gotten things to work, but when I render everything using glVertex/TexCoord pointer and then glDrawArrays, I can an exception in my ATI driver (accessing something it shouldn't be). When I render the data 'manually' using 'stop and start' immediate mode GL, it renders fine, meaning that the data is 'correct.' Somewhere, I'm goofing up bigtime.
Below is the two different ways I render 'NT_MODELs'
PHP Code:
#if 1
int start_index = mesh_ref.mStartVertIndex;
//also tried start_index = mdl_ref.mpIndexArray[mesh_ref.mStartVertIndex]
NT_GL(glVertexPointer(3,GL_FLOAT,sizeof(NT_VERTEX),&mdl_ref.mpVertices[start_index].vertex))
NT_GL(glTexCoordPointer(2,GL_FLOAT,sizeof(NT_VERTEX),&mdl_ref.mpVertices[start_index].tex_coord))
NT_GL(glDrawElements(GL_TRIANGLES,mesh_ref.mNumMeshVerts,GL_UNSIGNED_INT,&mdl_ref.mpIndexArray[mesh_ref.mStartVertIndex]))
#else
gpNTGLAPI->ntglBegin(GL_TRIANGLES);
for(int j = 0; j < mesh_ref.mNumMeshVerts; j += 3)
{
for(int k = 0; k < 3; k++) //plot each coordinate w/texture coord
{
int index = mdl_ref.mpIndexArray[j + k + mesh_ref.mStartVertIndex];
NT_VERTEX & vert_ref = mdl_ref.mpVertices[index];
gpNTGLAPI->ntglTexCoord2f(vert_ref.tex_coord[0],vert_ref.tex_coord[1]);
gpNTGLAPI->ntglVertex3fv(vert_ref.vertex);
}
}
gpNTGLAPI->ntglEnd();
#endif
First way crashes, second renders perfectly.
This is similar, if not ultimately identical in structure, to how I render quake3 faces (a quake3 face is ultimately a mesh, the bsp has an index array)
PHP Code:
i = mvQuake3SingleTexturedFaces.at(k);
gpTextureManager->BindTexture(GL_TEXTURE_2D,gpBSP->mpGLTextures[gpBSP->mpFaces[i].textureID]);
NT_GL(glVertexPointer(3,GL_FLOAT,sizeof(tBSPVertex),&gpBSP->mpVertices[gpBSP->mpFaces[i].startVertIndex].vPosition))
NT_GL(glTexCoordPointer(2, GL_FLOAT,sizeof(tBSPVertex), &gpBSP->mpVertices[gpBSP->mpFaces[i].startVertIndex].vTextureCoord))
//doesn't work when you pass GL_FLOAT instead of int
NT_GL(glDrawElements(GL_TRIANGLES, gpBSP->mpFaces[i].numMeshVerts, GL_UNSIGNED_INT, &gpBSP->mpIndexArray[gpBSP->mpFaces[i].meshVertIndex]))
This is quite strange indeed. I'm sure I'm doing something simple wrong.