I'm migrating to OpenGL ES2 for one of my iOS projects, and I'm having trouble to get any geometry to render successfully. Here's where I'm setting up the VAO rendering:

void bindVAO(int vertexCount, struct Vertex* vertexData, GLushort* indexData, GLuint* vaoId, GLuint* indexId){

//generate the VAO & bind
glGenVertexArraysOES(1, vaoId);

GLuint positionBufferId;

//generate the VBO & bind
glGenBuffers(1, &positionBufferId);
glBindBuffer(GL_ARRAY_BUFFER, positionBufferId);

//populate the buffer data
glBufferData(GL_ARRAY_BUFFER, vertexCount, vertexData, GL_STATIC_DRAW);

//size of verte position
GLsizei posTypeSize = sizeof(kPositionVertexType);

glVertexAttribPointer(kVertexPositionAttributeLocation, kVertexSize, kPositionVertexTypeEnum, GL_FALSE, sizeof(struct Vertex),  (void*)offsetof(struct Vertex, position));

//create & bind index information
glGenBuffers(1, indexId);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *indexId);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertexCount, indexData, GL_STATIC_DRAW);

//restore default state
glBindBuffer(GL_ARRAY_BUFFER, 0);

And here's the rendering step:

//bind the frame buffer for drawing
glBindFramebuffer(GL_FRAMEBUFFER, outputFrameBuffer);


//use the shader program

glClearColor(0.4, 0.5, 0.6, 0.5);

float aspect = fabsf(320.0 / 480.0);
GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 0.1f, 100.0f);

GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -1.0f);

GLKMatrix4 mvpMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix);

//glUniformMatrix4fv(projectionMatrixUniformLocation, 1, GL_FALSE, projectionMatrix.m);
glUniformMatrix4fv(modelViewMatrixUniformLocation, 1, GL_FALSE, mvpMatrix.m);

glDrawElements(GL_TRIANGLE_FAN, kVertexCount, GL_FLOAT, &indexId);

//bind the color buffer
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderBuffer);
[context presentRenderbuffer:GL_RENDERBUFFER];

The screen is rendering the color passed to glClearColor correctly, but not the shape passed into bindVAO. Is my VAO being built correctly? Thanks!

  • \$\begingroup\$ To clarify: you're saying that the exact code you have is rendering the color passed in on the screen somewhere, it just doesn't look like what you'd expect? Like maybe the vertices are wrong, but the render is still partially working? And you've tried this without the VAO, to verify that the rest of your code and render logic is all correct? \$\endgroup\$ Aug 18, 2012 at 23:09
  • \$\begingroup\$ So what you see there in the second code block is the entirety of the rendering call. I'm fairly confident that at least the frame buffer and render buffer have been set up correctly and are rendering because the color expected from glClearColor(0.4, 0.5, 0.6, 0.5) is being rendered on screen. For now that's all the output I'm getting - a blue-green screen. Nothing from the VAO appears on screen. I'll try doing it without the VAO, thanks for the suggestion. I was hoping there might be something glaringly wrong with the VAO code someone could point me towards. \$\endgroup\$
    – sak
    Aug 19, 2012 at 0:15

1 Answer 1


So it turns out there were two issues. In this line:

glBufferData(GL_ARRAY_BUFFER, vertexCount, vertexData, GL_STATIC_DRAW);

I was using the vertex count instead of the size of the buffer in bytes. It should have been:

glBufferData(GL_ARRAY_BUFFER, vertexCount*sizeof(GLfloat), vertexData, GL_STATIC_DRAW);

Then in the rendering step, I was passing the vertex data type instead of the index data type into glDrawElements here:

glDrawElements(GL_TRIANGLE_FAN, kVertexCount, GL_FLOAT, &indexId);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .