glDrawElements not working on iPhone but glDrawArrays works

2.1k views Asked by At

I have tried to convert my OpenGL application to OpenGL ES. I am drawing elements on Mac this way:

glUseProgram(m_program);

// Update uniform value.
glUniform4f(uniforms[UNIFORM_COLOR], (GLfloat)color[0], (GLfloat)color[1], (GLfloat)color[2], (GLfloat)color[3]);


// Update attribute values.
glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, data);
glEnableVertexAttribArray(ATTRIB_VERTEX);

// Validate program before drawing. This is a good check, but only really necessary in a debug build.
// DEBUG macro must be defined in your debug configurations if that's not already the case.

glDrawElements(GL_TRIANGLE_STRIP, count, GL_UNSIGNED_INT, indices);

Everything is OK but when I try to draw this way on iPhone 4 (iOS 4.2 and XCode 3.2.5) I can see nothing. Strange thing is all computations is done and when I try to draw it with glDrawArrays, something is shown on screen (but vertexes are not rendered in right order):

glUseProgram(m_program);

// Update uniform value.
glUniform4f(uniforms[UNIFORM_COLOR], (GLfloat)color[0], (GLfloat)color[1], (GLfloat)color[2], (GLfloat)color[3]);


// Update attribute values.
glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, data);
glEnableVertexAttribArray(ATTRIB_VERTEX);

glDrawArrays(GL_TRIANGLE_STRIP, 0, count);

Am I missing anything?

2

There are 2 answers

0
Martin Pilch On BEST ANSWER

GL_UNSIGNED_INT as type of glDrawElements indices array is not allowed on iPhone. I have to use GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT

1
Martin Pilch On

On the Apple Developers forum I have go hint that GL_UNSGNED_INT can be used on iPhone using OES_element_index_uint ectension