OpenGL

 

Description

OpenGL is intended to act as a software interface to graphics hardware. OpenGL only performs rendering (drawing), not event handling or window management. This is because it is intended to be independent of any particular windowing/event handling system, and different such systems perform windowing and event handling differently. In fact, OpenGL will run across networks, provided the client machine has the proper library to interpret OpenGL's rendering behaviour.

Figure. The relationship between OpenGL, GLU, GLX, and GLUT.
OpenGL API

OpenGL is a State Machine

OpenGL is a state machine: when you put it in a state, it remains in that state until you explicitly change it. This means, even though you set some state in a particular subroutine, that state does not change back automatically when the subroutine returns. For example, let's say the thread of control is currently in main() and the current drawing colour is yellow. main() calls mysub(), and mysub() sets the current drawing colour to black; mysub() returns without resetting the current colour. When the thread of control returns to main(), the current colour will be black, not yellow.


void mysub() {

  ...

  set_colour( BLACK );

  ...
}



void main() {

  ...

  set_colour( YELLOW );

  mysub();

  // Current colour is BLACK

  ...
}

OpenGL is Immediate

There is one other feature of OpenGL that is very important for you to understand. When you have some "object" like a cube in your program, you describe it to OpenGL in terms of primitives: lines, points, polygons, etc. OpenGL has no notion of these things being associated with each other.

Furthermore, you need to understand that OpenGL immediately (more or less) dumps out to its buffer as soon as you give it a command. Once a pixel is set in the buffer, OpenGL doesn't know anything about it except that it is a pixel at a certain place with a certain colour. It doesn't know if it is a point or part of a line or anything else about it. This means, if you draw your cube by issuing all the appropriate commands, and then tell OpenGL to do a rotation, everything which has already been drawn is unchanged. Your cube does not move. However, if you draw your cube, do a rotation, then draw your cube again with the same commands, you will see a second, rotated version of your first cube! This can be very handy.

OpenGL Utilities (GLU)

OpenGL provides functions which are very general. Often one encounters situations where this much freedom just gets in the way, and simplified interfaces are more useful. This is where GLU comes in. Strictly built on top of OpenGL, GLU provides some common functions in forms which are much simpler to call.

From Geometry to Pixels

OpenGL programs describe the objects to be drawn in terms of a 3D- (sometimes 2D-) modelling space, what it outputs is a 2D array of pixels. You may alter this transformation by changing matrices and viewports along the way.

Figure. A simple overview of the OpenGL rendering pipeline.
OpenGL Rendering Pipeline