Hello, I’m new to openGL platform.
I’m trying to implement a VBO based program to render multiple meshes, given a common vertex list, and individual index lists for each mesh.
In order to simplify things, I deactivated all other meshes and I want to draw only 1 quad, which consists of 2 big triangles.
in init() function I created vertex, normal and index buffers like this:
vertexData = (GLfloat*)malloc(sizeof(GLfloat)*totalNumVertices*3);
...
<parse and create buffers named vertexData and normalData>
glGenBuffers(1, &vboVertex); // buffer for both normals and positions.
glGenBuffers(1, &vboNormal);
glBindBuffer(GL_ARRAY_BUFFER, vboVertex); // activate buffer.
glBufferData(GL_ARRAY_BUFFER, totalNumVertices * 3 * sizeof(GLfloat), vertexData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, vboNormal);
glBufferData(GL_ARRAY_BUFFER, totalNumVertices * 3 * sizeof(GLfloat), normalData, GL_STATIC_DRAW);
// here, for every Mesh structure I create their own index buffer. Then, in display() I plan to call their own index buffers with global vertex and normal buffers.
for(vector<Mesh>::iterator it_mesh = CurrentScene->_meshes.begin(); it_mesh!=CurrentScene->_meshes.end(); it_mesh++)
{
glGenBuffers(1, &(*it_mesh).buffer_id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, (*it_mesh).buffer_id);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, numberoftriangles*3*sizeof(uint), (*it_mesh).indexBuffer, GL_STATIC_DRAW);
}
This code above is roughly the init function.
In Display() function I tried to render scene like this:
for every mesh, do:
<pushmatrix, set material, set modeling transforms>
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, vboVertex); // activate buffer.
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, vboNormal); // activate buffer.
glNormalPointer(GL_FLOAT, 0, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, (*it_mesh).buffer_id);
glDrawElements(GL_TRIANGLES, triangle_count, GL_UNSIGNED_INT, 0);
<pop matrix>
However, I can’t see any output. The screen is black. What might be the problem?
Thanks in advance.