Minimal code to create a Direct3D9 Device
This isn't for stable release code, I just need to get a windowed D3D9 device created in a C++ app from a HWND on my dev PC for testing something... it can default on loads of options.
I was trying to hack it together from an old D3D8 class I had but I'm getting D3DERR_INVALIDCALL.
Basically I have this now:
HWND mHWnd = ...;
LPDIRECT3D9 mpD3D = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS md3dpp;
ZeroMemory( &md3dpp, sizeof(D3DPRESENT_PARAMETERS) );
md3dpp.Windowed = true;
md3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
md3dpp.BackBufferCount = 1;
md3dpp.EnableAutoDepthStencil = 0;
md3dpp.hDeviceWindow = mHWnd;
md3dpp.BackBufferWidth = 0;
md3dpp.BackBufferHeight = 0;
md3dpp.FullScreen_RefreshRateInHz = 0;
md3dpp.Present开发者_如何学GoationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
md3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
md3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
md3dpp.MultiSampleQuality = 0;
LPDIRECT3DDEVICE9 mpD3DDevice=0;
HRESULT hr = mpD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,mHWnd,0,&md3dpp,&mpD3DDevice);
I figure some D3DPRESENT_PARAMETERS
options might be to blame - I don't care about back-buffers of z-buffers or stencils or AA, any old plain device is fine.
Have I copy-pasted together some incompatible flags?
1 problem is that you need to set some Behaviour flags.
From the docs on CreateDevice.:
BehaviorFlags [in]
DWORD
Combination of one or more options that control device creation. For more information, see D3DCREATE.
And from the D3DCREATE docs:
D3DCREATE_HARDWARE_VERTEXPROCESSING, D3DCREATE_MIXED_VERTEXPROCESSING, and D3DCREATE_SOFTWARE_VERTEXPROCESSING are mutually exclusive flags. At least one of these vertex processing flags must be specified when calling CreateDevice.
Try:
HRESULT hr = mpD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,mHWnd,D3DCREATE_MIXED_VERTEXPROCESSING,&md3dpp,&mpD3DDevice);
精彩评论