【发布时间】:2014-03-23 05:29:30
【问题描述】:
我正在学习一些简单的 DX 教程,但遇到了早期的障碍。我正在使用旧笔记本电脑和新 PC,所以我使用 d3d10_1.lib,它可以让我使用 9 个功能集。但是,PC 确实支持到 DX11,所以那里应该没有问题。
所以这是失败的函数:
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 帮助不大。
Debug 输出中也有一行:
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 控制面板中打开了调试输出?它应该给你一个更有用的调试喷射。
-
我现在有,10/11,但 DirectX9 选项卡上的选项都是灰色的。
-
D3D10_1_SDK_VERSION 应该是 D3D10_SDK_VERSION 作为功能级别 9...
-
该类名为 DirectX9Renderer 但您创建的是 D3D10 设备? ;-)