#include "d3dUtility.h"
IDirect3DDevice9 * Device = 0;
bool Setup()
{
return true;
}
void Cleanup()
{
}
bool Display(float timeDelta)
{
if(Device)
{
Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, //clears backbuffer and depth/stencil buffer to black
0x00000000, 1.0f, 0);
Device->Present(0, 0, 0, 0); // present backbuffer
}
return true;
}
//windows procedure method
LRESULT CALLBACK d3d::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
:

ostQuitMessage(0);
break;
case WM_KEYDOWN:
if (wParam == VK_ESCAPE)
{
:

estroyWindow(hwnd);
break;
}
}
return :

efWindowProc(hwnd, msg, wParam, lParam);
}
//WinMain()
int WINAPI WinMain (HINSTANCE hinstance,
HINSTANCE prevInstance,
PSTR cmdLine,
int showCmd)
{
if(!d3d::InitD3D(hinstance,
800, 600, true, D3DDEVTYPE_HAL, &Device))
{
::MessageBox(0, TEXT("InitD3D() - FAILED"), 0, 0);
return 0;
}
if (!Setup())
{
::MessageBox(0, TEXT("Setup() - FAILED"), 0, 0);
return 0;
}
d3d::EnterMsgLoop(Display);
Cleanup();
Device->Release();
return 0;
}
d3dUtility.h
#include <d3dx9.h>
#include <d3d9.h>
#include <string>
namespace d3d
{
bool InitD3D(
HINSTANCE hInstance, // application instance
int width, int height, // back buffer dimensions
bool windowed, //windows (true) or full screen (false)
D3DDEVTYPE deviceType, //HAL or REF
IDirect3DDevice9** device); //created device
//application message loop
int EnterMsgLoop(
bool (*ptr_display)(float timeDelta));
//callback function declaration
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam);
template<class T> void Release(T t)
{
if (t)
{
t->Release();
t = 0;
}
}
template<class T> void Delete(T t)
{
if (t)
{
t = 0;
}
}
}
Partager