![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The CreateSurface() FunctionSpeaking of convenience functions, the CreateSurface() function is also a convenience function. The CreateSurface() function constructs an off-screen DirectDraw surface given the surfaces 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. Well use this function in the FullScreen demo. The ClearSurface() FunctionLike 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() FunctionThe Render() function is the last (and the simplest) RMWin function that well 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 applications screen updates. Among other things, the Render() function should perform page flipping. The FullScreen DemoFor 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.
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.
The demo also displays the programs current display speed, or frames-per-second (FPS). The FullScreen demo demonstrates the following techniques:
|
![]() |
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. |