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..
Technically, they don't have to do the extra bind in this case. However, it's a good idea to do so, because it's very easy to accidentally break code that doesn't use it. If the programmer wants to change the buffer creation code to create two buffer objects, using the GL_ARRAY_BUFFER
binding, then the subsequent code would be broken.
However, if you bind the correct buffer, then it will always work, no matter what you did before.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments