BlueMonkMN's picture

Menus in GameWindow

As I upgrade my project from DirectX to OpenGL using OpenTK, I am first trying out the possibility of deriving my window from GameWindow instead of embedding my converted display control in the main window. But that cuts out a number of things, the most important of which is menus. Is there any way to add menus to a GameWindow? Is the next best option to resort to using a GLControl on a form with menus? Will there be support for menus at some point if there isn't now?

I'm a little unclear on the portability of System.Windows.Forms; it appears that Mono has some form of System.Windows.Forms implementation for Win32 and X11. Does that mean GameForm could simply inherit from System.Windows.Forms.Form and retain its portability? If so, it seems like that would be the way to go to provide all the features one might expect from a "Form". I'd like to hear your comments on this and more specifically how I might best implement a menu on the main window.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

GameWindow cannot be used in Windows.Forms applications by design. Even if GameWindow had a Windows.Forms backend (relevant discussion), it still wouldn't be possible to embed a menu inside the GameWindow client area.

As you found out, the best option is to use GLControl. It is cross-platform (as of Mono 1.2.7 it will work on Windows, X11, but not yet OSX). The drawback is that:

  1. GLControl is quite low-level, and is based on an event-driven paradigm (no game-loop or timing information unless you add that manually).
  2. You cannot select a different color depth than that of the containing window. I.e., if the screen has a 16bit color depth, you cannot select a 32bit one for your opengl context (this usually isn't a problem, as most computers use 32bit depths these days).

To create a game loop you'll need to hook the Application.Idle event and loop inside that:

while (GLControl.IsIdle)
{
    // Perform rendering
}

Timing information can be gathered by using the System.Diagnostics.Stopwatch class. Last, to make the application go fullscreen you'll have to disable the borders and maximize the containing Form.