我正在尝试创建 opengl 三角形,但遇到了一些问题。
EBO:元素阵列缓冲区对象 VAO:顶点阵列对象
虽然我试图在绑定 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。