![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
COLORREF and D3DCOLOR ConversionsWindows 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.
Experimental LearningThere 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 developers mistakes usually dont 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 (dont forget to use the RGB color model). When you are finished experimenting, itll be time to read Chapter 5, where youll learn about textures and texture mapping.
|
![]() |
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. |