Creating multiple windows?

I wrote the original code to do this in MG… lets see what i can remember…

Is there any way to display two windows and keep both of them active at the same time?

You just need to create a second GameWindow

var otherWindow = GameWindow.Create(myGame, sizeX, sizeY);

You then have one Game instance and two GameWindow instances.

You can use the otherWindow.Handle to get the HWND and do other things like place Winforms content or other things. If you want to display graphics on it you need to use the SwapChainRenderTarget class.

            var swapChain = new SwapChainRenderTarget(myGame.GraphicsDevice,
                                                  otherWindow.Handle,
                                                  otherWindow.ClientBounds.Width,
                                                  otherWindow.ClientBounds.Height,
                                                  false,
                                                  SurfaceFormat.Color,
                                                  DepthFormat.Depth24Stencil8,
                                                  1,
                                                  RenderTargetUsage.PlatformContents,
                                                  PresentInterval.Default);

Then in your main Game.Draw method you need to update the second window too…

            device.SetRenderTarget(swapChain);

            // your drawing code for the second window.

            swapChain.Present();

Note i don’t think we ever got the SwapChainRenderTarget working on anything other than Windows under DirectX… but that could be fixed if someone contributed some code.

Hope this helps you get started!

4 Likes