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


The CreateSurface() Function

Speaking of convenience functions, the CreateSurface() function is also a convenience function. The CreateSurface() function constructs an off-screen DirectDraw surface given the surface’s desired width and height. The function looks like this:

LPDIRECTDRAWSURFACE RMWin::CreateSurface( DWORD w, DWORD h )
{
    DDSURFACEDESC desc;
    memset( &desc, 0, sizeof(desc) );
    desc.dwSize = sizeof(desc);
    desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
    desc.dwWidth = w;
    desc.dwHeight = h;
    desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;

    LPDIRECTDRAWSURFACE surf;
    HRESULT r=ddraw->CreateSurface( &desc, &surf, 0 );
    if (r!=DD_OK)
        return 0;

    return surf;
}

A local DDSURFACEDESC structure is used to describe an off-screen surface with dimensions equal to those provided as parameters. The DirectDraw CreateSurface() function is used to create the surface. If the CreateSurface() function succeeds, a pointer to the new surface is returned.

The CreateSurface() function is designed to be used by classes derived from the RMWin class, but is not used by RMWin itself. We’ll use this function in the FullScreen demo.

The ClearSurface() Function

Like the CreateSurface() function, the ClearSurface() function is provided in order to make classes derived from RMWin easier to write. The ClearSurface() function assigns a specified value to each element in a surface. The function is defined like this:

bool RMWin::ClearSurface(LPDIRECTDRAWSURFACE surf, DWORD clr)
{
    DDBLTFX bltfx;
    memset( &bltfx, 0, sizeof(bltfx) );
    bltfx.dwSize = sizeof(bltfx);
    bltfx.dwFillColor = clr;
    surf->Blt( 0, 0, 0, DDBLT_COLORFILL | DDBLT_WAIT, &bltfx );
    return TRUE;
}

The function takes two arguments: a pointer to the surface to be cleared and the value to be used to clear the surface.

The DirectDrawSurface Blt() function is used to erase the contents of the surface. Typically, the Blt() function is used to copy surfaces or portions of surfaces to other surfaces. However, the Blt() function can perform special operations such as mirroring, rotating, and Z-buffer operations. In this case, we are using the DDBLTFX structure and the DDBLT_COLORFILL constant to indicate to the Blt() function that we want a color fill operation to be applied to the given surface.

The Render() Function

The Render() function is the last (and the simplest) RMWin function that we’ll study. The Render() function is declared, but not defined:

virtual void Render() = 0;

Render is a pure virtual function. This means that Render() must be overridden by classes derived from RMWin. Our reasons for declaring the Render() function this way is to ensure that classes derived from RMWin handle the application’s screen updates. Among other things, the Render() function should perform page flipping.

The FullScreen Demo

For the remainder of this chapter, we will be studying the FullScreen demo. The FullScreen demo is a full-screen Direct3D application. The FullScreen demo uses the full-screen version of the RMWin class to allow display-mode switching and page flipping. The demo appears in Figure 10.2.


Figure 10.2  The FullScreen Demo.

The FullScreen demo animates the familiar swirl mesh across the screen using the Direct3DRMAnimation interface. Of more interest, however, is the fact that the demo displays all of the detected display modes and allows each to be activated. The arrow keys can be used to select any of the display modes, and the ENTER key activates the selected mode.

When you run the FullScreen demo, any display modes that your video card supports will appear. The display modes shown in Figure 10.2 are display modes detected on an ATI Mach 64 video card.


TIP:  Monitor—your limitations
Both your monitor and your video card must support a display mode if the display mode is to work properly. The FullScreen demo displays display modes supported by your video card. The modes may or may not be supported by your monitor. If you select a mode and your screen turns blank for longer than 10 seconds, you can press ESCAPE to exit the demo and return to the Windows desktop.

The demo also displays the program’s current display speed, or frames-per-second (FPS).

The FullScreen demo demonstrates the following techniques:

  Creating full-screen Direct3D applications
  Page flipping
  Integrating 2D surfaces into 3D scenes
  Using Win32 functions to draw text on DirectDraw surfaces
  Calculating a program’s frames-per-second (FPS)
  Alternatives to traditional Windows menus


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.