Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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);
glBindVertexArrayOES(*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));
glEnableVertexAttribArray(kVertexPositionAttributeLocation);

//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
glBindVertexArrayOES(0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}

And here's the rendering step:

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

glClear(GL_COLOR_BUFFER_BIT);

//use the shader program
glUseProgram(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);

glBindVertexArrayOES(vaoId);
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!

share|improve this question
    
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? –  Sean Middleditch Aug 18 '12 at 23:09
    
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. –  sak Aug 19 '12 at 0:15
add comment

1 Answer

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);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.