|
This tutorial explains how to acess and render mesh
data with OGL(see appOptimizeVBO sample).
// Create the scene object
bX::Scene *scn = new bX:Scene();
// Open file with scene data
bX::File *f = bX::OpenFileStream("exported_data.bx");
// Load scene data
scn->Read(f);
// Get the mesh datablock data
bX::Mesh *msh = scn->GetMesh("Cube");
// Support variables to store the mesh vertices normals and positions.
bX::Vec3 *vertex_position, *vertex_normal;
// Get the vertex data.
bX::GetVertexBuffer(msh,&vertex_position,&vertex_normal);
// Create support variables to process and store the mesh triangulated faces.
bX::Export_TriangleFace *tris= NULL;
unsigned int *tris_faces = NULL;
unsigned int tris_count = 0;
// Get faces data.
bX::GetFaceBuffer(msh,&tris,&tris_count);
// Create the face buffer for OGL rendering
tris_faces = new unsigned int[tris_count*3];
// Copy triangles vertices id's to the buffer
for(unsigned int i = 0;i<tris_count;i++)
{
tris_faces[i*3] = tris[i].m_Vertices[0];
tris_faces[i*3+1] = tris[i].m_Vertices[1];
tris_faces[i*3+2] = tris[i].m_Vertices[2];
}
In the rendering method use the following lines.
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glNormalPointer(GL_FLOAT,0,(void*)vertex_position);
glNormalPointer(3,GL_FLOAT,0,(void*)vertex_normal);
glDrawElements(GL_TRIANGLES,tris_count*3,GL_UNSIGNED_INT,(void*)tris_faces);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
The rendering can be improved by using the OGL VBO extensions, it's the same
code, only with diferent opengl extensions.
|