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
|
//*************************************************************************//
//******************************* LIQUID 3D *******************************//
//*************************************************************************//
//* Letzte Aktualisierung: 01.04.2007 *//
//* Content: Direct3D Initialisierung/test *//
//* *//
//* *//
//*************************************************************************//
#include "main.h"
//*************************************************************************
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
//*************************************************************************
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASS wc;
//Log starten
lqLogInit("log.html");
//Config Dialog ausführen
lqConfig Config=lqConfigDoConfig();
//Eigenschaften festlegen
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)CreateSolidBrush(RGB(0,0,0));
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance=hInstance;
wc.lpfnWndProc=WndProc;
wc.lpszClassName="WindowClass1";
wc.lpszMenuName=NULL;
wc.style=CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
//Klasse registrieren
RegisterClass(&wc);
//Fenster erstellen
hWnd=CreateWindow(wc.lpszClassName,"Direct3D - Startup",WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
Config.VideoMode.Width,Config.VideoMode.Height,NULL,NULL,
hInstance,NULL);
//Fenster anzeigen
ShowWindow(hWnd,iCmdShow);
//Neu zeichnen
UpdateWindow(hWnd);
//Direct3D initialisieren
InitDirect3D(Config,hWnd);
InitScene(Config);
//Nachrichtenschleife
while(GetMessage(&msg,NULL,0,0))
{
//Nachrichten verarbeiten
TranslateMessage(&msg);
DispatchMessage(&msg);
//Direct3D
Render();
}
//Log beenden
lqExitLog();
//Direct3D herunterfahren
ExitDirect3D();
//Alles klar
return 0;
}
//*************************************************************************
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//Nachrichten
switch(message)
{
case WM_CREATE:
{
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
//Alles ok
return DefWindowProc(hWnd, message, wParam, lParam);
}
//*************************************************************************
lqResult InitDirect3D(const lqConfig& Config, HWND hWnd)
{
HRESULT hr;
D3DPRESENT_PARAMETERS PresentParams;
//Globale SChnittstelle erstellen
g_pD3D=Direct3DCreate9(D3D_SDK_VERSION);
//Schnittstelle erzeugt?
if(!g_pD3D)
{
LQ_ERROR("Direct3D-Schnittstelle konnte nicht erzeugt werden!");
}
//PresentParams vorbereiten
ZeroMemory(&PresentParams,sizeof(D3DPRESENT_PARAMETERS));
PresentParams.BackBufferWidth=Config.VideoMode.Width;
PresentParams.BackBufferHeight=Config.VideoMode.Height;
PresentParams.BackBufferFormat=Config.BackBufferFormat;
PresentParams.BackBufferCount=1;
PresentParams.MultiSampleType=Config.MultiSamplingType;
PresentParams.MultiSampleQuality=Config.dwMultiSamplingQuality;
PresentParams.SwapEffect=D3DSWAPEFFECT_DISCARD;
PresentParams.hDeviceWindow=hWnd;
PresentParams.Windowed=Config.bWindowed;
PresentParams.EnableAutoDepthStencil=true;
PresentParams.AutoDepthStencilFormat=Config.ZStencilBufferFormat;
PresentParams.Flags= Config.ZStencilBufferFormat!= D3DFMT_D16_LOCKABLE ? D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL : 0;
PresentParams.FullScreen_RefreshRateInHz= Config.bWindowed ? D3DPRESENT_RATE_DEFAULT : Config.VideoMode.RefreshRate;
PresentParams.PresentationInterval= Config.bWindowed ? D3DPRESENT_INTERVAL_IMMEDIATE : D3DPRESENT_INTERVAL_ONE;
//D3DDevice erstellen
if(FAILED(g_pD3D->CreateDevice(Config.iAdapter,Config.DeviceType,hWnd,Config.dwFlags,&PresentParams,&g_pD3DDevice)))
{
ExitDirect3D();
LQ_ERROR("Direct3DDevice konnte nicht erstellt werden!");
}
return LQ_OK;
}
//*************************************************************************
lqResult ExitDirect3D(void)
{
if(g_pD3D)g_pD3D->Release();
if(g_pD3DDevice)g_pD3DDevice->Release();
return LQ_OK;
}
//*************************************************************************
lqResult InitScene(lqConfig Config)
{
//Vertexformat setzen
if(FAILED(g_pD3DDevice->SetFVF(SVertex::dwFvF)))LQ_ERROR("konnte Vertex format nicht setzen");
//Renderstates setzen
g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
g_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
g_pD3DDevice->SetRenderState(D3DRS_DITHERENABLE, TRUE);
//Geometrie vorbereiten
g_aTriangleVertex[0].vPosition=lqVector3(0.0f,1.0f,0.0f);
g_aTriangleVertex[1].vPosition=lqVector3(1.0f,-1.0f,0.0f);
g_aTriangleVertex[2].vPosition=lqVector3(-1.0f,-1.0f,0.0f);
g_aTriangleVertex[0].dwColor=0xFFFFFFFF;
g_aTriangleVertex[1].dwColor=0xFFFFFFFF;
g_aTriangleVertex[2].dwColor=0xFFFFFFFF;
//Projektionsmatrix setzen
float fAspect=Config.VideoMode.Width/Config.VideoMode.Height;
lqMatrix mProjection=lqMatrixProjection(lqDegToRad(45.0f),fAspect,0.1f,100.0f);
g_pD3DDevice->SetTransform(D3DTS_PROJECTION,(D3DMATRIX*)(&mProjection));
LQ_INFO("InitScene erfolgreich!");
//Alles ok;
return LQ_OK;
}
//*************************************************************************
lqResult Render(void)
{
lqMatrix mRotation=lqMatrixRotationY(lqDegToRad(45.0f));
lqMatrix mTranslation=lqMatrixTranslation(lqVector3(0.0f,0.0f,-5.0f));
lqMatrix mWorld=mRotation*mTranslation;
g_pD3DDevice->SetTransform(D3DTS_WORLD,(D3DMATRIX*)(&mWorld));
//Device löschen
g_pD3DDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0),0.0f,0);
//Zeichnen
g_pD3DDevice->BeginScene();
if(FAILED(g_pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST,1,(void*)g_aTriangleVertex,sizeof(SVertex))))LQ_ERROR("konnte nicht zeichnen!");
g_pD3DDevice->EndScene();
g_pD3DDevice->Present(NULL,NULL,NULL,NULL);
LQ_INFO("Rendern erfolgreich!");
return LQ_OK;
}
//*************************************************************************
|