up to Schedule & Notes

OpenGL Introduction

GL = graphics library

OpenGL started in 1992 to replace proprietary SGI "IRIS GL".

Sub-libraries:
GLUGL UtilitiesBasic objects, textures, some transformations
GLUTGL Utility ToolkitSet up windows and handle events. No longer used.
GLEWGL Extension WranglerMaps OpenGL API functions to internal implementation
GLFWGraphics Library FrameworkWindows and events. Good.
GLADMaps API functions to implementations. Good.
GLMGL mathLots of graphics-oriented math functions. Somewhat messy.

Main graphics loop:

Events

Events can be:

Each event is processed by a 'handler', which is just a function.

Each event handler is registered during initialization with (in our case) GLFW.

Double Buffering

OpenGL usually has two drawing buffers:

One shows what's on the screen (the "front buffer").

The other is used to draw the next image (the "back buffer").

Once drawing in the back buffer is finished, the buffers are swapped so that the new image appears on the screen all at once, rather than bit-by-bit as it was being drawn.

See 00-intro/src/demo1.cpp in openGL.zip

Drawing in OpenGL

Object vertices are stored in a "vertex buffer object" or VBO.

Each vertex can have many attributes, such as

The VBO is just a buffer and could be set out like this:

In OpenGL, you must:

  1. Fill the VBO.
  2. Tell OpenGL about the VBO format, including vertex attributes.

See 00-intro/src/demo2.cpp in openGL.zip

Animating in OpenGL

Maintain a "world state" that contains all the information necessary to provide a snapshot of the world at a particular instant.

For example, if the world consists of a rotating square, the world state would contain the square's:

To animate, update the state as a function of either (a) the relative time since the last update or (b) the absolute current time.

See 00-intro/src/demo3.cpp in openGL.zip

up to Schedule & Notes