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
|
#include "dxLibrary.h"
BOOL dxInitWindow(int iWidth, int iHeight, char* pcTitle, HICON hIcon)
{
HWND hWnd;
WNDCLASSEX wndclass = {sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0, 0, GetModuleHandle(NULL), hIcon, NULL, NULL, NULL,
"DX Window", NULL};
if (!RegisterClassEx(&wndclass))
{
MessageBox(hWnd, "ERROR DX11: An error encountered while registering WNDCLASS!", "ERROR DX11", MB_OK | MB_ICONSTOP);
return FALSE;
}
dxHWND = CreateWindow("DX Window", pcTitle, WS_VISIBLE | WS_OVERLAPPEDWINDOW, GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN), iWidth, iHeight, NULL, NULL, GetModuleHandle(NULL), NULL);
if (dxHWND == NULL)
{
MessageBox(hWnd, "ERROR DX12: Creating window failed!", "ERROR DX12", MB_OK | MB_ICONSTOP);
return FALSE;
}
return TRUE;
}
BOOL dxInitD3D(SDirect3DParameters* pParameters, HWND hWnd)
{
HRESULT hResult;
D3DPRESENT_PARAMETERS PresentParams;
if (pParameters == NULL)
{
MessageBox(hWnd, "ERROR DX21: Nullpointer!", "ERROR DX21", MB_OK | MB_ICONSTOP);
return FALSE;
}
g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if (g_pD3D == NULL)
{
MessageBox(hWnd, "ERROR DX22: Creating Direct3D Device failed!", "ERROR DX22", MB_OK | MB_ICONSTOP);
return FALSE;
}
ZeroMemory(&PresentParams, sizeof(D3DPRESENT_PARAMETERS));
PresentParams.BackBufferWidth = pParameters->VideoMode.Width;
PresentParams.BackBufferHeight = pParameters->VideoMode.Height;
PresentParams.BackBufferFormat = pParameters->BackBufferFormat;
PresentParams.BackBufferCount = 1;
PresentParams.MultiSampleType = pParameters->MultiSamplingType;
PresentParams.MultiSampleQuality = pParameters->dwMultiSamplingQuality;
PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
PresentParams.hDeviceWindow = hWnd;
PresentParams.Windowed = pParameters->bWindowed;
PresentParams.EnableAutoDepthStencil = TRUE;
PresentParams.AutoDepthStencilFormat = pParameters->ZStencilBufferFormat;
PresentParams.Flags = pParameters->ZStencilBufferFormat != D3DFMT_D16_LOCKABLE ? D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL : 0;
PresentParams.FullScreen_RefreshRateInHz = pParameters->bWindowed ? D3DPRESENT_RATE_DEFAULT : pParameters->VideoMode.RefreshRate;
PresentParams.PresentationInterval = pParametes->bWindowed ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_ONE;
if (FAILED(hResult = g_pD3D->CreateDevice(pParameters->iAdapter, pParameters->DeviceType, hWnd, pParameters->dwFlags,
&PresentParams, &g_pD3DDevuce)))
{
MessageBox(hWnd, "ERROR DX23: Creating Direct3D Device failed", "ERROR DX23", MB_OK | MB_ICONSTOP);
return FALSE;
}
if (!pParameters->bWindowed) ShowCursor(FALSE);
return TRUE;
}
|