Loading meshes in assimp to a vbo in opengl

2.3k views Asked by At

I'm using the code at the bottom of this tutorial to load meshes using assimp. Mesh Loading

So I load the meshes and then load the first one into a vbo and then link them to a vao.

glGenVertexArrays(1, &_vertexArray1); //Bind to first VAO
glBindVertexArray(_vertexArray1);
glGenBuffers(1, &_vertexBufferCube1);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferCube1);
glBufferData(GL_ARRAY_BUFFER, g_point_count * 3 * sizeof (float), &g_vp[0], GL_STATIC_DRAW);

glEnableVertexAttribArray(loc1);
glVertexAttribPointer(loc1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(loc2);
glVertexAttribPointer(loc2, 3, GL_FLOAT, GL_FALSE, 0, NULL);

But how can I load the second mesh into the vbo? As in should the second mesh be contained at g_vp[g_point_count * 3 * sizeof (float)]? Because I have tried that and it doesn't work but it's possible something else is wrong.

1

There are 1 answers

2
sirian_ye On

If you are using vao based drawing, you can store different vbos in different vaos. When you are drawing the scene, using glBindVertexArray(vao) and glBindVertexArray(0) to swith between different vaos. There are also better solutions. You can store multiple objects in one vao, but record the index data of each object. Then you can draw each object using glDrawElementsBaseVertex by specifying the index.

This tutorial shows an example of doing the render with glDrawElementsBaseVertex + assimp http://ogldev.atspace.co.uk/www/tutorial38/tutorial38.html