-
CreateDevice failing
I can't figure out why this code is failing, it's basic so its frustrating. The message "arg" always displays meaning that CreateDevice is failing for whatever reason.
Code:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
"Real Earth Engine test App", NULL };
RegisterClassEx( &wc );
HWND hWnd = CreateWindow( "Engine", "Public Demo",
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
GetDesktopWindow(), NULL, wc.hInstance, NULL );
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
return false;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
MessageBox(NULL, "arg", NULL, NULL);
return -1;
}
}
thank you
-
your back buffer's dimensions are 0x0
-
I don't understand what you mean?
What do I need to do to fix the problem
Thanks
-
Code:
d3dpp.BackBufferWidth = 800;
d3dpp.BackBufferHeight = 600;
You need those. There might be some other required settings too, I'll post a default version for you with everything set so you can get an idea of the other members:
Code:
D3DPP.BackBufferWidth = 800;
D3DPP.BackBufferHeight = 600;
D3DPP.BackBufferFormat = D3DFMT_A8R8G8B8;
D3DPP.BackBufferCount = 1;
D3DPP.MultiSampleType = D3DMULTISAMPLE_NONE;
D3DPP.MultiSampleQuality = 0;
D3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD;
D3DPP.hDeviceWindow = hwnd;
D3DPP.Windowed = true;
D3DPP.EnableAutoDepthStencil = true;
D3DPP.AutoDepthStencilFormat = D3DFMT_D24S8;
D3DPP.Flags = 0;
D3DPP.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
D3DPP.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
-
Arg, the dang thing still pops up
Code:
#include <d3d9.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
HWND hWnd = NULL;
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
return -1;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
d3dpp.BackBufferHeight = 1024;
d3dpp.BackBufferWidth = 768;
d3dpp.EnableAutoDepthStencil = false;
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.hDeviceWindow = hWnd;
d3dpp.MultiSampleQuality = 0;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.Windowed = FALSE;
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
MessageBox(NULL, "Fail", NULL, NULL);
return -1;
}
return 0;
}
Now I'm off for homework, sleep, and then to check out a Direct3D book :)
-
well, as a rule of thumb, whenever I work on cars..
Say the pressure gague is giving you a 0 rating...
What is the first thing you check?
The pressure gague!
So check your if statement :)
-
You don't have to set the dimensions, leaving them out will use the dimensions of the window you use (since you have Windowed == TRUE).
You should sheck the return-value form CreateDevice to see exactly what error you get. It may be something simple like your system not supporting A8R8G8B8 back buffers (note the A, I've had trouble with this before, try X8R8G8B8 instead).