-
Direct3D CreateDevice
Code:
pDirect3D=Direct3DCreate9(D3D_SDK_VERSION);
if(pDirect3D==NULL)
{
goto EXIT;
}
D3DPRESENT_PARAMETERS D3DPresentParams;
ZeroMemory(&D3DPresentParams, sizeof(D3DPRESENT_PARAMETERS));
D3DPresentParams.Windowed=false;
D3DPresentParams.BackBufferCount=1;
D3DPresentParams.BackBufferWidth=800;
D3DPresentParams.BackBufferHeight=600;
D3DPresentParams.BackBufferFormat=D3DFMT_X8R8G8B8;
D3DPresentParams.SwapEffect=D3DSWAPEFFECT_DISCARD;
D3DPresentParams.hDeviceWindow=hWnd;
HRESULT hResult = pDirect3D->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, FALSE);
if(hResult!=D3D_OK)
{
MessageBox(hWnd, L"CheckDeviceType failed!", L"", MB_OK);
goto EXIT;
}
hResult = pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,&D3DPresentParams, &pDirect3DDevice);
if(hResult!=D3D_OK)
{
MessageBox(hWnd, L"CreateDevice failed!", L"", MB_OK);
goto EXIT;
}
The display format is compatible with my system. The file compiles, but for some reason, I can NOT get the CreateDevice call to work. The DirectX pointers are declared as global variables in the program. I am using Visual Studio 2005. Just a FYI, the gotos are in there for debugging purposes. Any help is greatly appreciated.
-
are you linking with d3d9.lib and including d3d9.h ?
make sure d3d8.lib isnt being linked instead/also.
also, you may want to put in some error handlign code to better handle results other than DD_OK. It may be a recoverable error.
D3DERR_INVALIDCALL means one of your parameters is invalid
D3DERR_NOTAVAILABLE means your card doesnt support soem feature you asked for.
D3DERR_OUTOFVIDEOMEMORY means you dont have enough video memory to perform the action.
use a simple switch statement to report the specific error (via messagebox) to gain more insight
offhand id also suggest you change
Code:
hResult = pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,&D3DPresentParams, &pDirect3DDevice);
to:
Code:
hResult = pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING,&D3DPresentParams, &pDirect3DDevice);
Some cards dont seem to like doing software vertex processing in full screen mode.
-
"cannot get to work" is far too vague for any kind of meaningful help. What errors are you getting? Does it compile? None of us can read minds... at least, I hope not... :eek: