![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
PalettesEight-bit display modes require palettes. With windowed applications, Direct3D creates and installs a palette automatically. With full-screen applications, we must supply the palette.
Palettes are represented with the DirectDrawPalette interface and created with the DirectDraw CreatePalette() function. Modifying The RMWin ClassIn Chapter 4, we discussed the strategy behind the class design that was used to write the demos in this book. Our strategy was to create two MFC-derived classes that provide Direct3D support. We named these classes RMWin and RMApp. Each demo supplies two more classes, one derived from RMWin and the other derived from RMApp. These application-specific classes augment and modify the functionality of the base classes. Figure 10.1 displays the class inheritance tree with respect to this division of labor.
In moving to full-screen applications, we want to keep the architecture shown in the figure. This way, any new features that we add to the RMWin and RMApp classes will automatically be inherited by derived classes. This will make it much easier to use the added features in subsequent applications. Because full-screen applications are so different internally from windowed applications, the Direct3D classes (RMWin in particular) must be heavily modified. The RMWin ClassThe extent of the modifications becomes clear if you compare the RMWin class definition in Chapter 4 to the full-screen version in this chapter. The full-screen RMWin class definition appears in Listing 10.1. Listing 10.1 The RMWin class. class RMWin : public CFrameWnd { public: RMWin(); RMWin( int w, int h ); BOOL Create( const CString& sTitle, int icon, int menu); void SetColorModel( D3DCOLORMODEL cm ) { colormodel=cm; } virtual void Render() = 0; protected: int GetNumDisplayModes() { return totaldisplaymodes; } BOOL ActivateDisplayMode( int index ); int GetCurDisplayMode() { return curdisplaymode; } BOOL GetDisplayModeDims( int index, DWORD& w, DWORD& h, DWORD& d ); BOOL GetCurDisplayModeDims( DWORD& w, DWORD& h, DWORD& d ); static void CheckResult( HRESULT ); static void CheckDirectDrawResult( HRESULT ); virtual void OnIdle(LONG) { } static int GetMouseX() { return mousex; } static int GetMouseY() { return mousey; } D3DVALUE ScaleMesh( LPDIRECT3DRMMESHBUILDER, D3DVALUE ); void UsePalette( CString filename ) { palettefile=filename; } LPDIRECTDRAWSURFACE CreateSurface( DWORD w, DWORD h ); BOOL ClearSurface(LPDIRECTDRAWSURFACE surf, DWORD clr); void SaveSurface( LPDIRECTDRAWSURFACE surf, int number ); protected: //{{AFX_MSG(RMWin) afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct ); afx_msg void OnDestroy(); afx_msg void OnMouseMove( UINT state, CPoint point ); //}}AFX_MSG DECLARE_MESSAGE_MAP() private: BOOL InitMainSurfaces(); BOOL InitDisplayMode(); BOOL ActivateDisplayMode(DWORD,DWORD,DWORD); void Initvars(); virtual BOOL CreateScene() = 0; BOOL CreateDevice(); GUID* GetGUID(); BOOL InstallPalette(); static HRESULT WINAPI DisplayModeAvailable(LPDDSURFACEDESC, LPVOID); static int CompareModes( const void *arg1, const void *arg2 ); protected: LPDIRECTDRAW ddraw; LPDIRECTDRAWSURFACE primsurf; LPDIRECTDRAWSURFACE backsurf; LPDIRECTDRAWSURFACE zbufsurf; LPDIRECTDRAWPALETTE palette; static LPDIRECT3DRM d3drm; static LPDIRECT3DRMFRAME scene; static LPDIRECT3DRMFRAME camera; static LPDIRECT3DRMDEVICE device; static LPDIRECT3DRMVIEWPORT viewport; private: static DWORD modewidth, modeheight, modedepth; D3DCOLORMODEL colormodel; CRect winrect; LPDIRECTDRAWCLIPPER clipper; static int mousex; static int mousey; static UINT mousestate; static int totaldisplaymodes; static videomode displaymode[MAXDISPLAYMODES]; static int curdisplaymode; CString palettefile; }; Lets look first at how this class definition differs from the windowed version of the RMWin class. We can do this by looking at functions that were present in the windowed version but are not present here. After that, well look at functions that have been added to support the full-screen capability. Removing Obsolete FunctionsThe first difference is that the following four member functions that appeared in the windowed version do not appear here because they arent necessary for full-screen operation:
These four functions serve as message handlers in the windowed demos. The OnActivate() function is called by MFC when an application gets or loses focus. We used the OnActivate() function to notify Direct3D of the WM_ACTIVATE message using the Direct3DRMWinDevice HandleActivate() function. With full-screen applications, this notification isnt necessary. The same is true with the OnPaint() function. In the windowed demos, we used the OnPaint() function to call the Direct3DRMWinDevice HandlePaint() function. This allowed Direct3D to perform screen updates. Because we will be handling our own screen updates, the OnPaint() function isnt required. Although the OnActivate() and OnPaint() functions have been removed, the WM_ACTIVATE and WM_PAINT messages that they handle are still passed to our application. This is not true of the WM_SIZE message. The reason that the OnSize() function has been removed is because our application cannot be resized. It is a full-screen application and provides no means for resizing. Finally, the OnEraseBkgnd() function has been removed because its purpose was to erase the window background. Although our application does create a window, it isnt necessary to erase its contents. The window is present primarily to quiet the Windows GDI.
|
![]() |
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. |