1
#include
<
d3dx9.h
>
2
#include
<
d3d9.h
>
3
4
5
6
#pragma comment(lib,
"
d3dx9.lib
"
)
7
#pragma comment(lib,
"
d3d9.lib
"
)
8
9
10
#define
MAX_LOADSTRING 100
11
12
13
HINSTANCE hInst;
14
TCHAR szTitle[MAX_LOADSTRING]
=
TEXT(
"
D3D
"
);
15
TCHAR szWindowClass[MAX_LOADSTRING]
=
TEXT(
"
HelloD3D
"
);
16
17
18
19
ATOM MyRegisterClass(HINSTANCE hInstance);
20
BOOL InitInstance(HINSTANCE,
int
);
21
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
22
23
24
25
HWND g_hWnd
=
NULL;
26
27
IDirect3D9
*
pD3D
=
NULL;
28
IDirect3DDevice9
*
pDevice
=
NULL;
29
30
31
bool
InitD3D();
32
void
Release();
33
void
Render();
34
35
36
37
int
APIENTRY WinMain(HINSTANCE hInstance,
38
HINSTANCE hPrevInstance,
39
LPSTR lpCmdLine,
40
int
nCmdShow)
41
{
42
MSG msg;
43
44
MyRegisterClass(hInstance);
45
46
if ( ! InitInstance (hInstance, nCmdShow))
47
{
48
return FALSE;
49
}
50
51
if ( ! InitD3D())
52
{
53
return - 1 ;
54
}
55
56
ZeroMemory( & msg, sizeof (msg));
57
58
while (msg.message != WM_QUIT)
59
{
60
if (PeekMessage( & msg,NULL, 0 , 0 ,PM_REMOVE))
61
{
62
TranslateMessage( & msg);
63
DispatchMessage( & msg);
64
65
}
66
else
67
{
68
Render();
69
}
70
}
71
72
return ( int )msg.wParam;
73
}
74
75
76
ATOM MyRegisterClass(HINSTANCE hInstance)
77
{
78
WNDCLASSEX wcex;
79
80
wcex.cbSize = sizeof (WNDCLASSEX);
81
82
wcex.style = CS_HREDRAW | CS_VREDRAW;
83
wcex.lpfnWndProc = (WNDPROC)WndProc;
84
wcex.cbClsExtra = 0 ;
85
wcex.cbWndExtra = 0 ;
86
wcex.hInstance = hInstance;
87
wcex.hIcon = NULL;
88
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
89
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1 );
90
wcex.lpszMenuName = NULL;
91
wcex.lpszClassName = szWindowClass;
92
wcex.hIconSm = NULL;
93
return RegisterClassEx( & wcex);
94
}
95
96
97
BOOL InitInstance(HINSTANCE hInstance,
int
nCmdShow)
98
{
99
HWND hWnd;
100
101
hInst = hInstance;
102
103
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
104
CW_USEDEFAULT, 0 , CW_USEDEFAULT, 0 , NULL, NULL, hInstance, NULL);
105
106
if ( ! hWnd)
107
{
108
return FALSE;
109
}
110
111
g_hWnd = hWnd;
112
113
ShowWindow(hWnd, nCmdShow);
114
UpdateWindow(hWnd);
115
116
return TRUE;
117
}
118
119
120
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
121
{
122
switch (message)
123
{
124
case WM_DESTROY:
125
Release();
126
PostQuitMessage( 0 );
127
break ;
128
default :
129
return DefWindowProc(hWnd, message, wParam, lParam);
130
}
131
return 0 ;
132
}
133
134
135
void
Release()
136
{
137
if (pDevice != NULL)
138
pDevice -> Release();
139
if (pD3D != NULL)
140
pD3D -> Release();
141
}
142
143
144
bool
InitD3D()
145
{
146
pD3D = Direct3DCreate9(D3D_SDK_VERSION);
147
148
if (pD3D == NULL)
149
{
150
MessageBox(NULL,TEXT( " pD3D init failed " ),TEXT( " error " ),MB_OK);
151
return false ;
152
}
153
154
D3DPRESENT_PARAMETERS d3dpp;
155
156
ZeroMemory( & d3dpp, sizeof (d3dpp) );
157
d3dpp.Windowed = TRUE;
158
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
159
160
161
162
HRESULT hr;
163
hr = pD3D -> CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,
164
g_hWnd,
165
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
166
& d3dpp,
167
& pDevice);
168
169
if (FAILED(hr))
170
{
171
MessageBox(NULL,TEXT( " create device failed " ),TEXT( " error " ),MB_OK);
172
return false ;
173
}
174
175
return true ;
176
}
177
178
179
180
void
Render()
181
{
182
if (pDevice == NULL)
183
{
184
return ;
185
}
186
187
pDevice -> Clear( 1 ,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB( 0 , 0 , 0 ), 1.0f , 0 );
188
189
pDevice -> Present(NULL,NULL,NULL,NULL);
190
191
}
192
193
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/None.gif)
10
![](/Images/OutliningIndicators/None.gif)
11
![](/Images/OutliningIndicators/None.gif)
12
![](/Images/OutliningIndicators/None.gif)
13
![](/Images/OutliningIndicators/None.gif)
14
![](/Images/OutliningIndicators/None.gif)
15
![](/Images/OutliningIndicators/None.gif)
16
![](/Images/OutliningIndicators/None.gif)
17
![](/Images/OutliningIndicators/None.gif)
18
![](/Images/OutliningIndicators/None.gif)
19
![](/Images/OutliningIndicators/None.gif)
20
![](/Images/OutliningIndicators/None.gif)
21
![](/Images/OutliningIndicators/None.gif)
22
![](/Images/OutliningIndicators/None.gif)
23
![](/Images/OutliningIndicators/None.gif)
24
![](/Images/OutliningIndicators/None.gif)
25
![](/Images/OutliningIndicators/None.gif)
26
![](/Images/OutliningIndicators/None.gif)
27
![](/Images/OutliningIndicators/None.gif)
28
![](/Images/OutliningIndicators/None.gif)
29
![](/Images/OutliningIndicators/None.gif)
30
![](/Images/OutliningIndicators/None.gif)
31
![](/Images/OutliningIndicators/None.gif)
32
![](/Images/OutliningIndicators/None.gif)
33
![](/Images/OutliningIndicators/None.gif)
34
![](/Images/OutliningIndicators/None.gif)
35
![](/Images/OutliningIndicators/None.gif)
36
![](/Images/OutliningIndicators/None.gif)
37
![](/Images/OutliningIndicators/None.gif)
38
![](/Images/OutliningIndicators/None.gif)
39
![](/Images/OutliningIndicators/None.gif)
40
![](/Images/OutliningIndicators/None.gif)
41
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
42
![](/Images/OutliningIndicators/InBlock.gif)
43
![](/Images/OutliningIndicators/InBlock.gif)
44
![](/Images/OutliningIndicators/InBlock.gif)
45
![](/Images/OutliningIndicators/InBlock.gif)
46
![](/Images/OutliningIndicators/InBlock.gif)
47
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
48
![](/Images/OutliningIndicators/InBlock.gif)
49
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
50
![](/Images/OutliningIndicators/InBlock.gif)
51
![](/Images/OutliningIndicators/InBlock.gif)
52
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
53
![](/Images/OutliningIndicators/InBlock.gif)
54
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
55
![](/Images/OutliningIndicators/InBlock.gif)
56
![](/Images/OutliningIndicators/InBlock.gif)
57
![](/Images/OutliningIndicators/InBlock.gif)
58
![](/Images/OutliningIndicators/InBlock.gif)
59
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
60
![](/Images/OutliningIndicators/InBlock.gif)
61
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
62
![](/Images/OutliningIndicators/InBlock.gif)
63
![](/Images/OutliningIndicators/InBlock.gif)
64
![](/Images/OutliningIndicators/InBlock.gif)
65
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
66
![](/Images/OutliningIndicators/InBlock.gif)
67
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
68
![](/Images/OutliningIndicators/InBlock.gif)
69
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
70
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
71
![](/Images/OutliningIndicators/InBlock.gif)
72
![](/Images/OutliningIndicators/InBlock.gif)
73
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
74
![](/Images/OutliningIndicators/None.gif)
75
![](/Images/OutliningIndicators/None.gif)
76
![](/Images/OutliningIndicators/None.gif)
77
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
78
![](/Images/OutliningIndicators/InBlock.gif)
79
![](/Images/OutliningIndicators/InBlock.gif)
80
![](/Images/OutliningIndicators/InBlock.gif)
81
![](/Images/OutliningIndicators/InBlock.gif)
82
![](/Images/OutliningIndicators/InBlock.gif)
83
![](/Images/OutliningIndicators/InBlock.gif)
84
![](/Images/OutliningIndicators/InBlock.gif)
85
![](/Images/OutliningIndicators/InBlock.gif)
86
![](/Images/OutliningIndicators/InBlock.gif)
87
![](/Images/OutliningIndicators/InBlock.gif)
88
![](/Images/OutliningIndicators/InBlock.gif)
89
![](/Images/OutliningIndicators/InBlock.gif)
90
![](/Images/OutliningIndicators/InBlock.gif)
91
![](/Images/OutliningIndicators/InBlock.gif)
92
![](/Images/OutliningIndicators/InBlock.gif)
93
![](/Images/OutliningIndicators/InBlock.gif)
94
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
95
![](/Images/OutliningIndicators/None.gif)
96
![](/Images/OutliningIndicators/None.gif)
97
![](/Images/OutliningIndicators/None.gif)
98
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
99
![](/Images/OutliningIndicators/InBlock.gif)
100
![](/Images/OutliningIndicators/InBlock.gif)
101
![](/Images/OutliningIndicators/InBlock.gif)
102
![](/Images/OutliningIndicators/InBlock.gif)
103
![](/Images/OutliningIndicators/InBlock.gif)
104
![](/Images/OutliningIndicators/InBlock.gif)
105
![](/Images/OutliningIndicators/InBlock.gif)
106
![](/Images/OutliningIndicators/InBlock.gif)
107
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
108
![](/Images/OutliningIndicators/InBlock.gif)
109
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
110
![](/Images/OutliningIndicators/InBlock.gif)
111
![](/Images/OutliningIndicators/InBlock.gif)
112
![](/Images/OutliningIndicators/InBlock.gif)
113
![](/Images/OutliningIndicators/InBlock.gif)
114
![](/Images/OutliningIndicators/InBlock.gif)
115
![](/Images/OutliningIndicators/InBlock.gif)
116
![](/Images/OutliningIndicators/InBlock.gif)
117
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
118
![](/Images/OutliningIndicators/None.gif)
119
![](/Images/OutliningIndicators/None.gif)
120
![](/Images/OutliningIndicators/None.gif)
121
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
122
![](/Images/OutliningIndicators/InBlock.gif)
123
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
124
![](/Images/OutliningIndicators/InBlock.gif)
125
![](/Images/OutliningIndicators/InBlock.gif)
126
![](/Images/OutliningIndicators/InBlock.gif)
127
![](/Images/OutliningIndicators/InBlock.gif)
128
![](/Images/OutliningIndicators/InBlock.gif)
129
![](/Images/OutliningIndicators/InBlock.gif)
130
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
131
![](/Images/OutliningIndicators/InBlock.gif)
132
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
133
![](/Images/OutliningIndicators/None.gif)
134
![](/Images/OutliningIndicators/None.gif)
135
![](/Images/OutliningIndicators/None.gif)
136
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
137
![](/Images/OutliningIndicators/InBlock.gif)
138
![](/Images/OutliningIndicators/InBlock.gif)
139
![](/Images/OutliningIndicators/InBlock.gif)
140
![](/Images/OutliningIndicators/InBlock.gif)
141
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
142
![](/Images/OutliningIndicators/None.gif)
143
![](/Images/OutliningIndicators/None.gif)
144
![](/Images/OutliningIndicators/None.gif)
145
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
146
![](/Images/OutliningIndicators/InBlock.gif)
147
![](/Images/OutliningIndicators/InBlock.gif)
148
![](/Images/OutliningIndicators/InBlock.gif)
149
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
150
![](/Images/OutliningIndicators/InBlock.gif)
151
![](/Images/OutliningIndicators/InBlock.gif)
152
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
153
![](/Images/OutliningIndicators/InBlock.gif)
154
![](/Images/OutliningIndicators/InBlock.gif)
155
![](/Images/OutliningIndicators/InBlock.gif)
156
![](/Images/OutliningIndicators/InBlock.gif)
157
![](/Images/OutliningIndicators/InBlock.gif)
158
![](/Images/OutliningIndicators/InBlock.gif)
159
![](/Images/OutliningIndicators/InBlock.gif)
160
![](/Images/OutliningIndicators/InBlock.gif)
161
![](/Images/OutliningIndicators/InBlock.gif)
162
![](/Images/OutliningIndicators/InBlock.gif)
163
![](/Images/OutliningIndicators/InBlock.gif)
164
![](/Images/OutliningIndicators/InBlock.gif)
165
![](/Images/OutliningIndicators/InBlock.gif)
166
![](/Images/OutliningIndicators/InBlock.gif)
167
![](/Images/OutliningIndicators/InBlock.gif)
168
![](/Images/OutliningIndicators/InBlock.gif)
169
![](/Images/OutliningIndicators/InBlock.gif)
170
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
171
![](/Images/OutliningIndicators/InBlock.gif)
172
![](/Images/OutliningIndicators/InBlock.gif)
173
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
174
![](/Images/OutliningIndicators/InBlock.gif)
175
![](/Images/OutliningIndicators/InBlock.gif)
176
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
177
![](/Images/OutliningIndicators/None.gif)
178
![](/Images/OutliningIndicators/None.gif)
179
![](/Images/OutliningIndicators/None.gif)
180
![](/Images/OutliningIndicators/None.gif)
181
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
182
![](/Images/OutliningIndicators/InBlock.gif)
183
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](/Images/dot.gif)
184
![](/Images/OutliningIndicators/InBlock.gif)
185
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
186
![](/Images/OutliningIndicators/InBlock.gif)
187
![](/Images/OutliningIndicators/InBlock.gif)
188
![](/Images/OutliningIndicators/InBlock.gif)
189
![](/Images/OutliningIndicators/InBlock.gif)
190
![](/Images/OutliningIndicators/InBlock.gif)
191
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
192
![](/Images/OutliningIndicators/None.gif)
193
![](/Images/OutliningIndicators/None.gif)