我很确定顶点数组没有绑定顶点缓冲区,因为如果我注释掉我取消绑定顶点缓冲区的行,它工作得非常好,这表明顶点数组没有正确绑定顶点缓冲区。这是代码(程序和窗口周围有一些抽象,但与问题无关):
GLuint va;
glGenVertexArrays(1, &va);
glBindVertexArray(va);
GLuint vb;
glGenBuffers(1, &vb);
glBindBuffer(GL_ARRAY_BUFFER, vb);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, (2 + 3) * sizeof(float), nullptr);
glBindAttribLocation(program.id(), 0, "i_position");
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, (2 + 3) * sizeof(float), (const void*)(2 * sizeof(float)));
glBindAttribLocation(program.id(), 1, "i_color");
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0); //< if this line is commented out it works perfectly fine
program.bind();
while(window->isOpen())
{
glfwPollEvents();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(va);
glBufferData(GL_ARRAY_BUFFER, 3 * (2 + 3) * sizeof(float), vertexes, GL_DYNAMIC_DRAW);
glDrawArrays(GL_TRIANGLES, 0, 3);
window->update();
}
有人知道我做错了什么吗?