I am a new learner in OpenGL. I am learning VAO and VBO to draw a simple triangle right now. I follow the video and write the code to generate and validate VAO and VBO like this
`void CreateTriangle()
{
GLfloat vertices[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f
};
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
everything works fine but I am not understand the last two lines:
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);`
I used glbindbuffer and glbindvertexarray before:
glBindVertexArray(VAO); glBindBuffer(GL_ARRAY_BUFFER, VBO);
that’s why I don’t understand why I need to do that again.
I tried to comment these two line:
` glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);`
and everything still works fine, which makes me confused more
I tried to comment lines which I don’t understand and found no error when I ran the code, which makes me confused about the meaning of these two lines I commented.
ScreamingBone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.