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 FullScreenWin Class

The FullScreen demo provides its functionality with the FullScreenWin class. The FullScreenWin class uses RMWin as a base class, as shown in Listing 10.8.

Listing 10.8 The FullScreenWin class.

class FullScreenWin : public RMWin
{
public:
    FullScreenWin();
protected:
    //{{AFX_MSG(FullScreenWin)
    afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
private:
    void OnRenderWireframe();
    void OnRenderFlat();
    void OnRenderGouraud();

    BOOL CreateScene();
    void Render();
    static void UpdateAnimation(LPDIRECT3DRMFRAME, void*, D3DVALUE);

    BOOL CreateMenuSurface();
    BOOL UpdateMenuSurface();

    BOOL CreateFPSSurface();
    BOOL UpdateFPSSurface();
private:
    LPDIRECT3DRMMESHBUILDER meshbuilder;
    static LPDIRECT3DRMANIMATION animation;

    HFONT smallfont, largefont;

    LPDIRECTDRAWSURFACE menusurf;
    RECT menurect;
    int selectmode;

    LPDIRECTDRAWSURFACE fpssurf;
    RECT fpsrect;
    BOOL displayfps;
};

The class’s only public member function is a constructor. The constructor is responsible for initializing the class’s non-static data members.

One message handler is declared: OnKeyDown(). MFC calls this function whenever a key is pressed. We’ll use this function to implement the demo’s menu functionality.

Notice that the usual Render menu functions aren’t present in the MFC afx_msg section. Instead, they appear as regular member functions, as the first three private functions. This is because we aren’t using a traditional Windows menu. We will have to invoke these functions manually instead of relying on MFC to call them.

The CreateScene() function is declared next. As with the demos in previous chapters, the CreateScene() function is responsible for constructing the application’s visual constructs.

Next, the Render() function is declared. Remember that the RMWin version of Render() is declared as a pure virtual function. This requires us to provide a version in the FullScreenWin class. We’ll use this function to render and display the visual output that the demo produces.

A static callback function called UpdateAnimation() is declared. This function will be used to update the demo’s animation sequence.

The next four functions that the FullScreenWin class declares deserve some extra discussion:

BOOL CreateMenuSurface();
BOOL UpdateMenuSurface();

BOOL CreateFPSSurface();
BOOL UpdateFPSSurface();

When you run the FullScreen demo, a list of available display modes appears in the top-left corner, and, after a second or two, the demo’s frames-per-second (FPS) appears in the lower-right corner.

Each of these displays is accomplished with a surface, and both surfaces are created and maintained by the FullScreenWin class. The CreateMenuSurface() and UpdateMenuSurface() functions create and maintain the list (or menu) of display modes. The CreateFPSSurface() and UpdateFPSSurface() functions create and maintain the FPS readout.

The remainder of the class definition declares data members. Pointers to the Direct3DRMMeshBuilder and Direct3DRMAnimation interfaces are declared. Next, two HFONT instances are declared. The HFONT type is a handle to a Windows font. We’ll use these handles to draw the text that appears in the display mode menu and FPS readout.

Data members that are specifically used to implement the display mode menu are declared next:

LPDIRECTDRAWSURFACE menusurf;
RECT menurect;
int selectmode;

The menusurf pointer will be used to manipulate the surface that implements the display mode menu. The menurect structure is used to store the menu surface’s dimensions. The selectmode integer will be used to track the currently selected display mode. This should not be confused with the currently active display mode. Entries in the display mode menu can be highlighted with the arrow keys. The selected display mode does not, however, get activated until you press ENTER.

Data members specific to the FPS readout appear like this:

LPDIRECTDRAWSURFACE fpssurf;
RECT fpsrect;
BOOL displayfps;

The fpssurf pointer will be used to display and update the FPS display surface. The fpsrect structure is used to store the dimensions of the fpssurf surface. The displayfps boolean is used to delay the display of the FPS readout each time the display mode is changed. This is done because initial FPS calculations are typically erratic. Once the speed of the demo has stabilized, the FPS readout is displayed.

The FullScreenWin() Function

The FullScreenWin constructor is shown in Listing 10.9.

Listing 10.9 The FullScreenWin() function.

FullScreenWin::FullScreenWin()
{
    meshbuilder = 0;
    animation   = 0;
    menusurf    = 0;
    fpssurf     = 0;
    selectmode  = -1;
    displayfps  = FALSE;

    UsePalette( "palette.bmp" );

    largefont = CreateFont( 28, 0, 0, 0,
        FW_NORMAL, FALSE, FALSE, FALSE,
        ANSI_CHARSET,
        OUT_DEFAULT_PRECIS,
        CLIP_DEFAULT_PRECIS,
        DEFAULT_QUALITY,
        VARIABLE_PITCH,
        "Arial" );

    smallfont = CreateFont( 14, 0, 0, 0,
        FW_NORMAL, FALSE, FALSE, FALSE,
        ANSI_CHARSET,
        OUT_DEFAULT_PRECIS,
        CLIP_DEFAULT_PRECIS,
        DEFAULT_QUALITY,
        VARIABLE_PITCH,
        "Arial" );
}

First, the class’s data members are initialized. Next, the UsePalette() function is used to provide the name of a BMP file that contains a palette to be used with 8-bit display modes.

The two font handles, largefont and smallfont, are initialized with the Win32 CreateFont() function. The only difference between the two fonts is the size. The larger font will be used for the demo’s title banner (on the upper portion of the display mode menu). The small font will be used for both the display mode entries and the FPS readout.


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.