我在與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