![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The Direct3DRMFrame Move() function updates the frame hierarchys internal values and executes any frame movement callbacks used by the hierarchy. The Direct3DRMViewport function calls (Clear() and Render()) clear the viewport contents (this has no effect on our surface) and calculate the new visual output. The Direct3DRMDevice Update() function copies the calculated output to the backsurf surface. This may not seem intuitive because the backsurf surface does not appear in the code snippet. But remember that the backsurf surface was used to create the Direct3D device. This association causes the Update() function to render output directly to the backsurf surface. The FPS surface is now displayed over, or on top of, the Direct3D output: UpdateFPSSurface(); if (displayfps) { DWORD w, h, d; GetCurDisplayModeDims( w, h, d ); backsurf->BltFast( w-fpsrect.right, h-fpsrect.bottom, fpssurf, &fpsrect, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT ); } The UpdateFPSSurface() is invoked to update the fpssurf surface. Then, if the displayfps boolean is set to TRUE, the contents of the surface are copied to the backsurf surface via the BltFast() function (the BltFast() function is an optimized version of the Blt() function). The fpssurf surface is to appear in the lower-right corner of the screen, so the display mode dimensions are used in calculating the surfaces destination on the back surface. The display mode menu surface is then copied to the backsurf surface: backsurf->BltFast( 0, 0, menusurf, &menurect, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT ); This code is simple because the display mode menu surface is always visible and appears in the upper-left corner of the screen. Finally, the contents of the backsurf surface are moved to the primary surface with a page flip operation: primsurf->Flip( 0, DDFLIP_WAIT ); It is this function call that makes the contents of the backsurf surface visible. The KeyDown() FunctionWe need to talk about one more function before we can fully understand the FullScreen demo. The KeyDown() function is the message handler that gets called whenever a key is pressed. Listing 10.15 displays the KeyDown() function. Listing 10.15 The KeyDown() function. void FullScreenWin::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { static int screencapture; int newindex; int nmodes=GetNumDisplayModes(); if (nmodes>maxmodes) nmodes=maxmodes; int rows=nmodes/menucols; if (nmodes%menucols) rows++; switch (nChar) { case VK_ESCAPE: PostMessage( WM_CLOSE ); break; case VK_UP: newindex=selectmode-1; if (newindex>=0) { selectmode=newindex; UpdateMenuSurface(); } break; case VK_DOWN: newindex=selectmode+1; if (newindex<nmodes) { selectmode=newindex; UpdateMenuSurface(); } break; case VK_LEFT: newindex=selectmode-rows; if (newindex>=0) { selectmode=newindex; UpdateMenuSurface(); } break; case VK_RIGHT: newindex=selectmode+rows; if (newindex<nmodes) { selectmode=newindex; UpdateMenuSurface(); } break; case VK_RETURN: if (menusurf) { menusurf->Release(); menusurf=0; } if (fpssurf) { fpssurf->Release(); fpssurf=0; } ActivateDisplayMode( selectmode ); displayfps=FALSE; CreateMenuSurface(); UpdateMenuSurface(); CreateFPSSurface(); break; case 'W': OnRenderWireframe(); break; case 'F': OnRenderFlat(); break; case 'G': OnRenderGouraud(); break; } RMWin::OnKeyDown( nChar, nRepCnt, nFlags ); } In essence, the KeyDown() function uses the arrow keys to highlight new display modes on the display mode menu. The ENTER key is used to activate selected display modes. The W, F, and G keys are used to change the rendering quality of the demos only mesh (wireframe, flat, and Gouraud). The ESCAPE key is used to terminate the demo. ConclusionWell, thats itthis is the last chapter in this book. I hope you learned what you wanted to know and maybe a little bit more. Good luck!
|
![]() |
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. |