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


Adding Display Mode Support

The full-screen version of RMWin provides several functions that facilitate display mode detection and switching. These functions are:

  GetNumDisplayModes()
  ActivateDisplayMode()
  GetCurDisplayMode()
  GetDisplayModeDims()
  GetCurDisplayModeDims()

Internally, the RMWin class assembles a list of supported display modes. The number of entries in the list can be determined with the GetNumDisplayModes() function. Specific display modes can be activated with the ActivateDisplayMode() function. The GetCurDisplayMode() function returns the currently active display mode. The GetDisplayModeDims() and GetCurDisplayModeDims() functions return the dimensions (width, height, and depth) of the display modes.

Surface Support Functions

The RMWin class creates and manages the DirectDraw surfaces that are necessary for Direct3D full-screen operations. It is, as you will see later in this chapter, sometimes useful to create and display extra surfaces. Two surface-related functions have been added to the RMWin class: CreateSurface() and ClearSurface(). The CreateSurface() function creates a new surface given the surface’s dimensions. The ClearSurface() function clears the contents of an existing surface.

Palette Support

Full-screen applications running in 8-bit modes require that a palette be constructed and attached to each surface. Palettes can be supplied to the RMWin class in the form of a BMP file. The UsePalette() function is provided for this purpose.

Internally, the RMWin class uses the InstallPalette() function to extract the palette data from the BMP file and create a DirectDraw palette. The new palette is then attached to the surfaces.

The OnCreate() Function

The OnCreate() function is called by MFC to allow window initialization. In the windowed version of RMWin, we used OnCreate() only to initialize the Direct3DRM interface. In the full-screen version, the OnCreate() function initializes Direct3D, DirectDraw, the DirectDraw surfaces, and the Direct3D device. The function also constructs any application-specific elements. The OnCreate() function is shown in Listing 10.2.

Listing 10.2 The OnCreate() function.

int RMWin::OnCreate(LPCREATESTRUCT)
{
    ShowCursor( FALSE );
    Direct3DRMCreate( &d3drm );
    DirectDrawCreate( 0, &ddraw, 0 );
    ddraw->SetCooperativeLevel( GetSafeHwnd(),
                DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX );
    InitDisplayMode();
    InitMainSurfaces();
    InstallPalette();
    CreateDevice();
    d3drm->CreateFrame( 0, &scene );
    CreateScene();
    return 0;
}

First, the Win32 ShowCursor() function is used to hide the mouse cursor. The mouse can be used in full-screen mode, but not as reliably as in windowed mode. Some display modes (Mode X display modes in particular) garble the mouse cursor.

Next, the Direct3DRMCreate() function is used to initialize Direct3D, and the DirectDrawCreate() function is used to initialize DirectDraw. Once DirectDraw has been initialized, the SetCooperativeLevel() function is used to specify that we will be running in full-screen, exclusive mode. The DDSCL_ALLOWMODEX constant is included to allow use of any supported Mode X display modes.

Next, the InitDisplayMode() function is called. This function creates a list of supported display modes and selects an initial mode.

The InitMainSurfaces() function creates the primary and back surfaces along with the Z-buffer. These three surfaces (the Z-buffer is a special type of surface) always have the same width and height. These dimensions are determined by the current display mode, so it is important that the intended display mode be active when these surfaces are created.

The InstallPalette() function is then used to create and attach a palette to the primary and back surfaces. The InstallPalette() function extracts a palette from a BMP file. The name of the BMP file must first be supplied with the UsePalette() function.

Next, the CreateDevice() function is called to create and configure the Direct3D device.

Finally, a root frame is created (using the scene pointer), and CreateScene() is called. You’ll recognize the CreateScene() function as the focus of our studies in previous chapters.


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.