本文介绍了DirectX11 2窗口渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用DirectX将对象渲染到2个单独的窗口中?
How can I render my objects with DirectX into 2 separated windows?
推荐答案
您需要创建一个SwapChain和RenderTargetView每个窗口。
You need to create one SwapChain and RenderTargetView for every window.
1如果您通过CreateDeviceAndSwapChain创建设备,则需要先获取IDXGIFactory
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);
使用DXGIFactory,您可以为新窗口创建其他交换链
With DXGIFactory you can create additional swapchain for new window
factory->CreateSwapChain(g_pd3dDevice, &sd, &g_pSwapChain2);
然后创建渲染目标视图
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);
....
我希望这会有所帮助。
最诚挚的问候:)
这篇关于DirectX11 2窗口渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!