Multiple Windows

Greetings Mono people!

I’m evaluating monogame for my company and would like to know if someone could point me towards the relevant documents/examples of creating more than 1 game window? I’ve experimented a bit on my own with using 2 Game instances and telling them to RunOneFrame() over and over but surely there are more idiomatic ways of doing this. I did the normal google/forum search but came up with very little.

Thanks,
Rob

https://msdn.microsoft.com/en-us/library/bb313965.aspx

I haven’t tested the, but I downloaded them for later use.

I knew i had seen Split Screen on RB’s…Found it!
http://rbwhitaker.wikidot.com/advanced-tutorials
This is a very good source of help: http://rbwhitaker.wikidot.com/xna-tutorials

I think he asked specifically for multiple windows, not split screen / multiple cameras.

Thanks for the replies,

I don’t think anyone answered my original question, so I borrowed a technique I’ve used on other libraries before to launch a few windows. Hopefully there isn’t something I’m missing that will bite me later.

public static class Program
    {
        private static BlockingCollection<Game1> _games = new BlockingCollection<Game1>();
        private static AutoResetEvent _stayAlive = new AutoResetEvent(false);

        [STAThread]
        static void Main()
        {
            SpawnWindow();
            SpawnWindow();

            // Keep the main UI thread alive until we decide we are done.
            _stayAlive.WaitOne();
        }

        static void SpawnWindow()
        {
            Task.Factory.StartNew(() =>
            {
                using (var game = new Game1())
                {
                    _games.Add(game);
                    game.Exiting += HandleGameExiting;
                    game.Run();
                }
            });
        }

        private static void HandleGameExiting(object sender, EventArgs e)
        {
            var game = sender as Game1;
            if (game != null)
            {
                Game1 gameToRemove;
                _games.TryTake(out gameToRemove);

                if(gameToRemove == null)
                {
                    Console.WriteLine("Failed to remove closing game.");
                    return;
                }

                // If no more windows exist lets close everything down.
                if (_games.Count == 0)
                    _stayAlive.Set();
            }
        }
    }

Are there any updates on this topic since 2015?

This is something I’m becoming more interested in and may need to employ soon,

Has anyone tried the above and tested this approach as ‘best’ practice?

What’s missing from the above is how to run routines, or send data to the different windows.

Thanks.

I’m curious as to WHY you would want two game windows running a game at the same time - is it for 2 monitors and 2 players where one screen would be on the left and the other on the right?

If this is the case, then maybe a server / client system would be better so the two players can sit at their own PCs and play, either next to each other, or at opposite ends of the world.

I built a casino platform using monogame for 2 monitors and I can tell you what I did.

I have extended desktop set up for top and bottom.

I then just initialize a frameless window that covers top and bottom. There doesn’t seem to be a performance hit in windowed mode these days,

This might be a slow way on older hardware, in which case you may try mutilple devices. But, the advantage of this approach is I can move items from top to bottom and vice versa with no loading.

Some casino platforms have a 3rd monitor also for the button panel and the principle is the same.

Im very much interested in this myself as i don’t know how to do it properly.

Especially when im thinking about a purely crossplatform solution for ui elements that can pop out of the game window itself into its own window such as any simple paint application could do.

As well as a save or load dialog that could pop out over top of the game window itself.

Though i never really spent much time actually trying to do this.


Id love to be able to just use eto winforms as the ui with monogame effortlessly for editors and stuff.

It’s simply the game would benefit from having two completely different views open. I could write the game for full 4k split into 4 and show loads of information but that’s completely over the top. To be able to ‘pop up’ a second window for a look at another path of the game while playing could be useful. Think of quickly picking up a map book while driving before we had SatNavs, that kind of thing. You want a quick view of the map without blocking out the road in front of you.

It isn’t a map, or have anything to do with a road, that’s just the best analogy I could think of.

Ah… interesting. Actually what you’re describing would be very cool for what I am currently doing.

I’ve been pondering this lately as well for the same reasons @willmotil described. Although WPFInterop has been dandy, some of my WPF controls (animation timeline and curve graphs specifically) butcher the daylights out of WPF even after obscene amounts optimization.

It’d be nice to just migrate over to an all/mostly IMGUI-paradigm, but those context menus and dialog windows always rear their heads and WPF is unsuitable for a minimal shell.

Unless anything has radically changed it should just be swapchains and multiple back-buffers for DX. Should be pretty doable in Winforms as WPFInterop does it across multiple controls and reference counting the underlying device. IIRC doing it in OpenGL was even easier, just changing the current context setup, buffers again, and go. I haven’t done any multi-window rendering since at least 2006 though, so WTF do I know about today - probably diddly.

Does suck that all of the examples I find are so incredibly overwrought that I haven’t had the patience to decipher them.

A good use for multiple windows are for realistic simulations where a lot of data has to be presented to the user. By using an interface library, most of the textual data can be represented easily enough.

However, how do you create second game window that relates to the primary game screen? For example, in military simulations such as war games one common attribute to such simulations is what is called a “jump window”, which displays the entire playing map in a secondary small window that allows the player to select an area on the map and immediately “jump” to it in the primary screen.

I would be very interested in seeing a technique for this using MonoGame. Maybe one of the MonoGame developers can answer this type of question…

I recall that @tomspilman did something with multiple windows a few years back, at least in the DirectX version. I’ll have to check if I remember this correctly and what the state of it may be.

Yeah, there’s at least still some code in there, but I don’t think it’s without issues in its current state.

I’ve done multiple windows in DirectX before. Maybe I should just dive right in and add some functionality.

Ah so this came up again in conversation is there a easy way to do this now or is there a tutorial somewere to get a popout window running i was told it can be done using swapchaintarget but i still have no idea how or what that even means

?