我正在通過一些簡單的DX教程工作,並且遇到了一個早期障礙。我正在使用舊筆記本電腦和新PC,因此我使用了d3d10_1.lib,它允許我使用9個功能集。但是,個人電腦確實支持DX11,所以沒有什麼問題。當創建DirectX 10設備和交換鏈時出現`E_FAIL` _com_error
因此,這裏是它失敗的功能:
bool DirectX9Renderer::Initialise(HWND* handle)
{
//window handle
hWnd = handle;
//get window dimensions
RECT rc;
GetClientRect(*hWnd, &rc);
UINT width = rc.right - rc.left;
UINT height = rc.bottom - rc.top;
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
//set buffer dimensions and format
swapChainDesc.BufferCount = 2;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;;
//set refresh rate
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
//sampling settings
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.SampleDesc.Count = 1;
//output window handle
swapChainDesc.OutputWindow = *hWnd;
swapChainDesc.Windowed = true;
HRESULT result = D3D10CreateDeviceAndSwapChain1(// this is line 57
NULL,
D3D10_DRIVER_TYPE_HARDWARE,
NULL,
D3D10_CREATE_DEVICE_SINGLETHREADED | D3D10_CREATE_DEVICE_DEBUG,
D3D10_FEATURE_LEVEL_9_1,
D3D10_1_SDK_VERSION,
&swapChainDesc,
&pSwapChain,
&pD3DDevice
);
if(FAILED(result))
{
return FatalError("D3D device creation failed");
}
// there's more stuff after this, but I don't get that far
}
所以調用D3D10CreateDeviceAndSwapChain1
失敗的,有用的少錯誤代碼E_FAIL
。
有一個在調試輸出太行:
First-chance exception at 0x770f56c4 in TileTest.exe: Microsoft C++ exception: _com_error at memory location 0x00b6e8d4..
我一直在使用D3D10_DRIVER_TYPE_REFERENCE
和不同D3D10_FEATURE_LEVEL_xx
值嘗試過,但似乎並沒有工作。
您是否打開了DirectX控制面板中的調試輸出?它應該給你一個更有用的調試花絮。 – Puppy 2012-03-31 14:57:41
對於10/11,我現在已經有了,但DirectX9選項卡上的選項全部變灰。 – Cylindric 2012-03-31 15:00:11
D3D10_1_SDK_VERSION應該是D3D10_SDK_VERSION作爲功能級別9 ... – zezba9000 2012-07-26 16:50:28