Original Post
So I wanted to make an MD2 loader... Well, I started off easy, by loading only the 1st frame using those horrid glBegin()/glEnd() functions. And it worked! I could load the Q2 models nicely. But then I wanted to render the models with VA (and then later on, VBO) method and now I'm seeing incomplete or corrupted models rendered on the screen. But, I should say, the MD2 models that were actually quite primitive (pyramids, cubes, hex prisms...) I had no problem rendering correctly. screenshot: http://i34.tinypic.com/2vudi7n.jpg code: rendering: NOTE: 'vertices_original' stores model's vertices on the local coordinate system 'vertices' stores model's vertices on the global (world) coordinate system and 'coords' are the model's origin coords of the global (world) coordinate system so basically coords + vertices_original positions the object into the world. P.S.: I'm kind of new to 3D, so I'm not sure if I used the phrases correctly :) [Edited by - Thirthe on September 2, 2008 7:11:13 AM]
index_num = model->header->num_tris * 3;
vertex_num = model->header->num_vertices * 3;
indices = new GLubyte[ index_num ];
vertices = new GLfloat[ vertex_num ];
vertices_original = new GLfloat[ vertex_num ];
color = new GLfloat[ vertex_num ];
int j;
for( int i = 0, j = 0; i < model->header->num_tris; ++i )
{
indices[j++] = model->triangle.vertexIndices[0];
indices[j++] = model->triangle.vertexIndices[1];
indices[j++] = model->triangle.vertexIndices[2];
}
// TODO: remember, there can be more than 1 frame
for( int i = 0, j = 0; i < model->header->num_vertices; ++i )
{
vertices_original[j++] = (model->frame[0].vertices.vertex[0] * model->frame[0].scale[0]) + model->frame[0].translate[0];
vertices_original[j++] = (model->frame[0].vertices.vertex[1] * model->frame[0].scale[1]) + model->frame[0].translate[1];
vertices_original[j++] = (model->frame[0].vertices.vertex[2] * model->frame[0].scale[2]) + model->frame[0].translate[2];
}
mode_primitive = GL_TRIANGLES;
coords[0] = x; // user-defined origin coords
coords[1] = y;
coords[2] = z;
for( unsigned int i = 0U; i <= vertex_num - 3; i += 3 )
{
vertices = coords[0] + vertices_original;
vertices[i+1U] = coords[1] + vertices_original[i+1U];
vertices[i+2U] = coords[2] + vertices_original[i+2U];
}
glEnableClientState( GL_COLOR_ARRAY );
glEnableClientState( GL_VERTEX_ARRAY );
glColorPointer( 3, GL_FLOAT, 0, color );
glVertexPointer( 3, GL_FLOAT, 0, vertices );
glDrawElements( mode_primitive, index_num, GL_UNSIGNED_BYTE, indices );
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_COLOR_ARRAY );