OK, hopefully somone can point out what I'm doing wrong here. I had been storing each polygons vertices with that polygon, but have now changed it to index into a main vertex array, which saves a huge amount of memory, as many of the vertices were repeated. I then decided to use vertex arrays so i now have my vertex array data stored like this:
double* m_dVertexArray; // Vertex array
When i load the number of vertices in the level from my file, the memory is allocated like so, with 3 doubles for each vertex:
// Create array of correct size
m_dVertexArray = new double[iVertexArraySize * 3];
But when I try rendering using vertex arrays I just get a complete load of jumbled polygons on the screen. So I tried to do the indexing into the array myself and that works fine using this code:
// Loop through the polygon list
for (CurrentPolygon; CurrentPolygon != NULL;)
{
// Bind the polygons texture
glBindTexture(GL_TEXTURE_2D, CurrentPolygon->TexID);
// Draw polygon
glBegin(GL_POLYGON);
// Loop through all vertices and draw each one
for (int i = 0; i < CurrentPolygon->GetVertexCount(); i++)
{
// Set texture coordinates
glTexCoord2d(CurrentPolygon->Vertices[i].tex[0],
CurrentPolygon->Vertices[i].tex[1]);
// Draw vertex i
glVertex3d(m_dVertexArray[CurrentPolygon->Vertices[i].index],
m_dVertexArray[CurrentPolygon->Vertices[i].index + 1],
m_dVertexArray[CurrentPolygon->Vertices[i].index + 2]);
}
// Finished drawing polygon
glEnd();
// Move to next polygon in linked list
CurrentPolygon = CurrentPolygon->GetNextPolygon();
}
But when i change the glVertex3d call to:
glArrayElement(CurrentPolygon->Vertices[i].index);
I get a load of garbage on the screen. The vertex array data is valid otherwise the first rendering code wouldn't work. I set up to use vertex arrays like this:
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_DOUBLE, 0, m_dVertexArray);
I can't figure out what I'm doing wrong, but it must be pretty obvious to someone with a bit of experience with vertex arrays, so...HELP!!
(Sorry for the long post)
FatalXC
Edited by - FatalXC on June 29, 2001 11:37:08 PM