![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The ActivateDisplayMode() FunctionThe RMWin class provides two versions of the ActivateDisplayMode() function. One is declared protected and is used by derived classes to signal RMWin to activate specific display modes. The second version is declared private and is used by the protected version to perform the actual display mode activation. The protected version of the ActivateDisplayMode() function looks like this: BOOL RMWin::ActivateDisplayMode( int index ) { DWORD w=displaymode[index].width; DWORD h=displaymode[index].height; DWORD d=displaymode[index].depth; curdisplaymode=index; return ActivateDisplayMode( w, h, d ); } The ActivateDisplayMode() function takes a single integer as an argument. The integer is an index into the list of supported display modes that was created by the InitDisplayMode() function. ActivateDisplayMode() uses the index integer to retrieve the display mode dimensions for the given entry in the displaymode array. The private curdisplaymode data member is updated, and the private version of ActivateDisplayMode() is called. The private version of ActivateDisplayMode() is defined as shown in Listing 10.7. Listing 10.7 The private version of ActivateDisplayMode(). BOOL RMWin::ActivateDisplayMode(DWORD w,DWORD h,DWORD d) { if (modewidth==w && modeheight==h && modedepth==d) return TRUE; modewidth=w; modeheight=h; modedepth=d; if (scene) { scene->Release(); scene=0; } if (device) { device->Release(); device=0; } if (primsurf) { primsurf->Release(); primsurf=0; } if (zbufsurf) { zbufsurf->Release(); zbufsurf=0; } ddraw->SetDisplayMode( modewidth, modeheight, modedepth ); InitMainSurfaces(); InstallPalette(); CreateDevice(); d3drm->CreateFrame( 0, &scene ); CreateScene(); return TRUE; } This version is more complicated than the previous version because it is responsible for destroying and rebuilding the internal application constructs. First, a check is made to see if the requested mode is not already in effect. If the requested display mode is no different from the current display mode, the function returns. If a new display mode is being requested, the modewidth, modeheight, and modedepth data members are updated. Next, the existing root frame, Direct3D device, primary surface, and Z-buffer are released. The back buffer is released along with the primary surface, so it should not be released explicitly. Then, the DirectDraw SetDisplayMode() function is used to activate the new display mode. The modewidth, modeheight, and modedepth data members are used as arguments. The next five function calls are identical to the portion of the OnCreate() function following the call to InitDisplayMode(): InitMainSurfaces(); InstallPalette(); CreateDevice(); d3drm->CreateFrame( 0, &scene ); CreateScene(); In the case of OnCreate(), the five calls initialize the application following the activation of the initial display mode. In this case, the calls reconfigure the application following a change in display mode. The GetNumDisplayModes() FunctionThe GetNumDisplayModes() is a protected function that returns the number of display modes detected by the InitDisplayMode() function. The function is declared and defined in the RMWin class definition: int GetNumDisplayModes() { return totaldisplaymodes; } The GetCurDisplayMode() FunctionThe GetCurDisplayMode() returns the index of the currently activated mode: int GetCurDisplayMode() { return curdisplaymode; } As with the GetNumDisplayModes() function, the simplicity of the GetCurDisplayMode() function makes it a good candidate for in-class (inline) declaration. The GetDisplayModeDims() FunctionThe GetDisplayModeDims() function returns the dimensions of a specific display mode: BOOL RMWin::GetDisplayModeDims( int index, DWORD& w, DWORD& h, DWORD& d ) { if (index<0 || index>=totaldisplaymodes) return FALSE; w=displaymode[index].width; h=displaymode[index].height; d=displaymode[index].depth; return TRUE; } The first GetDisplayModeDims() parameter is the index of the display mode in question. The index is used to retrieve the display modes dimensions from the displaymode array. Later in this chapter, well use this function to retrieve the dimensions of each supported display mode. The dimensions will be used to construct a menu of display modes. The GetCurDisplayModeDims() FunctionThe GetCurDisplayModeDims() function is defined as follows: BOOL RMWin::GetCurDisplayModeDims( DWORD& w, DWORD& h, DWORD& d ) { if (curdisplaymode<0 || curdisplaymode>=totaldisplaymodes) return FALSE; w=displaymode[curdisplaymode].width; h=displaymode[curdisplaymode].height; d=displaymode[curdisplaymode].depth; return TRUE; } The function is almost identical to GetDisplayModeDims() except that this function retrieves the dimensions of the current display mode and not an arbitrary mode. This is a convenience function. The same data can be retrieved by using the GetDisplayModeDims() function in conjunction with the GetCurDisplayMode() function.
|
![]() |
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. |