void prepare_axes(void) {
axes[0][0] = -win_width / 2.5f; axes[0][1] = 0.0f;
axes[1][0] = win_width / 2.5f; axes[1][1] = 0.0f;
axes[2][0] = 0.0f; axes[2][1] = -win_height / 2.5f;
axes[3][0] = 0.0f; axes[3][1] = win_height / 2.5f;
// Initialize vertex buffer object.
glGenBuffers(1, &VBO_axes);
glBindBuffer(GL_ARRAY_BUFFER, VBO_axes);
glBufferData(GL_ARRAY_BUFFER, sizeof(axes), axes, GL_STATIC_DRAW);
// Initialize vertex array object.
glGenVertexArrays(1, &VAO_axes);
glBindVertexArray(VAO_axes);
glBindBuffer(GL_ARRAY_BUFFER, VBO_axes);
glVertexAttribPointer(LOC_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
I was looking into OpenGL source code, but I didn't understand why call glBindBuffer(GL_Array_Buffer, VBO_axes) twice.
From my understanding, after the first time they call glGenBuffer, glBindBuffer and glBufferData,
the information of the variable 'axes' is stored in GL_ARRAY_BUFFER.
After that, they generate, bind VAO and call glBindBuffer again.
I can't understand why they did that.
I knew that glBufferData() deletes the current buffer store if there already was one, and creates a new buffer store. This means that the information of the variable 'axes' is fade away when calling glBindBuffer secondly.
Help me please..
glBindBuffer
occurs within the context of the currently boundVAO
. So the first call toglBindBuffer
will bindVBO_axes
to whicheverVAO
is bound at that point (presumably the defaultVAO
) whereas the second call toglBindBuffer
will bind toVAO_axes
. (Not sure I've got the terminology entirely correct here, so I'm leaving this as a comment rather than an answer.) – G.M.glBindBuffer
only affects VAO state if you're binding to theGL_ELEMENT_ARRAY_BUFFER
target. TheGL_ARRAY_BUFFER
binding is not part of VAO state. – Nicol Bolas