#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "EASTL.lib")
#pragma comment(lib, "DxErr.lib")
#pragma comment(lib, "legacy_stdio_definitions.lib")
#pragma comment(lib, "winmm.lib")
#include <stdint.h>
void* operator new[](size_t size, const char* name, int flags, unsigned debugFlags, const char* file, int line)
{ return new uint8_t[size]; }
void* operator new[](size_t size, size_t alignment, size_t alignmentOffset, const char* pName, int flags, unsigned debugFlags, const char* file, int line)
{ return new uint8_t[size]; }
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <stdio.h>
#include <DxErr.h>
#include <iostream>
using namespace std;
#include "EASTL\vector.h"
using namespace eastl;
IDirect3D9* g_pD3D = 0;
UINT g_Adapter = D3DADAPTER_DEFAULT;
D3DDEVTYPE g_DevType = D3DDEVTYPE_HAL;
D3DCAPS9 g_Caps;
DWORD g_VertexProc = 0;
IDirect3DDevice9* g_pd3dDevice = 0;
D3DDISPLAYMODE d_Mode;
D3DPRESENT_PARAMETERS d3dpp{};
HWND hWnd;
void Disp_HR(HRESULT hr)
{
cout << hr << endl;
cout << DXGetErrorString(hr) << endl;
cout << DXGetErrorDescription(hr) << endl << endl;
}
HRESULT InitD3D()
{
g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if (!g_pD3D)
return E_FAIL;
g_pD3D->GetDeviceCaps(g_Adapter, g_DevType, &g_Caps);
if (g_Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
g_VertexProc = D3DCREATE_HARDWARE_VERTEXPROCESSING;
else
g_VertexProc = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d_Mode);
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
d3dpp.Windowed = true;
return g_pD3D->CreateDevice(g_Adapter, g_DevType, hWnd, g_VertexProc, &d3dpp, &g_pd3dDevice);
}
void Render()
{
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 120), 1.0f, 0);
g_pd3dDevice->BeginScene();
g_pd3dDevice->EndScene();
g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
}
LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
PostQuitMessage(0); break;
case WM_PAINT:
Render();
ValidateRect(hWnd, NULL); break;
case WM_KEYDOWN:
if (wParam == VK_ESCAPE)
DestroyWindow(hWnd);
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
int main()
{
const char* win_ClassName = "D3D Tutor 111";
WNDCLASS wc
{
0,
MsgProc, 0, 0, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW),
NULL, NULL, win_ClassName
};
RegisterClass(&wc);
hWnd = CreateWindow(win_ClassName, "D3D Test My 111",
WS_OVERLAPPEDWINDOW , 700, 200,
800, 600, NULL, NULL, wc.hInstance, NULL);
HRESULT hr = InitD3D();
if (FAILED(hr))
{
Disp_HR(hr);
return 1;
}
ShowWindow(hWnd, SW_SHOWDEFAULT);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}