【发布时间】:2011-12-27 16:14:39
【问题描述】:
我对 VBO 有这个问题,我不太了解。我的问题是通过意外更改 glVertexAttribPointer 方法调用中的最后一个参数来解决的。因此,我正在寻找关于 为什么 这突然起作用或为什么我以前的代码不再起作用的答案。 (只是为了更好地了解opengl)
结构:
typedef struct
{
float position[3];
float color[4];
} Vertex;
没有 VBO:
// Get pointers to the data
GLsizei stride = sizeof(Vertex);
const GLvoid *pCoords = &squareVertices[0].position[0];
const GLvoid *pColors = &squareVertices[0].color[0];
// Setup pointers to positions and colors
glVertexAttribPointer(positionSlot, 3, GL_FLOAT, GL_FALSE, stride, pCoords);
glVertexAttribPointer(colorSlot, 4, GL_FLOAT, GL_FALSE, stride, pColors);
// Draw
glDrawArrays(GL_TRIANGLES, 0, sizeof(squareVertices) / sizeof(Vertex));
使用 VBO(这给了我一个 EXC_BAD_ACCESS)
// Stide
GLsizei stride = sizeof(Vertex);
// Setup pointers to positions and colors
glVertexAttribPointer(positionSlot, 3, GL_FLOAT, GL_FALSE, stride, 0);
glVertexAttribPointer(colorSlot, 4, GL_FLOAT, GL_FALSE, stride, (GLvoid*) (sizeof(float) * 3));
// Draw
glDrawElements(GL_TRIANGLES, sizeof(squareIndices) / sizeof(squareIndices[0]), GL_UNSIGNED_BYTE, 0);
所以,唯一真正不同的是 glVertexAttribPointer 调用,它有一个指向数据的指针,现在有固定的数字。任何人都可以详细说明这一点吗?提前致谢。
【问题讨论】:
标签: exc-bad-access opengl-es-2.0 vbo