Correct use of VAO's in OpenGL ES2 for iOS?
        Posted  
        
            by 
                sak
            
        on Game Development
        
        See other posts from Game Development
        
            or by sak
        
        
        
        Published on 2012-08-18T18:36:49Z
        Indexed on 
            2012/09/18
            15:55 UTC
        
        
        Read the original article
        Hit count: 382
        
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!
© Game Development or respective owner