Graphics library developed by Silicon Graphics, an API that provides a large set of functions to manipulate graphics and images
OpenGL
Platform independent, but not windows-system independent
Provides the core library
glut
GL Utilities Toolkit, contains extra routines for drawing 3D objects and other primitives
Enables writing windows-system independent code
glu
OpenGL Utilities, contains extra routines for projections and rendering complex 3D objects
glui
Contains extra routines for creating user-interfaces
Function naming convention
Prefix is gl, glu, or glut depending on the library
Main part indicates the purpose of the function
Suffix indicates the number and type of arguments
Symbolic constants
Predefined identifiers defined using #define, always written in capital letters
Getting started with OpenGL
1. Include gl.h for core OpenGL
2. Include glu.h for glu library
3. Include glui.h for glui library
4. Include glut.h for glut library
Writing OpenGL code
1. Perform GLUT initialization with glutInit
2. Set initial window position with glutInitWindowPosition
3. Set initial window size with glutInitWindowSize
4. Set display mode options with glutInitDisplayMode
5. Create display window with glutCreateWindow
Event-driven
OpenGL executes code in response to events, defined by programmer-defined callback functions
Display event
Most important event, occurs whenever OpenGL needs to redraw the display window
Structure of OpenGL programs
1. Perform initialization tasks
2. Define callback functions and associate them with events
3. Start the event loop
OpenGL programs consist of a number of parts: initialization, defining callback functions, and starting the event loop
Coordinate system
System that uses one or more numbers, or coordinates, to uniquely determine the position of points or other geometric elements
Number line
Simplest example of a coordinate system, identifies points on a line with real numbers
Cartesian coordinate system
Prototypical example, uses perpendicular lines in 2D or mutually orthogonal planes in 3D to define coordinates
Synthetic camera
Programmer's reference model for specifying 3D view projection parameters, including position, orientation, field of view, depth of field, and projection type
View volume
Contains everything visible from the camera's point of view, can be approximated by a rectangular cone (frustum) for efficient clipping
Primitive attribute
Parameter that affects the way a primitive is displayed, OpenGL maintains a list of current state variables representing these attributes
Color representation
RGB: color defined by red, green, and blue components
RGBA: color defined by red, green, blue, and alpha (transparency) components
Frame buffer
Used by raster graphics systems to store the image ready for display, can use direct storage or color look-up table
Direct storage
Color values of each pixel are stored directly in the frame buffer
Color look-up table
Stores an index for each pixel, the actual colors are stored in a separate look-up table
OpenGL uses direct storage by default, but the programmer can choose to use a color look-up table
Setting OpenGL color attributes
Use glColor*() to set the drawing color
Use glClearColor() to set the background color
Drawing color can be set using RGB or RGBA representation
Background color is always set using RGBA representation
Defining the frame buffer for color drawing
Use glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) for RGB color
Use glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA) to store alpha values
Down the rasterization process, an extra look-up operation is required
Color look-up tables were commonly used in the early days of computer graphics when memory was expensive, but these days memory is cheaper, so most systems use direct storage
OpenGL uses direct storage by default, but the programmer can choose to use a color look-up table if they wish
glColor*
Function to change the current drawing colour
glClearColor
Function to change the current background colour
The background colour is always set using an RGBA colour representation
The drawing colour can be set using either RGB or RGBA representations
Setting drawing and background colours
glColor3f(1.0,0.0,0.0);
glColor4f(0.0,1.0,0.0,0.05);
glClearColor(1.0,1.0,1.0,1.0);
Defining a frame buffer before drawing in OpenGL
1. Specify a color frame buffer
2. To store alpha values in the frame buffer, use GLUT_RGBA
3. To use a color look-up table, use GLUT_INDEX
Point primitives
The only attributes we can modify are the color and size
Changing point size
Use glPointSize(size)
Changing point color
Use glColor3f(colorCode)
Line primitives
Attributes that can be modified: line color, line width, line style (solid/dashed etc.)