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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
#include <Windows.h>
#include <StdIO.h>
#include <D3D9.h>
#include <d3dx9.h>
#include <string.h>
#include <iostream>
#include <math.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* pcCmdLine, int iShowCmd){
HWND hwnd;
MSG msg;
WNDCLASSEXW wndclass;
// Fenster bauen
wndclass.cbSize = sizeof(WNDCLASSEXW);
wndclass.style = CS_CLASSDC;
wndclass.lpfnWndProc = WindowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = NULL;
wndclass.hCursor = NULL;
wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = L"Testfenster";
wndclass.hIconSm = NULL;
RegisterClassExW(&wndclass);
hwnd = CreateWindowW(L"Testfenster",
L"Testfenster",
WS_VISIBLE | WS_OVERLAPPEDWINDOW,
GetSystemMetrics(SM_CXSCREEN) / 2 - 400,
GetSystemMetrics(SM_CYSCREEN) / 2 - 200,
800,
400,
NULL,
NULL,
NULL,
NULL);
ShowWindow(hwnd, iShowCmd);
UpdateWindow(hwnd);
//Direct3D Teil
IDirect3D9 *pD3D = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS PresentParams;
PresentParams.BackBufferWidth = 1680;
PresentParams.BackBufferHeight = 1050;
PresentParams.BackBufferFormat = D3DFMT_A8R8G8B8;
PresentParams.BackBufferCount = 1;
PresentParams.MultiSampleType = D3DMULTISAMPLE_4_SAMPLES;
PresentParams.MultiSampleQuality = 4;
PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
PresentParams.hDeviceWindow = hwnd;
PresentParams.Windowed = FALSE;
PresentParams.EnableAutoDepthStencil = TRUE;
PresentParams.AutoDepthStencilFormat = D3DFMT_D24X8;
PresentParams.Flags = 0;
PresentParams.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
PresentParams.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
PDIRECT3DDEVICE9 test;
pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &PresentParams, &test);
test->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);
test->SetRenderState(D3DRS_LIGHTING, FALSE);
test->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
test->SetRenderState(D3DRS_DITHERENABLE, TRUE);
// Projektionsmatrix erzeugen
D3DXMATRIX Projektionsmatrix;
const float near_plane=0.1f; // Distance to near clipping // plane
const float far_plane=100.0f; // Distance to far clipping // plane
const float fov_horiz=45.0f; // Horizontal field of view // angle, in radians
const float fov_vert=45.0f; // Vertical field of view // angle, in radians
float h, w, Q;
w = static_cast<float>(1/tan(fov_horiz*0.5)); // 1/tan(x) == cot(x)
h = static_cast<float>(1/tan(fov_vert*0.5)); // 1/tan(x) == cot(x)
Q = far_plane/(far_plane - near_plane);
ZeroMemory(&Projektionsmatrix, sizeof(Projektionsmatrix));
Projektionsmatrix(0, 0) = w;
Projektionsmatrix(1, 1) = h;
Projektionsmatrix(2, 2) = Q;
Projektionsmatrix(3, 2) = -Q*near_plane;
Projektionsmatrix(2, 3) = 1;
test->SetTransform(D3DTS_PROJECTION, &Projektionsmatrix);
// End of ProjectionMatrix
D3DXMATRIX Rotation;
D3DXMATRIX Translation;
D3DXMATRIX Welt;
Rotation=*(&Translation);
Welt=Rotation;
test->SetTransform(D3DTS_WORLD, &Welt);
//Das Dreieck bauen
struct SVertex {
D3DVECTOR Position;
DWORD Farbe;
};
SVertex Dreieck[3];
Dreieck[0].Position.x=0.0f;
Dreieck[0].Position.y=0.0f;
Dreieck[0].Position.z=70.0f;
Dreieck[0].Farbe=(0x80FF00FF);
Dreieck[1].Position.x=1.0f;
Dreieck[1].Position.y=1.0f;
Dreieck[1].Position.z=70.0f;
Dreieck[1].Farbe=(0x80F0000F);
Dreieck[2].Position.x=1.0f;
Dreieck[2].Position.y=0.0f;
Dreieck[2].Position.z=70.0f;
Dreieck[2].Farbe=(0x800F0F0F);
msg.message=WM_NULL;
while(msg.message != WM_QUIT)
{
if(PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
test->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
test->BeginScene();
test->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 3, &Dreieck, sizeof(D3DVECTOR));
test->EndScene();
test->Present(NULL,NULL,NULL,NULL);
}
}
UnregisterClassW(wndclass.lpszClassName, hInstance);
test->Release();
pD3D->Release();
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
return 0;
break;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
|