Game Development Reference
In-Depth Information
Chapter 4
Color
In the last chapter we rendered the objects in the scene using lines to
form wireframe meshes. In this chapter we learn how to render solid
objects with color.
Objectives
To learn how color is described in Direct3D
To understand how colors are shaded across a triangle
4.1 Color Representation
In Direct3D, colors are described with an RGB triplet. That is, we spec-
ify the amount of red, green, and blue color. The additive mixing of
these three components determines the final color. By using a combina-
tion of red, green, and blue, we can represent millions of colors.
We use two different types of structures to hold the RGB data. The
first is the D3DCOLOR type, which is actually typedef ed as a DWORD
and is 32 bits. The bits in the D3DCOLOR type are divided into four 8-bit
sections, where each section stores the intensity of a color component.
Figure 4.1 shows the distribution.
Figure 4.1: A 32-bit color, where a byte is
allocated for each primary color component
red, green, and blue. A fourth byte is allo-
cated for the alpha component.
Since each color component gets a byte of memory, the intensity of the
color can range from 0-255. Values near 0 specify a low intensity, and
values near 255 specify a strong intensity.
91
 
Search WWH ::




Custom Search