Color and Shading Lecture 9 Mon, Sep 26, 2005
The RGB Color System The three primary light colors are red, green, and blue. By mixing these three colors in various proportions, all colors can be made. red + green = yellow red + yellow = orange dark orange = brown etc. + = + =
The Color Monitor Each pixel of the color monitor is square consisting of three vertical bands: a red, a green, and a blue band. The color we perceive depends on how bright each band is. Each band can be set to a level from 0 to 255. 0 = darkest level 255 = brightest level
The Color Monitor Red Yellow Black Green Magenta White Blue Cyan
The Color Monitor Red Yellow Black Green Magenta White Blue Cyan
Mixing Colors Read Run
Gray Levels If we mix the colors together in equal amounts, we get a level of gray. (0.0, 0.0, 0.0) = black (0.2, 0.2, 0.2) = dark gray (0.5, 0.5, 0.5) = medium gray (0.8, 0.8, 0.8) = light gray (1.0, 1.0, 1.0) = white
Gray Levels The following graphic shows 16 levels of gray.
Gray Levels The following graphic uses hundreds of levels of gray.
Setting the Color The function glColor*() will set the brightness levels of the red, green, and blue bands of the pixel. glColor3i(int red, int green, int blue) red, green, and blue are ints from 0 to 255. glColor3f(float red, float green, float blue) red, green, and blue are floats from 0.0 to 1.0. glColor3fv(float color[ ]) color is an array of three floats (red, green, blue).
Setting the Color Read Run
Varying the Color Levels Read Run
The Full Range of Colors Read Run
Shading Shading refers to adding color to an object. In OpenGL, we specify the colors only of the vertices of the polygon. OpenGL uses linear interpolation to determine the colors of the pixels within the polygon.
Shading For triangles, the interpolated are determined uniquely by the colors of the three vertices. For larger polygons, OpenGL will triangulate the polygon, then shade each triangle. If the effect is undesirable, then the programmer must do his own triangulation.
Shading Larger Polygons Read Run
Shading Model OpenGL provides two shading models Smooth shading (interpolation) Flat shading (no interpolation) Flat shading shades the interior with the color of one arbitrarily selected vertex. Almost always, the smooth shading model produces better results.
Flat Shading of a Polygon Read Run