Original Post
I'm currently working on a project where I have a room with furniture in it. The problem I'm having now is that I'm reading in meshes and aligning the vertex and normal data for the vbo functionality per item and the second furniture item to be drawn is taking on the attributes of the first. For example, I read in a couch mesh (it draws fine using vbo) and then I read in a lamp mesh (when I draw the lamp it draws in the shape of the couch). I've created a class to do all of this so the code looks like: I of course skipped code that isn't necessary to my problem like pushmatrix(), translate, rotate, etc.
// load the couch and set it up for vbo drawing
// ObjLoader is my mesh loading class
ObjLoader oLoader("couch.txt");
// ObjModel is an object that holds all of the meshes data
ObjModel *oModel = oLoader.ReturnObj();
// AlignForVBOs sets up the vert/normal/index data for vbo usage
// it returns the index buffer number
nCouchVBO = oModel->AlignForVBOs();
nCouchTriangles = oModel->NumTriangle;
// load the lamp and set it up for vbo drawing
oLoader.LoadObj(LAMP_FILE);
oModel = oLoader.ReturnObj();
nLampVBO = oModel->AlignForVBOs();
nLampTriangles = oModel->NumTriangle;
Inside the AlignForVBOs function I generate the buffers and set things up like so:
unsigned int vbos[3];
glGenBuffers(3, vbos);
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, vbos[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(ObjVertex) * this->NumVertex, this->Aligned_Vertex_Data, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0);
glEnableClientState(GL_NORMAL_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, vbos[1]);
// i'm using numvertex here again because the vertex array and normal array should be the same for the vbo
glBufferData(GL_ARRAY_BUFFER, sizeof(ObjNormal) * this->NumVertex, this->Aligned_Normal_Data, GL_STATIC_DRAW);
glNormalPointer(GL_FLOAT, 0, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbos[2]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(ObjIndex) * this->NumTriangle, this->Aligned_Index_Data, GL_STATIC_DRAW);
return vbos[2];
I then draw like so:
// draw using vbo's
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, nCouchVBO);
glDrawElements(GL_TRIANGLES, (nCouchTriangles * 3), GL_UNSIGNED_INT, 0);
// draw using vbo's
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, nLampVBO);
glDrawElements(GL_TRIANGLES, (nLampTriangles * 3), GL_UNSIGNED_INT, 0);