Right i attempted it again and i think i got a bit further, but before i go any further.... i've got an error.
Code:
CInitDirectX.cpp(12) : error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'WNDPROC'
None of the functions with this name in scope match the target type
I don't know how to fix this error... here is the code:
CRenderDevice.h
Code:
#include <d3dx9.h>
class CRenderDevice
{
public:
HRESULT CInitDirectX(
HINSTANCE hInstance,
int width, int height,
bool windowed,
D3DDEVTYPE deviceType,
IDirect3DDevice9** device);
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)
{
delete t;
t = 0;
}
}
protected:
int width;
int height;
int vp;
bool windowed;
D3DCAPS9 caps;
IDirect3D9* d3d9;
HRESULT hr;
HINSTANCE hInstance;
HWND hwnd;
UINT Msg;
D3DDEVTYPE deviceType;
IDirect3DDevice9** device;
};
CInitDirectX.cpp
Code:
#include "CRenderDevice.h"
HRESULT CRenderDevice::CInitDirectX(
HINSTANCE hInstance,
int width, int height,
bool windowed,
D3DDEVTYPE deviceType,
IDirect3DDevice9** device)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(0, IDI_APPLICATION);
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = "Direct3DApp";
if(!RegisterClass(&wc))
{
MessageBox(0, "RgisterClass() - FAILED!", "Error", 0);
return 0;
}
hwnd = CreateWindowEx(
0,
"Direct£DApp",
"Direct3DApp",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
width,
height,
hwnd,
NULL,
hInstance,
NULL);
if(!hwnd)
{
MessageBox(0, "CreateWindowEx() - FAILED!", "Error", 0);
return 0;
}
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
if(!d3d9)
{
MessageBox(0, "Direct3DCreate9() - FAILED!", "Error", 0);
return 0;
}
d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, deviceType, &caps);
if(caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
{
vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
}
else
{
vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}
D3DPRESENT_PARAMETERS d3dpp;
d3dpp.BackBufferWidth = width;
d3dpp.BackBufferHeight = height;
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hwnd;
d3dpp.Windowed = windowed;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
hr = d3d9->CreateDevice(
D3DADAPTER_DEFAULT,
deviceType,
hwnd,
vp,
&d3dpp,
device);
if(FAILED(hr))
{
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
hr = d3d9->CreateDevice(
D3DADAPTER_DEFAULT,
deviceType,
hwnd,
vp,
&d3dpp,
device);
}
if(FAILED(hr))
{
d3d9->Release();
MessageBox(0, "CreateDevice() - FAILED!", "Error", 0);
return 0;
}
d3d9->Release();
return 1;
}