Hi,
I am trying to render using VAO, everything works fine but I just want to understand something.
When I initialize my opengl context using Qt I do also create a VAO this way :
glGenVertexArrays(1, &vao);
glGenBuffers(1, &vertexBuffer);
glGenBuffers(1, &indexBuffer);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, 3*vertices.size() * sizeof(GL_FLOAT), vertices.constData(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3*indices.size() * sizeof(GL_FLOAT), indices.constData(), GL_STATIC_DRAW);
glBindVertexArray(0);
You see that glEnableVertexAttribArray(0); is already there.
However when I want to render (after compiling, linking my shader), I have to use this code in order to have something rendered at my screen.
shaderProgram.bind();
//UNIFORMS
shaderProgram.setUniformValue("mvpMatrix", pMatrix * view * model);
shaderProgram.setUniformValue("color", QColor(255,244,255));
//ARRAYS
//VERTEX ARRAY
glBindVertexArray(vao);
glEnableVertexAttribArray(0);
glDrawElements(rendStyle, indices.size(), GL_UNSIGNED_INT, 0);
glDisableVertexAttribArray(0);
//RELEASE SHADER
shaderProgram.release();
So there is a repetition of glEnableVertexAttribArray(0), If I remove this latter from the rendering part nothing is drawn at the screen.
Now, I don’t understand why I have to use glEnableVertexAttribArray(0) in the rendering part since it was already set up in the vao (initilization part).
Thanks.