Game Development Reference
In-Depth Information
Note: Do not worry about the alpha component now; it is used for
alpha blending—the topic of Chapter 7.
Specifying each component and then inserting it into the proper posi-
tion in the D3DCOLOR type will require some bit operations. Direct3D
provides a macro that performs this for us called D3DCOLOR_ARGB .
There is one parameter for each color component and the alpha compo-
nent. Each parameter must be in the range 0-255 and is used like so:
D3DCOLOR brightRed = D3DCOLOR_ARGB(255, 255, 0, 0);
D3DCOLOR someColor = D3DCOLOR_ARGB(255, 144, 87, 201);
Alternatively, we can use the D3DCOLOR_XRGB macro, which is similar
but does not take the alpha parameter; rather, it sets the alpha to 0xff
(255).
#define D3DCOLOR_XRGB(r,g,b) D3DCOLOR_ARGB(0xff,r,g,b)
Another way to store a color in Direct3D is with the D3DCOLORVALUE
structure. With this structure we use a floating-point value to measure
the intensity of each component. The range measures from 0 to 1—0
being no intensity and 1 being full intensity.
typedef struct _D3DCOLORVALUE {
float r; // the red component, range 0.0-1.0
float g; // the green component, range 0.0-1.0
float b; // the blue component, range 0.0-1.0
float a; // the alpha component, range 0.0-1.0
} D3DCOLORVALUE;
Alternatively, we can use the D3DXCOLOR structure, which contains the
same data members as D3DCOLORVALUE but provides useful construc-
tors and overloaded operators, making color manipulations easy. In
addition, since they can contain the same data members, we can cast
back and fourth between the two. D3DXCOLOR is defined as:
typedef struct D3DXCOLOR
{
#ifdef __cplusplus
public:
D3DXCOLOR() {}
D3DXCOLOR( DWORD argb );
D3DXCOLOR( CONST FLOAT * );
D3DXCOLOR( CONST D3DXFLOAT16 * );
D3DXCOLOR( CONST D3DCOLORVALUE& );
D3DXCOLOR( FLOAT r, FLOAT g, FLOAT b, FLOAT a );
// casting
operator DWORD () const;
operator FLOAT* ();
operator CONST FLOAT* () const;
Search WWH ::




Custom Search