Usage of QOpenGLVertexArrayObject

Viewed 3985

i have a question concering VAO in QT. As supposed here, i wrote the following piece of code for initialization:

void GLWidget::initializeGL() {
    vao.create();
    vao.bind();
    // setting up buffers
    buffer.create();
    buffer.setUsagePattern(QOpenGLBuffer::StaticDraw);
    buffer.bind();
    buffer.allocate(vertices.data(), 3 * vertices.size() * sizeof(float));
    vao.release();

}

In the painting stage, i simply do the following:

void GLWidget::paintGL() {
  // some other code
  vao.bind();
  if(shader_program->isLinked()) {
    shader_program->setUniformValue("mvpMatrix", p_matrix * v_matrix * m_matrix);
    // the interesting part about the buffer:
    shader_program->setAttributeBuffer("vertex", GL_FLOAT, 0, 3);
    shader_program->enableAttributeArray("vertex");
    // the drawing
    glDrawArrays(GL_TRIANGLES, 0, vertices.size());
    shader_program->disableAttributeArray("vertex");
  } 
  vao.release();
} 

This works as far as i am dealing with only one VAO. But while using multiple VAO's, nothing or only one 'object' (buffer) is drawn. The code is exactly the same for each object, so the drawing is always

  1. Bind VAO
  2. Assign variables to the shader program
  3. Draw Triangles
  4. Release VAO

So the question is how to use multiple vao's including different buffers.

1 Answers
Related