Hi
Cal3D uses from the following algorithm during the rendering process to get the information of the model:
for all the meshes
for all the sumbemeshes
{
1)get the information of the vertices, normals and texture coordinates as well as vertex, normal and texture coordinate count
2)Draw the submesh with vertex arrays
Vertex data and other data are saved in a 2D array.As an example:
static GLfloat meshVertices[3000][3];
int vertexCount = pCalRenderer->getVertices(&meshVertices[0][0]);
I have no problem with vertex arrays. I draw in this manner:
static GLfloat meshVertices[3000][3];
int vertexCount = pCalRenderer->getVertices(&meshVertices[0][0]);
// get the transformed normals of the submesh
static GLfloat meshNormals[3000][3];
int normalCount = pCalRenderer->getNormals(&meshNormals[0][0]);
// get the texture coordinates of the submesh
static GLfloat meshTextureCoordinates[3000][2];
int textureCoordinateCount = pCalRenderer->getTextureCoordinates(0, &meshTextureCoordinates[0][0]);
// get the faces of the submesh
static CalIndex meshFaces[3000][3];
int faceCount = pCalRenderer->getFaces(&meshFaces[0][0]);
// set the vertex and normal buffers
glVertexPointer(3, GL_FLOAT, 0, &meshVertices[0][0]);
glNormalPointer(GL_FLOAT, 0, &meshNormals[0][0]);
if( (pCalRenderer->getMapCount() > 0) && textureCoordinateCount > 0 )
{
lightModel.EnableSeparateSpecular();
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_COLOR_MATERIAL);
// set the texture id we stored in the map user data
glBindTexture(GL_TEXTURE_2D, (GLuint)pCalRenderer->getMapUserData(0));
// set the texture coordinate buffer
glTexCoordPointer(2, GL_FLOAT, 0, &meshTextureCoordinates[0][0] );
glColor3f(1.0f, 1.0f, 1.0f);
}
if(sizeof(CalIndex)==2)
glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_SHORT, &meshFaces[0][0]);
else
glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_INT, &meshFaces[0][0]);
However with VBOs I only see part of the object:
if( GLEW_ARB_vertex_buffer_object )
{
glBindBufferARB( GL_ARRAY_BUFFER_ARB, VBO_buffer );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, ( 3 * ( vertexCount + normalCount ) + ( 2 * textureCoordinateCount ) )* sizeof( GLfloat ),
NULL, GL_DYNAMIC_DRAW );
glBufferSubData( GL_ARRAY_BUFFER_ARB, 0, 3 * vertexCount * sizeof( GLfloat ), meshVertices );
glBufferSubData( GL_ARRAY_BUFFER_ARB, 3* vertexCount * sizeof( GLfloat ), 3 * normalCount * sizeof( GLfloat ), meshNormals );
glVertexPointer( 3, GL_FLOAT, 0, 0 );
glNormalPointer( GL_FLOAT, 0, BUFFER_OFFSET( 3 * vertexCount * sizeof( GLfloat ) ) );
if( (pCalRenderer->getMapCount() > 0) && textureCoordinateCount > 0 )
{
lightModel.EnableSeparateSpecular();
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_COLOR_MATERIAL);
// set the texture id we stored in the map user data
glBindTexture(GL_TEXTURE_2D, (GLuint)pCalRenderer->getMapUserData(0));
// set the texture coordinate buffer
glTexCoordPointer(2, GL_FLOAT, 0, BUFFER_OFFSET( 3*( vertexCount + normalCount ) * sizeof( GLfloat )) );
glColor3f(1.0f, 1.0f, 1.0f);
}
glDrawArrays( GL_TRIANGLES, 0, 3 );
}
So what’s the problem?
Has it worth to use glBufferData in each loop?( deleting the previous data and reallocation the buffer)
-Ehsan-