Code:
/*
* d3d
*/
#include <windows.h>
#include "GFXBase.h"
//#include <d3d9.h>
#include <d3dx9.h>
#include "D3DManager.h"
D3DManager* d3dm = 0;
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void Render(float timeDelta);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
GFXBase* gfxBase = GFXBase::CreateInstance();
MSG msg;
HWND hWnd = 0;
bool done = false;
static float lastTime = (float) timeGetTime();
float currTime;
float timeDelta;
d3dm = new D3DManager;
hWnd = gfxBase->NewWindow(hInstance, WndProc, WS_OVERLAPPEDWINDOW, "d3d", "d3d", 0, 0, 640, 480);
if (! hWnd) {
::MessageBox(0, "GFXBase::NewWindow failed", "Error", MB_OK | MB_ICONERROR | MB_TASKMODAL);
gfxBase->DestroyWindow();
GFXBase::FreeInstance();
return 1;
}
if (! d3dm->Initialise(hWnd, D3DDEVTYPE_HAL, 640, 480, true)) {
::MessageBox(0, "D3DManager::Initialise failed", "Error", MB_OK | MB_ICONERROR | MB_TASKMODAL);
return 1;
}
ShowWindow(hWnd, nCmdShow);
SetFocus(hWnd);
UpdateWindow(hWnd);
ZeroMemory(&msg, sizeof(MSG));
while (! done) {
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) done = true;
TranslateMessage(&msg);
DispatchMessage(&msg);
} else {
currTime = (float) timeGetTime();
timeDelta = (currTime - lastTime) * 0.001f;
Render(timeDelta);
lastTime = currTime;
}
}
gfxBase->DestroyWindow();
GFXBase::FreeInstance();
delete d3dm;
return msg.wParam;
}
void Render(float timeDelta)
{
if (d3dm->VerifyDevice()) {
d3dm->GetDevice()->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
d3dm->GetDevice()->Present(0, 0, 0, 0);
}
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
EDIT: Actually, I lie. I just realised that's my desktop wallpaper. Coincidence that I'd just stopped playing BM, but still, why?