创建 Direct3D9 设备的最少代码
这不适用于稳定的发布代码,我只需要从我的开发 PC 上的 HWND 获取在 C++ 应用程序中创建的窗口化 D3D9 设备来测试某些内容...它可以默认加载选项。
我试图从我拥有的旧 D3D8 类中将其组合在一起,但我收到了 D3DERR_INVALIDCALL。
基本上我现在有这个:
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.PresentationInterval = 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);
我认为一些 D3DPRESENT_PARAMETERS
选项可能是罪魁祸首 - 我不关心 z 缓冲区或模板或 AA 的后缓冲区,任何旧的普通设备都可以。
我是否将一些不兼容的标志复制粘贴在一起?
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.PresentationInterval = 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个问题是您需要设置一些行为标志。
来自 CreateDevice. 上的文档:
并来自 D3DCREATE 文档:
尝试:
1 problem is that you need to set some Behaviour flags.
From the docs on CreateDevice.:
And from the D3DCREATE docs:
Try: