Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualrocklobster

Posted 07 June 2012 - 12:04 PM

Hrm, it only seems to be drawing the first VBO. Hate to post a bit of a code dump, but someone might be able to spot an error?

First i'm creating a vertex array object and binding it. Then i iterate over the model data in each VBO and create the opengl VBO from it.

void loadModel(Model* model, bool withIBO)
{
  unsigned int indexCount = 0;
  GLuint vaoID;
  glGenVertexArrays(1, &vaoID);
  glBindVertexArray(vaoID);
  model->setVAOHandle(vaoID);
  for (int i = 0; i < (signed)model->getVBOs()->size(); i++)
  {
   VBO vbo = model->getVBOs()->at(i);
   GLuint vboID;
   glGenBuffers(1, &vboID);
   glBindBuffer(GL_ARRAY_BUFFER, vboID);
   glBufferData(GL_ARRAY_BUFFER, vbo.getArray().size() * sizeof(Vertex), &vbo.getArray()[0], GL_STATIC_DRAW);
   glEnableVertexAttribArray(0);
   glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(0));
   glEnableVertexAttribArray(1);
   glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(12));
   glEnableVertexAttribArray(2);
   glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(24));
   vbo.setVBOID(vboID);
   GLuint iboID;
   glGenBuffers(1, &iboID);
   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iboID);
   glBufferData(GL_ELEMENT_ARRAY_BUFFER, vbo.getIBO().getArray().size() * sizeof(unsigned int), &vbo.getIBO().getArray()[0], GL_STATIC_DRAW);
   vbo.setIBOID(iboID);
   indexCount += vbo.getIBO().getArray().size() * sizeof(unsigned int);
  }
  model->setTotalIndices(indexCount);
}
...
void drawModel(Model* model)
{
		 glBindVertexArray(model->getVAOHandle());
		 glDrawElements(GL_TRIANGLES, model->getTotalIndices(), GL_UNSIGNED_INT, BUFFER_OFFSET(0));

}

#1rocklobster

Posted 07 June 2012 - 12:03 PM

Hrm, it only seems to be drawing the first VBO. Hate to post a bit of a code dump, but someone might be able to spot an error?

void loadModel(Model* model, bool withIBO)
{
  unsigned int indexCount = 0;
  GLuint vaoID;
  glGenVertexArrays(1, &vaoID);
  glBindVertexArray(vaoID);
  model->setVAOHandle(vaoID);
  for (int i = 0; i < (signed)model->getVBOs()->size(); i++)
  {
   VBO vbo = model->getVBOs()->at(i);
   GLuint vboID;
   glGenBuffers(1, &vboID);
   glBindBuffer(GL_ARRAY_BUFFER, vboID);
   glBufferData(GL_ARRAY_BUFFER, vbo.getArray().size() * sizeof(Vertex), &vbo.getArray()[0], GL_STATIC_DRAW);
   glEnableVertexAttribArray(0);
   glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(0));
   glEnableVertexAttribArray(1);
   glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(12));
   glEnableVertexAttribArray(2);
   glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(24));
   vbo.setVBOID(vboID);
   GLuint iboID;
   glGenBuffers(1, &iboID);
   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iboID);
   glBufferData(GL_ELEMENT_ARRAY_BUFFER, vbo.getIBO().getArray().size() * sizeof(unsigned int), &vbo.getIBO().getArray()[0], GL_STATIC_DRAW);
   vbo.setIBOID(iboID);
   indexCount += vbo.getIBO().getArray().size() * sizeof(unsigned int);
  }
  model->setTotalIndices(indexCount);
}
...
void drawModel(Model* model)
{
		 glBindVertexArray(model->getVAOHandle());
         glDrawElements(GL_TRIANGLES, model->getTotalIndices(), GL_UNSIGNED_INT, BUFFER_OFFSET(0));
 
}

PARTNERS