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
|
veResult veDirect3D::Init(bool bWindowed, char * pcWindowTitle, HINSTANCE hInstance)
{
// -----------------------------------------------------------------------------------
// Direct3D initialisieren
// -----------------------------------------------------------------------------------
// Variablen deklarieren
HRESULT hResult; // Ist die Funktion erfolgreich oder nicht?
D3DPRESENT_PARAMETERS PresentParams; // PresentParamters f¸r Direct3D
D3DDISPLAYMODE VideoMode; // Struktur ausf¸llen
WNDCLASSEX wc; // WNDCLASSEX-Struktur Variable um die Struktur zu f¸llen
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbSize = sizeof(WNDCLASSEX);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.cbWndExtra = 0;
wc.cbClsExtra = 0;
wc.lpszClassName = "VisualEngine";
wc.lpszMenuName = NULL;
wc.hbrBackground = HBRUSH(GetStockObject(BLACK_BRUSH));
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Fehler beim Registrieren des Fensters", "Fehler aufgetreten",
MB_OK | MB_ICONEXCLAMATION);
return VE_ERROR;
}
// Fenster erzeugen
m_hwnd = CreateWindow("VisualEngine",
pcWindowTitle,
WS_VISIBLE | WS_OVERLAPPEDWINDOW,
GetSystemMetrics(SM_CXSCREEN) / 2,
GetSystemMetrics(SM_CYSCREEN) / 2,
800,
600,
NULL,
NULL,
hInstance,
NULL);
if(!m_hwnd)
{
MessageBox(NULL, "Fehler beim Erstellen des Fensters", "Fehler aufgetreten",
MB_OK | MB_ICONEXCLAMATION);
return VE_ERROR;
}
// Direct3D Schnittstelle erzeugen
m_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &VideoMode);
ZeroMemory(&PresentParams, sizeof(D3DPRESENT_PARAMETERS));
// Presentations-Parameter setzen
PresentParams.hDeviceWindow = m_hwnd;
PresentParams.BackBufferCount = 1;
PresentParams.BackBufferFormat = D3DFMT_X8R8G8B8;
PresentParams.BackBufferWidth = 800;
PresentParams.BackBufferHeight = 600;
PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
PresentParams.EnableAutoDepthStencil = true;
PresentParams.AutoDepthStencilFormat = D3DFMT_D16;
PresentParams.Windowed = bWindowed;
PresentParams.MultiSampleQuality = NULL;
PresentParams.MultiSampleType = D3DMULTISAMPLE_NONE;
PresentParams.Flags = NULL;
PresentParams.FullScreen_RefreshRateInHz = VideoMode.RefreshRate;
PresentParams.PresentationInterval = NULL;
// IDirect3DDevice-Schnittstelle erzeugen
if(FAILED(hResult = m_pD3D->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
m_hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&PresentParams,
&m_pD3DDevice)))
{
MessageBox(NULL, "Fehler beim erstellen der IDirect3DDevice-Schnittstelle", "Fehler aufgetreten",
MB_OK | MB_ICONEXCLAMATION);
return VE_ERROR;
}
// PresentParams der private Variable ¸bergeben
m_PresentParams = PresentParams;
// Anzahl der RenderObjekte auf 0 setzen
m_NumRenderObjects = 0;
// Alle RenderObjekte auf false setzen
for(int iRenderObject = 0; iRenderObject < 10000; iRenderObject++)
{
m_RenderObjects[iRenderObject].IsRenderObject = false;
m_RenderObjects[iRenderObject].RenderObjectType = VE_NONE;
}
// Direct3D wurde initialisiert, also Variable auf True setzen.
m_bInitialized = true;
return VE_OK;
}
|