Friday, 6 September 2013

Drawing Multiple Models with dlDrawArrays

Drawing Multiple Models with dlDrawArrays

I have a struct to store vertex data for 2 distinct models one is a cube
the other a pyramid.
Model cubeModel;
Model pyramidModel;
cubeModel.vbo = cubeVerts; //an array designated earlier.
cubeModel.drawCount = sizeof(cubeVerts);//size of the vbo in bytes
pyramidModel.vbo = pyVerts;
pyramidModel.drawCount = sizeof(pyVerts);
glGenBuffers(1, &m_vertexBuffer); //Generate a buffer for the vertices
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer); //Bind the vertex buffer
glBufferData(GL_ARRAY_BUFFER, cubeModel.drawCount, cubeModel.vbo,
GL_STATIC_DRAW);
And then to draw I use:
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, cubeModel.drawCount);
glDisableClientState(GL_VERTEX_ARRAY);
Which works, and I successfully draw the cube, But i've been trying
multiple ways to draw the pyramid as well.
What do I need to do to render both on screen at the same time?
EDIT: Here's what i've tried specifically, duplicating the glBufferData()
call and passing in the pyramid data then making
glDrawArays(GL_TRIANGLES,0,cubeModel.drawcount+pyramidModel.drawCount)
figuring the vertex data would stack and glDrawArrays would go through all
the geometry passed in one go.
I've also tried making 2 sets of instructions from glGenBuffers() to
glDisableClientState() but instead using all of pyramid model's data. This
was interesting because my glDrawArrays was:
glDrawArrays(GL_TRIANGLES, 0, cubeModel.drawCount);
glTranslatef(4.0f,0.0f,0.0f);
glDrawArrays(GL_TRIANGLES, 0, pyramidModel.drawCount);
and it ended up drawing a really messed up pyramid 2 times, leading me to
believe that when I cal glBufferData() twice the second time Overwrites
the data previously passed.

No comments:

Post a Comment