我有点困惑为什么这仍然呈现。我认为您需要绑定一个顶点缓冲区对象,以便 glDrawArrays 知道要使用哪个顶点缓冲区。
这是我的初始化代码..
// Create and bind vertex array to store vertex attribute states.
glGenVertexArraysOES(NUM_VERTEX_ARRAYS, &m_vertexArray);
glBindVertexArrayOES(m_vertexArray);
// Create and bind vertex buffer to store vertex data.
glGenBuffers(NUM_VERTEX_BUFFERS, &m_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * 36, &m_vertices[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(VertexAttribPosition);
glVertexAttribPointer(VertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0));
glEnableVertexAttribArray(VertexAttribNormal);
glVertexAttribPointer(VertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArrayOES(0);
这是我的渲染代码。我很困惑为什么当我将 0 绑定到 GL_ARRAY_BUFFER 时 glDrawArrays 仍然有效。
glBindVertexArrayOES(m_vertexArray);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArrayOES(0);