我有一组顶点和索引
static const GLfloat cubeVertices[192] = {
// right 0
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
.....
};
unsigned int cubeIndices[36] = {
// right
0, 1, 2, 2, 3, 0,
....
};
此处的完整数据:http://stevezissouprogramming.blogspot.com/2012/03/basic-cube-part-3-drawing.html
// Create the Vertex Buffer
glGenBuffers(1, &_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(cubeVertices), cubeVertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// Create the Indices Buffer
glGenBuffers(1, &_indicesBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indicesBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cubeIndices), cubeIndices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// tell openGL how to interpret the buffers
GLsizei stride = sizeof(GLfloat) * 8; // 8 components per row = 4 * 8 = 32
glEnableVertexAttribArray(GLKVertexAttribPosition);
glEnableVertexAttribArray(GLKVertexAttribNormal);
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(0));
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(stride*3/8));
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(stride*6/8));
然后在我的绘画方法中我有
glDrawElements(GL_TRIANGLES, 24, GL_UNSIGNED_INT, NULL);
我首先使用顶点数组和glDrawArray创建了这个例子,这个例子使用了纹理和所有东西(虽然看起来很奇怪)因为我应该使用indices数组。
当我切换到glDrawElements时,应用程序崩溃了glDrawElements。调试此类问题的正确方法是什么?