Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Cutting Edge Direct 3D Programming
(Publisher: The Coriolis Group)
Author(s): Stan Trujillo
ISBN: 1576100502
Publication Date: 11/01/96

Bookmark It

Search this book:
 
Previous Table of Contents Next


COLORREF and D3DCOLOR Conversions

Windows uses the COLORREF type to express colors. Direct3D uses the D3DCOLOR type. The two types are not compatible, so the RMWin class provides conversion functions. The COLORREF_2_D3DCOLOR() function converts the Windows color type to the Direct3D color type. The D3DCOLOR_2_COLORREF() function performs the opposite conversion. The code for both functions appears as shown:

inline D3DCOLOR RMWin::COLORREF_2_D3DCOLOR(COLORREF cref)
{
    D3DVALUE r=D3DVALUE(GetRValue(cref))/D3DVALUE(255);
    D3DVALUE g=D3DVALUE(GetGValue(cref))/D3DVALUE(255);
    D3DVALUE b=D3DVALUE(GetBValue(cref))/D3DVALUE(255);
    return D3DRMCreateColorRGB( r, g, b );
}

inline COLORREF RMWin::D3DCOLOR_2_COLORREF(D3DCOLOR d3dclr)
{
    D3DVALUE red=D3DVALUE(255)*D3DRMColorGetRed(d3dclr);
    D3DVALUE green=D3DVALUE(255)*D3DRMColorGetGreen( d3dclr );
    D3DVALUE blue=D3DVALUE(255)*D3DRMColorGetBlue( d3dclr );
    return RGB((int)red,(int)green,(int)blue);
}

Both functions are declared inline in order to minimize the performance impact.


TIP:  Performance issues
In general, worrying about performance while using a package like Direct3D is like rearranging deck chairs on the Titanic. Ninety-nine percent of the work that a Direct3D program does is done by Direct3D. The application code is a very small part of the big picture and would have to be poorly written indeed before a performance hit could be detected.

Experimental Learning

There is no greater learning tool than experimentation. One of the great things about software development is that experimentation is easy and free. If we were architects or nuclear engineers, our mistakes could cause serious damage and the loss of millions of dollars. A software developer’s mistakes usually don’t cause anything more serious than a reboot.

Experiment with the code in the Sample example. Experiment with the demos on the CD-ROM. Try adding multiple meshes to a scene. Experiment with colored lighting (don’t forget to use the RGB color model).

When you are finished experimenting, it’ll be time to read Chapter 5, where you’ll learn about textures and texture mapping.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.