1

几天前我开始学习 c++ 和 directx11。

所以我不是这方面的专家。.请好心解释一下为什么会发生...我正确地创建了窗口和东西。即使交换链初始化也按预期进行。但我被困在渲染目标视图初始化...

当我调试时,它会给我以下错误

    dxgiDevice  0x008959ac <Information not available, no symbols loaded for d3d11.dll> IDXGIDevice 

我不知道我在这里做错了什么。我已经包含了静态库(dxgi.lib d3dx11.lib d3d11.lib dxguid.lib D3DCompiler.lib)并正确链接了头文件和库。

错误似乎来自这一行

        SwapChain->GetBuffer(0,__uuidof(ID3D11Texture2D),(LPVOID*)(&backBuffer));

我不知道该怎么办..这让我真的很沮丧。

请在这里帮助我..我将非常感谢

谢谢

这是完整的代码

#include <Windows.h>
#include <windowsx.h>
#include <D3D11.h>

#include <D3DX11.h>
#include <D3DX10.h>

using namespace std;




LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

bool InitWindowClass(HINSTANCE hinst,int shw,HWND * _hwnd,WNDCLASSEX * exClass);

RECT windowWidth = {0,0, 1000,768};
int WINAPI WinMain(HINSTANCE inst,HINSTANCE previnst,LPSTR cmdLine,int show)
{


    // Window Params
    HWND hwnd;
    WNDCLASSEX exClass;
    MSG msg;

    // Iniitaliztion
    SecureZeroMemory(&hwnd,sizeof(HWND));
    SecureZeroMemory(&exClass,sizeof(exClass));
    SecureZeroMemory(&msg,sizeof(MSG));


    // Directx  11 Functionalities

         #pragma region Create the device
            D3D_FEATURE_LEVEL featureLevels[4] = {D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1  , D3D_FEATURE_LEVEL_10_0 ,  D3D_FEATURE_LEVEL_9_1};
            D3D_FEATURE_LEVEL feature_LEVEL;
            ID3D11Device * d3dDevice = 0;
            ID3D11DeviceContext * d3dContext = 0;


            HRESULT hr = D3D11CreateDevice(0,
                                           D3D_DRIVER_TYPE_HARDWARE,
                                           0,
                                           0,       // No flags 
                                           featureLevels,4,
                                           D3D11_SDK_VERSION,
                                           &d3dDevice,
                                           &feature_LEVEL,&d3dContext);
            if(FAILED(hr))
            {
                MessageBox(hwnd,L"FAiled TO CREATE DEVICE",L"ERROR",0);
            }

      #pragma endregion

         #pragma region Multisampling
            UINT multisampleQuality;
            d3dDevice->CheckMultisampleQualityLevels(DXGI_FORMAT_B8G8R8A8_UNORM,4,&multisampleQuality);


        #pragma endregion

        #pragma region DescribeSwapChain
            DXGI_SWAP_CHAIN_DESC swapDesc;

            // Allocate Mommory
             SecureZeroMemory(&swapDesc,sizeof(DXGI_SWAP_CHAIN_DESC));

            swapDesc.BufferDesc.Width =  1000;
            swapDesc.BufferDesc.Height = 768;
            swapDesc.BufferDesc.RefreshRate.Numerator= 60;
            swapDesc.BufferDesc.RefreshRate.Denominator = 1;
            swapDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
            swapDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
            swapDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

            //MSAA 
            swapDesc.SampleDesc.Count = 4;
            swapDesc.SampleDesc.Quality = multisampleQuality;

            //BackBuffer
            swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
            swapDesc.BufferCount = 1;

            swapDesc.OutputWindow = hwnd;
            swapDesc.Windowed = true;

            swapDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
            swapDesc.Flags = 0;


        #pragma endregion

        #pragma region CreateSwapChain

            #pragma region Obtain DXGIFactory

            // DXGIFactory >> DXGIAdaptor >> DXGIDevice

            // Get the DXGI device
            IDXGIDevice * dxgiDevice = 0;
            d3dDevice->QueryInterface(__uuidof(IDXGIDevice),(void**)&dxgiDevice);

            // Obtain DXGIAdaptor
            IDXGIAdapter * dxgiAdaptor = 0;
            dxgiDevice->GetParent(__uuidof(IDXGIAdapter),(void**)&dxgiAdaptor);

            IDXGIFactory * dxgiFactory = 0;
            dxgiAdaptor->GetParent(__uuidof(IDXGIFactory),(void**)&dxgiFactory);
            #pragma endregion

            IDXGISwapChain * SwapChain = 0;
            SecureZeroMemory(&SwapChain,sizeof(IDXGISwapChain));
            dxgiFactory->CreateSwapChain(d3dDevice,&swapDesc,&SwapChain);
            dxgiAdaptor->Release();
            dxgiDevice->Release();
            dxgiFactory->Release();

        #pragma endregion

        #pragma region Create Render Target View

            ID3D11RenderTargetView * RenderTarget = 0;
            ID3D11Texture2D * backBuffer = 0;

            SwapChain->GetBuffer(0,__uuidof(ID3D11Texture2D),(LPVOID*)(&backBuffer));
            d3dDevice->CreateRenderTargetView(backBuffer,NULL,&RenderTarget);
            backBuffer->Release();



        #pragma endregion




    if(InitWindowClass(inst,show,&hwnd,&exClass))
    {
            while(msg.message != WM_QUIT)
        {
            if(PeekMessage(&msg,hwnd,0,0,PM_REMOVE))
          {
              TranslateMessage(&msg);
              DispatchMessage(&msg);
            }else{

             // Update Sequences
            }
        }
    }

    return msg.wParam;

}

