如果我的怀疑是愚蠢或愚蠢的,请原谅我。我对 DirectX 编程完全陌生。只需具备 C++ 知识(非常基本的 COM 知识)。
下面的代码示例来自 MSDN创建 D3D 设备,它解释了如何从头开始创建 D3D 设备。
我的怀疑是:
这里函数“ pD3D->CreateDeviceEx() ”接受一个参数HWND hwnd。如果我尝试从需要使用 D3D 设备接口中的某些功能的 commadline C++ win32 应用程序创建 D3D 设备怎么办?如何获得 HWND 字段。在这种情况下如何创建 D3D 设备。请详细解释。
HRESULT InitD3D9Ex( /* IN */ HWND hWnd, /* OUT */ IDirect3DDevice9Ex ** ppD3DDevice )
{
HRESULT hr = E_FAIL;
IDirect3D9Ex * pD3D = NULL;
IDirect3DDevice9Ex * pDevice = NULL;
if(ppD3DDevice == NULL)
{
return hr;
}
// Create the D3D object, which is needed to create the D3DDevice.
if(FAILED(hr = Direct3DCreate9Ex( D3D_SDK_VERSION, &pD3D )))
{
*ppD3DDevice = NULL;
return hr;
}
// Set up the structure used to create the D3DDevice.
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
// Create the Direct3D device.
if( FAILED( hr = pD3D->CreateDeviceEx( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, NULL, &pDevice ) ) )
{
*ppD3DDevice = NULL;
return hr;
}
// Device state would normally be set here
*ppD3DDevice = pDevice;
return hr;
}