Game Development Reference
In-Depth Information
Figure 3-22. Having fun with mixing the primary colors red, green, and blue
We can, of course, generate a lot more colors than the ones shown in Figure 3-22 by varying the
intensity of the red, green, and blue components. Each component can have an intensity value
between 0 and some maximum value (say, 1). If we interpret each color component as a value on
one of the three axes of a three-dimensional Euclidian space, we can plot a so-called color cube ,
as depicted in Figure 3-23 . There are a lot more colors available to us if we vary the intensity of
each component. A color is given as a triplet (red, green, blue) where each component is in the
range between 0.0 and 1.0 (0.0 means no intensity for that color, and 1.0 means full intensity).
The color black is at the origin (0,0,0), and the color white is at (1,1,1).
Figure 3-23. The mighty RGB color cube
Encoding Colors Digitally
How can we encode an RGB color triplet in computer memory? First, we have to define what
data type we want to use for the color components. We could use floating-point numbers and
specify the valid range as being between 0.0 and 1.0. This would give us quite some resolution
for each component and would make a lot of different colors available to us. Sadly, this
approach uses up a lot of space (3 times 4 or 8 bytes per pixel, depending on whether we use
32-bit or 64-bit floats).
 
Search WWH ::




Custom Search