OpenGL:  Color

Color Models

OpenGL supports two color models: RGBA and color index. The latter is used to implement a readable and writeable linear color map. It is more complex and less frequently used, so we will not discuss it here.

RGBA stands for Red, Green, Blue, and Alpha, and is used to specify varying degrees of color and opacity. All values vary between 0.0 and 1.0. An alpha value can be set globally or locally. Color values are set using the routine glColor3f(<red>,<blue>,<green>); in this case the global setting of alpha is used. The routine glColor4f(<red>,<blue>,<green><alpha>) may be used to specify alpha in-line.

                      Commonly Used RGB Colors

 

The color buffer should be cleared each time before drawing a scene using the command
 glClear(GL_COLOR_BUFFER_BIT).
 
Choosing Background Color and Clearing Screen

glClearColor(red,green,blue, alpha)

  • sets current clear color
  • example:   glClearColor(1.0,0.0,0.0,1.0);  /*sets to red*/

glClear(CL_COLOR_BUFFER_BIT)

  • clears window to color set previously by a call to glClearColor() or uses default of black.
 

Dithering is a coloring technique used to accommodate hardware with limited color resolution.

[2]

It is a bit hard to see in the gif above, so here is an illustration of the general idea of what is happening:

Moving from left to right, each grid contains a larger proportion of black than white, which - when viewed from afar - gives the impression of a gradual fade from white to black. Think of it like an Impressionist painting.
 
 
In-Class Exercise: 

Using Color

Show your work to your instructor.