I am just wondering if DirectX 11 allows me to set an area to render to instead of rendering the whole window. Thanks a lot!
2 Answers
Yes, use ID3D11DeviceContext::RSSetViewports
and the D3D11_VIEWPORT
structure. Setting the TopLeftX
, TopLeftY
, Width
, and Height
members to portions of the window dimensions will cause the render target to be drawn into that section of the back buffer.
It's worth noting that this will not prevent DXGI from clearing the whole application window if you create a swap chain against your application's main window handle. If you need to blend Win32 controls and Direct3D content, create a child window specifically for the Direct3D content, create a swap chain against that window, and add the child window to the main application window.

- 1,794
- 9
- 20
-
The ``RSSetViewports`` sets the pixel locations that map to (-1,-1) to (1,1) in normalized coordinates, so this is the correct solution. ``RSSetScissors`` sets the pixel location of the 'clipping' or 'scissor' rectangles that is used to prevent drawing outside a particular rectangle. The default scissors for DX11 are the same as the viewport, but you can use specific rectangles via the ``D3D11_RASTERIZER_DESC.ScissorEnable`` state. With DX12, you have to explicitly set the 'clipping' using ``RSSetScissorRects`` in all cases. – Chuck Walbourn Nov 14 '18 at 00:41
-
So you mean by setting the Rect of scissors I can just render to a specific rectangle area? – stephen Nov 14 '18 at 09:52
Finally got it, so to render to a specific rectangle area of your main window application. You first need to create a second childhWnd to let DirectX render to, and then attach this childhWnd to your main hWnd using setParent() to display only one window in total.

- 71
- 8