Ways to debug glDrawElements in OpenGL ES

392 views Asked by At

I have a set of vertices and indices

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,
    ....
};

Full Data Here: 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));

and then in my draw method I have

glDrawElements(GL_TRIANGLES, 24, GL_UNSIGNED_INT, NULL);

I first created the example using only the vertices array and glDrawArray and the example worked with textures and everything (although it looked odd) because I was supposed to use the indices array.

When I switched to glDrawElements, the app crashed on glDrawElements. What is the proper way to debug such a problem?

0

There are 0 answers