State of OpenGL

  • OpenGL acts as one big state machine, and will remain in a state until changed. Example: glClearColor() can be used to set the clearing color but only a call to glClear() clears the color buffers; a call to glColor() can be used to specify the current drawing color, and any subsequent vertex will be drawn with the same color.

  • glEnable() can be used to used to enable specific rendering capabilities and will affect all the subsequent drawing commands

Vertex Arrays

  • Vertex arrays can be used to specify a lot of vertex-related data with small number of arrays and function calls.

  • There are three steps to using vertex arrays:

    • Enable the arrays: Use glEnableClientState(ArrayType) specifies the array to enable
    • Put data into the array: Use glXXXPointer() to specify the location of the data; data remains on the client side until dereferenced
    • Draw geometry with the data: glDrawElements() “dereferences” the last set pointer(s); contents are transferred to the server, and then rendered.

Textures

  • There are five steps to using Textures:
    • Create texture objects: Use glGenTextures(), and glBindTextures()
    • Specify texture data: Use glTexImageXD()
    • Specify parameters: Use glTexEnvf(), and glTexParameter*() to specify how the texture is to be applied to each pixel
    • Enable texture mapping: Use glEnable()
    • Draw the scene:

      Using immediate mode:

          glBegin(SHAPE)
             glTexCoord();  glVertex()
          glEnd()
      

      Using vertex arrays:

          glEnableClientState(VertexArray)
          glEnableClientState(TextureArray)
          glEnableClientState(ColorArray)
          glVertexPointer(); glTexCoordPointer(); glColorPointer()
          glDrawElements()
      

References