// Initialize and show the Window
bool InitWindowClass(HINSTANCE hinst,int shw,HWND * _hwnd,WNDCLASSEX * exClass)
{
     HWND  hwnd2 ;
     SecureZeroMemory(&hwnd2,sizeof(HWND));
     exClass->cbSize = sizeof(WNDCLASSEX);
     exClass->hCursor = LoadCursor(0,IDC_ARROW);
     exClass->hInstance = hinst;
     exClass->lpfnWndProc = WndProc;
     exClass->lpszClassName = L"DX_Test";
     exClass->lpszMenuName = L"Test";
     exClass->hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
     RegisterClassEx(exClass);


     AdjustWindowRect(&windowWidth,WS_OVERLAPPEDWINDOW,false);

     (*_hwnd) = CreateWindowEx(0,L"DX_Test",L"Test",WS_OVERLAPPEDWINDOW,500,200,windowWidth.left,windowWidth.top,NULL,NULL,hinst,0);

     ShowWindow((*_hwnd),shw);


     UpdateWindow(*_hwnd);

     return true;

}



// Message Loop
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
    switch (msg)
    {
    case WM_LBUTTONDBLCLK:
        MessageBox(hwnd,L"Prressed Button 1",L"Mouse 1",0);
        return 0;
        break;
     case WM_DESTROY:
         PostQuitMessage(0);
         return 0;
        break;
    case WM_KEYDOWN:
            if(wparam == VK_ESCAPE)
            DestroyWindow(hwnd);
            return 0;

    }

    return DefWindowProc(hwnd,msg,wparam,lparam);
}
4

1 回答 1

1

您正在谈论的“错误消息”来自 VS 调试器:它告诉您的是它没有任何 d3d11.dll 的调试符号。换句话说,这不是你的问题 - 这是一个红鲱鱼。

要解决此问题,您需要进行一些错误检查。IDXGISwapChain::GetBuffer返回 a HRESULT,您应该检查它是否有错误,例如:

HRESULT res = SwapChain->GetBuffer(...);
if (!SUCCEEDED(res))
{
    std::cerr << "Error getting buffer from swap chain: " << std::hex << res << std::endl;
}

然后,您可以根据这组文档中的值检查结果,以具体找出错误所在。

请注意,您可能也应该对许多其他 DirectX 调用执行类似的操作。

于 2014-12-20T09:59:59.667 回答