Original Post
I've been staring at this source I wrote but can't find the problem. It starts up fine in windowed mode but when I change it to fullscreen, I get the messagebox errors. As I said, when I run windowed it's fine but when I turn on fullscreen, the errors comes up: "Could not initialize 3D card!" Obviously, the createdevice call is failing. I think it has to do w/ one of the parameters in d3dpp but I'm not sure which one. I'm using DX9 for the coding. I think I've been staring at the code too long, I just can't find the problem. Thanks for any help you can give.
int InitD3DDevice(HWND hWndTarget, int Width, int Height, BOOL bWindowed,
D3DFORMAT FullScreenFormat, LPDIRECT3D9 pD3D, LPDIRECT3DDEVICE9* ppDevice)
{
D3DPRESENT_PARAMETERS d3dpp;
D3DDISPLAYMODE d3ddm;
HRESULT result = 0;
if(*ppDevice)
(*ppDevice)->Release();
ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
result = pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);
if(FAILED(result))
{
MessageBox(g_hWndMain, "Could not get 3D card!", "Error", MB_OK | MB_ICONINFORMATION);
return E_FAIL;
}
if(bWindowed)
{
d3dpp.BackBufferWidth = Width;
d3dpp.BackBufferHeight = Height;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
d3dpp.hDeviceWindow = hWndTarget;
d3dpp.Windowed = TRUE;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
}
if(!bWindowed)
{
d3dpp.BackBufferWidth = Width;
d3dpp.BackBufferHeight = Height;
d3dpp.BackBufferFormat = FullScreenFormat;
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
d3dpp.hDeviceWindow = hWndTarget;
d3dpp.Windowed = FALSE;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
}
result = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWndTarget,
D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, ppDevice);
if(FAILED(result))
{
MessageBox(g_hWndMain, "Could not initialize 3D card!", "Error", MB_OK | MB_ICONINFORMATION);
return E_FAIL;
}
g_DeviceHeight = Height;
g_DeviceWidth = Width;
g_SavedPresParams = d3dpp;
return S_OK;
}