Advertisement Jump to content

DX11 How to render to multiple windows at once?

Recommended Posts

I have some code (not written by me) that is creating a window to draw stuff into using these:

CreateDXGIFactory1 to create an IDXGIFactory1

dxgi_factory->CreateSwapChain to create an IDXGISwapChain

D3D11CreateDevice to create an ID3D11Device and an ID3D11DeviceContext

Other code (that I dont quite understand) that creates various IDXGIAdapter1 and IDXGIOutput instances

Still other code (that I dont quite understand) that is creating some ID3D11RenderTargetView and ID3D11DepthStencilView instances and is doing something with those as well (possibly loading them into the graphics context somewhere although I cant quite see where)

What I want to do is to create a second window and draw stuff to that as well as to the main window (all drawing would happen on the one thread with all the drawing to the sub-window happening in one block and outside of any rendering being done to the main window). Do I need to create a second IDXGISwapChain for my new window? Do I need to create a second ID3D11Device or different IDXGIAdapter1 and IDXGIOutput interfaces? How do I tell Direct3D which window I want to render to? Are there particular d3d11 functions I should be looking for that are involved in this?

I am good with Direct3D9 but this is the first time I am working with Direct3D11 (and the guy who wrote the code has left our team so I cant ask him for help :)


Share this post

Link to post
Share on other sites

If I remember this correctly it was like this:

  • You have to create a swap chain for each window (using hwnd)
  • For each swap chain get a texture for it, create a render target for it
  • Now, to render into window - just set the render target view for specific swap chain (specific for window in which you want to draw), calling Present for swap chain will display backbuffer contents in that window

Share this post

Link to post
Share on other sites

What Vilem Otte said ^^^

There's no need to create multiple devices or adapters, that will just make your life more difficult. You just need multiple swap chains.

Share this post

Link to post
Share on other sites

Ok so I need to create a second IDXGISwapChain pointing at my second window, obtain the ID3D11Texture2D from that swap chain via GetBuffer, hook that up to an ID3D11RenderTargetView and then call OMSetRenderTargets with that new render target view on my ID3D11DeviceContext before I render stuff?


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!