小编use*_*474的帖子

EBO 和 VAO 之间的 OpenGL 绑定顺序

我正在尝试创建 opengl 三角形,但遇到了一些问题。

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);
Run Code Online (Sandbox Code Playgroud)

它在渲染时引起问题。

如果我像这样修复代码。

// 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);
Run Code Online (Sandbox Code Playgroud)

它按我的预期工作。

我真的不知道为什么不在 VAO …

c++ opengl buffer vertex glad

3
推荐指数
1
解决办法
1786
查看次数

标签 统计

buffer ×1

c++ ×1

glad ×1

opengl ×1

vertex ×1