Reputation: 25187
I'd like to render something at one resolution, but display it in a window at another resolution (e.g. render the scene at 640x480 and stretch it to a 1024x768 window).
Simply resizing the window after creation allows this to work - however, the image is filtered using nearest-neighbor. Is there a way to change the filtering algorithm to e.g. bilinear?
Upvotes: 0
Views: 611
Reputation: 41117
There's basically three approaches to this:
One approach is to use a Direct3D backbuffer that is always 640 x 480, but allow the DXGI Present
to handle the scaling to some other window size (1024 x 768). In Direct3D 11.1 you can achieve this using DXGI_SWAP_CHAIN_DESC1.Scaling
and set it DXGI_SCALING_STRETCH
. On Windows phone 8 or Windows 10, you can use DXGI_SCALING_ASPECT_RATIO_STRETCH
as well. In this case you don't have control over how the filtering is achieved, but it is mostly automatic.
DXGI_SCALING_ASPECT_RATIO_STRETCH
only works with CoreWindow and DirectComposition swapchains usingCreateSwapChainForCoreWindow
orCreateSwapChainForComposition
(i.e. not classic Win32 windows usingCreateSwapChainForHwnd
). To know where in the output window the aspect-ratio preserved image is actually placed, see the code for DirectX Tool Kit's Viewport::ComputeDisplayArea
The other approach is to resize your backbuffer to match the output window, but then use texturing on a 'full-screen quad' to achieve the stretch. In this case, you have more direct control over the filtering used. See DirectX Tool Kit's SpriteBatch and D3D11_FILTER.
Finally, you can do the resizing of the original image on the CPU. Here you have the most flexibility and control to do the resize, but the performance will be significantly slower. You can do a Resize with WIC or DirectXTex as well.
Upvotes: 3