Course list http://www.c-jump.com/bcc/

Lab 3 Vertex Array Objects and Vertex Buffer Objects


  1. Introduction
  2. Getting started
  3. OpenGL client program
  4. Things to do
  5. More things to do
  6. How to submit

1. Introduction


  • Vertex shader

    
    #version 150
    
    in vec4 vPosition;
    in vec4 vColor;
    out vec4 passColor;
    
    void main () {
        gl_Position = vPosition;
        passColor = vColor;
    }
    
    
  • Fragment shader

    
    #version 150
    
    in vec4 passColor;
    out vec4 fColor;
    
    void main () {
        fColor = passColor;
    }
    
    

2. Getting started



3. OpenGL client program


  • App init

    • init GLUT and GLEW

    • Compile and link shaders

    • init and upload each model (sky, terrain, objects)

    • glutMainLoop

  • App render

    • glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)

    • render each model

    • glutSwapBuffers



  • Model init

    • glGenVertexArrays and get your vao

    • glGenBuffers and get your vbo

    • for vertices, normals, colors, and texture:

      • load data (e.g. from a file)

      • glGetAttribLocation ***

  • Model upload

    • glBindVertexArray( vao )

    • glBindBuffer( GL_ARRAY_BUFFER... )

    • glBufferData( GL_ARRAY_BUFFER... )

    • for vertices, normals, colors, and texture:

      • glBufferSubData( GL_ARRAY_BUFFER... )

      • glVertexAttribPointer

  • Model render

    • glBindVertexArray( vao )

    • glUseProgram( shader->program_ID )

    • for vertices, normals, colors, and texture:

      • glEnableVertexAttribArray ***

    • glDrawArrays( GL_TRIANGLES... )

    • for vertices, normals, colors, and texture:

      • glDisableVertexAttribArray ***

     

     

     

  • Note: functions marked *** use vertex attribute IDs in the vertex shader.



  • App shutdown

    • shutdown each model

  • Model Shutdown

    • for vertices, normals, colors, and texture:

      • glDisableVertexAttribArray ***

    • glDeleteBuffers( ...vbo )

    • glDeleteVertexArrays( ...vao )

    • delete any dynamically allocated memory


4. Things to do



5. More things to do



6. How to submit