PDA

View Full Version : Displaying Models



Bassam
10-30-2013, 03:08 AM
Hi guys! I am trying to display two or more models on the screen at the same time. I have successfully displayed one model using three buffers, vertex,color,and normal buffer:

glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, model1.vertices.size() * sizeof(vec3), &model1.vertices[0], GL_STATIC_DRAW);


glGenBuffers(1, &colorbuffer);
glBindBuffer(GL_ARRAY_BUFFER, colorbuffer);
glBufferData(GL_ARRAY_BUFFER, model1.vertices.size() * sizeof(vec3), &model1.foreColors[0], GL_STATIC_DRAW);


glGenBuffers(1, &normalbuffer);
glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
glBufferData(GL_ARRAY_BUFFER, model1.vertices.size() * sizeof(vec3), &model1.normals[0], GL_STATIC_DRAW);

////////

Now to display the second object, do I need to repeat the above code with a little change, instead model1, I should use model2?? I actually tried to use model2 instead model1, but what has displayed is just the first model1.

I read in some resources , that I should use glBufferSubData instead of glBufferData, but the problem is that I dont know how to use it. Any idea please? Thanks

Ehsan Kamrani
11-12-2013, 01:01 PM
for each geometry,you should generate one VBO. glBufferSubData is useful for geometries that change over time(for example,skeletal animation)