if there is no “glBindBuffer(…)”, how can glDrawArrays(…) know what array of data it should draw ???
that makes no sense ! there must be anywhere a glBindBuffer(), at least when you set up your vertexarray
example
void Init()
{
// create shader
float vertices[] = {
// x y z u v normal
0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
};
glGenVertexArrays(1, vao);
glBindVertexArray(vao);
glGenBuffers(1, vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// BEFORE you specify any attribute pointers, there must be a buffer bound from which to read the data !!!
// no GL_ARRAY_BUFFER, no data source
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 8, (void*)(sizeof(float) * 0));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 8, (void*)(sizeof(float) * 3));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 8, (void*)(sizeof(float) * 5));
// now all 3 attributes use the same buffer "vbo", because it was bound when the pointers where specified
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
void render()
{
glUseProgram(shader);
glBindVertexArray(vao);
// when you enable an attribute, how does openGL "know" from where to get the data ???
// answer: see above
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glBindVertexArray(0);
glUseProgram(0);
}