DirectX11 2 window rendering

后端 未结 1 1756
失恋的感觉
失恋的感觉 2021-02-06 09:09

How can I render my objects with DirectX into 2 separated windows?

相关标签:
1条回答
  • 2021-02-06 09:25

    You need to create one SwapChain and RenderTargetView for every window.

    1 if you created your device via CreateDeviceAndSwapChain you need to obtain IDXGIFactory first

    IDXGIDevice * device;
    d3ddevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&device);
    
    IDXGIAdapter * adapter;
    device->GetParent(__uuidof(IDXGIAdapter), (void**)&adapter);
    
    IDXGIFactory * factory;
    adapter->GetParent(__uuidof(DDXGIFactory), (void**)&factory);
    

    With DXGIFactory you can create additional swapchain for new window

    factory->CreateSwapChain(g_pd3dDevice, &sd, &g_pSwapChain2);
    

    then create a render target view

    ID3D11Texture2D* pBackBuffer = NULL;
    hr = g_pSwapChain2->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer );
    if( FAILED( hr ) )
        return hr;
    
    hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView );
    pBackBuffer->Release();
    if( FAILED( hr ) )
        return hr;
    

    And finally just set your render target(s) and Draw something!

    g_immediateContext->OMSetRenderTargets(1, &g_RenderTargetView, NULL);
    ....
    

    I hope this has been helpful.

    Best regards Quest :)

    0 讨论(0)
提交回复
热议问题