0

由于某种原因,我似乎无法初始化我的RenderTargetView(它保持NULL),这会导致访问冲突。

这是应该初始化 RenderTargetView 的行:

hr = g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_pRenderTargetView);

pBackBuffer是后台缓冲区,它得到一个值,它不是NULL。但是,rendertagetview 会NULL在整个过程中保持不变。知道为什么吗?

4

2 回答 2

2

In order to trace the DirectX11 errors, you'd better to create the D3D11 device with the debug layer, it will print the error message to output window in Visual Studio when you launch your app.

    // Create device and swap chain
    HRESULT hr;
    UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#if defined( DEBUG ) || defined( _DEBUG )
    flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif 

    // Create device and swap chain
    D3D_FEATURE_LEVEL FeatureLevelsRequested = D3D_FEATURE_LEVEL_11_0; // Use d3d11
    UINT              numLevelsRequested = 1; // Number of levels 
    D3D_FEATURE_LEVEL FeatureLevelsSupported;

    if (FAILED (hr = D3D11CreateDeviceAndSwapChain( NULL, 
        D3D_DRIVER_TYPE_HARDWARE,
        NULL,
        0,
        &FeatureLevelsRequested,
        numLevelsRequested,
        D3D11_SDK_VERSION,
        &sd_, 
        &swap_chain_,
        &d3ddevice_,
        &FeatureLevelsSupported,
        &immediate_context_)))
    {
        MessageBox(hWnd, L"Create device and swap chain failed!", L"Error", 0);
    }
于 2013-08-30T12:14:51.483 回答
-1

我认为您无法创建渲染目标视图,因为第二个参数为 NULL:

HRESULT CreateRenderTargetView
(
  [in]   ID3D11Resource *pResource,
  [in]   const D3D11_RENDER_TARGET_VIEW_DESC *pDesc, <== You need to pass in a valid description
  [out]  ID3D11RenderTargetView **ppRTView
);

您可以将其初始化为以下内容:

D3D11_RENDER_TARGET_VIEW_DESC desc = {0};
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
于 2013-09-10T08:12:13.287 回答