How to get the base window in MonoGame?

I am converting Gleed2D from XNA to MonoGame.

Gleed2D is a Windows Form application that creates an instance of XnaGame . Then the window created by the Game is hidden, and DeviceWindowHandle set to Canvas in the main form.

I know that a little sip; the code speaks for itself: here it is completely .
The corresponding bits are in the constructor:

  _drawSurface = mainForm.GetHandleToCanvas(); _graphics = new GraphicsDeviceManager( this ) { PreferredBackBufferWidth = 800, PreferredBackBufferHeight = 600 } ; _graphics.PreparingDeviceSettings += graphics_PreparingDeviceSettings; _winform = (Form)Form.FromHandle(Window.Handle); _winform.VisibleChanged += game1VisibleChanged; _winform.Size = new Size(10, 10); Mouse.WindowHandle = _drawSurface; Size pictureBoxSize = _mainForm.CanvasSize ; ResizeBackBuffer( pictureBoxSize.Width, pictureBoxSize.Height ) ; ... some other stuff.... void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e) { e.GraphicsDeviceInformation.PresentationParameters.DeviceWindowHandle = _drawSurface; } 

My question is: in XNA, Window.Handle can be added to Form . In MonoGame, it is implemented as OpenTK.GameWindow . How can I get into the actual window so that I can hide and / or resize it? . Alternative question: How can I create a MonoGame Game and say that the rendering surface belongs to another control?

+4
source share
2 answers

GameWindow OpenTK goes a long way before creating its own window. On this page you can see the built-in implementation: https://github.com/mono/opentk/blob/master/Source/OpenTK/Platform/Windows/WinGLNative.cs

My solution was to hack the OpenTK source code or ask in the OpenTK forums.

+1
source

Not sure if this helps, but in the MonoGame constructor, he initializes the GraphicsDeviceManager to a variable called _graphics. What kind of object can you get in the current GraphicsDevice Manager, which has the SetRenderTarget and SetRenderTargets methods. You can also get a handle in game windows using this.Window.Handle, where "this" is the current game object. Also, the Graphics device has a Present method, which allows you to transfer the source and target Rectangle, as well as any Windows pen. Good luck.

+1
source

Source: https://habr.com/ru/post/1439902/


All Articles