Render one image to several window

Started by
4 comments, last by Stakhmich 8 years, 10 months ago

Hi.

I have a question. How i can draw a image on 2 or more windows, using directx11? The windows have different resolution.

How i do it for one window:

1) create swapchain

  1. 
    var swapChainDescription = new SwapChainDescription()
    {
        BufferCount = 1,
        ModeDescription = new ModeDescription()
        {
            Width = this.WidthImage,
            Height = this.HeightImage,
            Format = Format.R8G8B8A8_UNorm,
            RefreshRate = new Rational(60, 1)
        },
        IsWindowed = true,
        OutputHandle = handleWindow,
        SampleDescription = new SampleDescription(1, 0),
        SwapEffect = SwapEffect.Discard,
        Usage = Usage.RenderTargetOutput
    };
    

?2) CreateWithSwapChain


SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, featureLevels, swapChainDescription, out device, out _swapChain);

3) create render target


using (SharpDX.Direct2D1.Factory d2dFactory = new SharpDX.Direct2D1.Factory())
using (Surface surface = Texture2D.FromSwapChain<Texture2D>(_swapChain, 0).QueryInterface<Surface>())
{
   _renderTarget2D = new RenderTarget(d2dFactory, surface, new RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
}

4) render


_renderTarget2D.BeginDraw();
_renderTarget2D.Clear(Color.Black);
renderTarget2D.DrawBitmap(bitmap, new RectangleF(0, 0, 800, 600), 1f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
_renderTarget2D.EndDraw();
Advertisement

You create a swapchain for each window you want to render to. For this to work you do NOT use the CreateWithSwapChain convenience function, but create device and swapchains separately, see here

You create a swapchain for each window you want to render to. For this to work you do NOT use the CreateWithSwapChain convenience function, but create device and swapchains separately, see here

thank you for answer. I'm read your link and have question. If i create several swapchain, i create several rendertarget too? In this way my render will be:


_renderTarget2D_window1.BeginDraw();
_renderTarget2D_window1.Clear(Color.Black);
_renderTarget2D_window1.DrawBitmap(bitmap, new RectangleF(0, 0, 800, 600), 1f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
_renderTarget2D_window1.EndDraw();
_swapChain_window1.Present(0, PresentFlags.None);

_renderTarget2D_window2.BeginDraw();
_renderTarget2D_window2.Clear(Color.Black);
_renderTarget2D_window2.DrawBitmap(bitmap, new RectangleF(0, 0, 600, 500), 1f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
_renderTarget2D_window2.EndDraw();
_swapChain_window2.Present(0, PresentFlags.None);

?

It's a different Texture2D, so I guess you need to create different RenderTarget too.

You create a swapchain for each window you want to render to. For this to work you do NOT use the CreateWithSwapChain convenience function, but create device and swapchains separately, see here

thank you for answer. I'm read your link and have question. If i create several swapchain, i create several rendertarget too? In this way my render will be:


_renderTarget2D_window1.BeginDraw();
_renderTarget2D_window1.Clear(Color.Black);
_renderTarget2D_window1.DrawBitmap(bitmap, new RectangleF(0, 0, 800, 600), 1f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
_renderTarget2D_window1.EndDraw();
_swapChain_window1.Present(0, PresentFlags.None);

_renderTarget2D_window2.BeginDraw();
_renderTarget2D_window2.Clear(Color.Black);
_renderTarget2D_window2.DrawBitmap(bitmap, new RectangleF(0, 0, 600, 500), 1f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
_renderTarget2D_window2.EndDraw();
_swapChain_window2.Present(0, PresentFlags.None);

?

That depends on what you want to achieve the swap chain itself should have created a pair of render target and depth target buffers in each swapchain to serve as the front and back buffers of that chain.

If you do more offline rendering you might need more targets but that depends on whether the stuff being rendered to that target is view, projection dependent on the final rendering.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

You create a swapchain for each window you want to render to. For this to work you do NOT use the CreateWithSwapChain convenience function, but create device and swapchains separately, see here

thank you for answer. I'm read your link and have question. If i create several swapchain, i create several rendertarget too? In this way my render will be:


_renderTarget2D_window1.BeginDraw();
_renderTarget2D_window1.Clear(Color.Black);
_renderTarget2D_window1.DrawBitmap(bitmap, new RectangleF(0, 0, 800, 600), 1f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
_renderTarget2D_window1.EndDraw();
_swapChain_window1.Present(0, PresentFlags.None);

_renderTarget2D_window2.BeginDraw();
_renderTarget2D_window2.Clear(Color.Black);
_renderTarget2D_window2.DrawBitmap(bitmap, new RectangleF(0, 0, 600, 500), 1f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
_renderTarget2D_window2.EndDraw();
_swapChain_window2.Present(0, PresentFlags.None);

?

That depends on what you want to achieve the swap chain itself should have created a pair of render target and depth target buffers in each swapchain to serve as the front and back buffers of that chain.

If you do more offline rendering you might need more targets but that depends on whether the stuff being rendered to that target is view, projection dependent on the final rendering.

hi. thank for answer. but i don't understand what you say. can you explain using code? i need draw image on several window.

This topic is closed to new replies.

Advertisement