Chapter 4
Color

Chapter Objectives

After reading this chapter, you'll be able to do the following:

  • Decide between using RGBA or color-index mode for your application
  • Specify desired colors for drawing objects
  • Use smooth shading to draw a single polygon with more than one color

The goal of almost all OpenGL applications is to draw color pictures in a window on the screen. The window is a rectangular array of pixels, each of which contains and displays its own color. Thus, in a sense, the point of all the calculations performed by an OpenGL implementation - calculations that take into account OpenGL commands, state information, and values of parameters - is to determine the final color of every pixel that's to be drawn in the window. This chapter explains the commands for specifying colors and how OpenGL interprets them in the following major sections:

  • "Color Perception" discusses how the eye perceives color.
  • "Computer Color" describes the relationship between pixels on a computer monitor and their colors; it also defines the two display modes, RGBA and color index.
  • "RGBA versus Color-Index Mode" explains how the two display modes use graphics hardware and how to decide which mode to use.
  • "Specifying a Color and a Shading Model" describes the OpenGL commands you use to specify the desired color or shading mode