我正在尝试创建OpenGL三角形,但遇到了一些问题。
EBO: ElementArrayBufferObject VAO: VertexArrayObject
当我尝试在绑定VAO之前绑定EBO时,它会导致错误,我不知道为什么。
我的代码:
EBO: ElementArrayBufferObject VAO: VertexArrayObject
当我尝试在绑定VAO之前绑定EBO时,它会导致错误,我不知道为什么。
我的代码:
// Generate the VAO and VBO with only 1 object each
glGenVertexArrays(1, &VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
// Make the VAO the current Vertex Array Object by binding it
glBindVertexArray(VAO);
在渲染时它会引起问题。
如果我按照这个顺序修复代码。
// Generate the VAO and VBO with only 1 object each
glGenVertexArrays(1, &VAO);
// Make the VAO the current Vertex Array Object by binding it
glBindVertexArray(VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
它按照我的预期工作。
我真的不知道为什么在绑定VAO之前没有绑定EBO而导致它无法工作。