我在与VBO的,我真的不明白这个问题。我的问题是通过意外更改glVertexAttribPointer方法调用中的最后一个参数来解决的。所以,我正在寻找一个答案,为什么这突然工作或者为什么我以前的代码不工作了。 (只是为了让OpenGL的更好的理解)glDrawElements EXC_BAD_ACCESS VBO的
结构:
typedef struct
{
float position[3];
float color[4];
} Vertex;
没有维也纳组织:
// 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));
随着维也纳组织(这给了我一个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
调用其中有一个数据指针现在已固定电话号码。任何人都可以详细说明这一点?提前致谢。
哇!这是一个快速的动物。非常感谢。克里斯塔尔明确;) – polyclick 2011-12-27 17:00:15