1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
#ifndef D3DFRAME_H
#define D3DFRAME_H
#include <ddraw.h>
#include <d3d.h>
//-----------------------------------------------------------------------------
// Name: CD3DFramework7
// Desc: The Direct3D sample framework class for DX7. Maintains the D3D
// surfaces and device used for 3D rendering.
//-----------------------------------------------------------------------------
class CD3DFramework7
{
// Internal variables for the framework class
HWND m_hWnd; // The window object
BOOL m_bIsFullscreen; // Fullscreen vs. windowed
BOOL m_bIsStereo; // Stereo view mode
DWORD m_dwRenderWidth; // Dimensions of the render target
DWORD m_dwRenderHeight;
RECT m_rcScreenRect; // Screen rect for window
LPDIRECTDRAW7 m_pDD; // The DirectDraw object
LPDIRECT3D7 m_pD3D; // The Direct3D object
LPDIRECT3DDEVICE7 m_pd3dDevice; // The D3D device
LPDIRECTDRAWSURFACE7 m_pddsFrontBuffer; // The primary surface
LPDIRECTDRAWSURFACE7 m_pddsBackBuffer; // The backbuffer surface
LPDIRECTDRAWSURFACE7 m_pddsBackBufferLeft; // For stereo modes
LPDIRECTDRAWSURFACE7 m_pddsZBuffer; // The zbuffer surface
DWORD m_dwDeviceMemType;
// Internal functions for the framework class
HRESULT CreateZBuffer( GUID* );
HRESULT CreateFullscreenBuffers( DDSURFACEDESC2* );
HRESULT CreateWindowedBuffers();
HRESULT CreateDirectDraw( GUID*, DWORD );
HRESULT CreateDirect3D( GUID* );
HRESULT CreateEnvironment( GUID*, GUID*, DDSURFACEDESC2*, DWORD );
public:
// Access functions for DirectX objects
LPDIRECTDRAW7 GetDirectDraw() { return m_pDD; }
LPDIRECT3D7 GetDirect3D() { return m_pD3D; }
LPDIRECT3DDEVICE7 GetD3DDevice() { return m_pd3dDevice; }
LPDIRECTDRAWSURFACE7 GetFrontBuffer() { return m_pddsFrontBuffer; }
LPDIRECTDRAWSURFACE7 GetBackBuffer() { return m_pddsBackBuffer; }
LPDIRECTDRAWSURFACE7 GetRenderSurface() { return m_pddsBackBuffer; }
LPDIRECTDRAWSURFACE7 GetRenderSurfaceLeft() { return m_pddsBackBufferLeft; }
// Functions to aid rendering
HRESULT RestoreSurfaces();
HRESULT ShowFrame();
HRESULT FlipToGDISurface( BOOL bDrawFrame = FALSE );
// Functions for managing screen and viewport bounds
BOOL IsFullscreen() { return m_bIsFullscreen; }
BOOL IsStereo() { return m_bIsStereo; }
VOID Move( INT x, INT y );
// Creates the Framework
HRESULT Initialize( HWND hWnd, GUID* pDriverGUID, GUID* pDeviceGUID,
DDSURFACEDESC2* pddsd, DWORD dwFlags );
HRESULT DestroyObjects();
CD3DFramework7();
~CD3DFramework7();
};
//-----------------------------------------------------------------------------
// Flags used for the Initialize() method of a CD3DFramework object
//-----------------------------------------------------------------------------
#define D3DFW_FULLSCREEN 0x00000001 // Use fullscreen mode
#define D3DFW_STEREO 0x00000002 // Use stereo-scopic viewing
#define D3DFW_ZBUFFER 0x00000004 // Create and use a zbuffer
#define D3DFW_NO_FPUSETUP 0x00000008 // Don't use default DDSCL_FPUSETUP flag
//-----------------------------------------------------------------------------
// Errors that the Initialize() and ChangeDriver() calls may return
//-----------------------------------------------------------------------------
#define D3DFWERR_INITIALIZATIONFAILED 0x82000000
#define D3DFWERR_NODIRECTDRAW 0x82000001
#define D3DFWERR_COULDNTSETCOOPLEVEL 0x82000002
#define D3DFWERR_NODIRECT3D 0x82000003
#define D3DFWERR_NO3DDEVICE 0x82000004
#define D3DFWERR_NOZBUFFER 0x82000005
#define D3DFWERR_INVALIDZBUFFERDEPTH 0x82000006
#define D3DFWERR_NOVIEWPORT 0x82000007
#define D3DFWERR_NOPRIMARY 0x82000008
#define D3DFWERR_NOCLIPPER 0x82000009
#define D3DFWERR_BADDISPLAYMODE 0x8200000a
#define D3DFWERR_NOBACKBUFFER 0x8200000b
#define D3DFWERR_NONZEROREFCOUNT 0x8200000c
#define D3DFWERR_NORENDERTARGET 0x8200000d
#define D3DFWERR_INVALIDMODE 0x8200000e
#define D3DFWERR_NOTINITIALIZED 0x8200000f
#endif // D3DFRAME_H
|