Petardo's picture

Creating Context manually in MAC OS fails

I have an gamethat uses OpenTK and works perfect in Windows via MONO. But the same application in MAC OS does not work. The Window is white. There are not exceptions and warning, and all the logic code runs flawesly.

The game is not a GameWindow, it is a common MONO Form, and the Graphics context is created manually:

if (OpenTK.Configuration.RunningOnMacOS)
            {
                Console.WriteLine("MACOS");
                _WindowInfo = OpenTK.Platform.Utilities.CreateMacOSCarbonWindowInfo(_Control.Handle, false, false);
            }            
 
            Console.WriteLine("Window Info:" + _WindowInfo.Handle.ToString());

The problem is that in Windows, the MONO Form Handle of the window is the real Windows handle, but in Mac it must be another thing. And the result is that the window is all white.

If Instead the Form.Handle, I create a NativeWindow and pass that handle then all is right (but it is no more my form with my functions and logic:

            NativeWindow nw = new NativeWindow(600, 600, "TEST", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default);
            nw.Visible = true;
            _WindowInfo = nw.WindowInfo;
 
            _Device = new OpenTK.Graphics.GraphicsContext(
                GraphicsMode.Default
                , _WindowInfo, 1,0, GraphicsContextFlags.Default);

It is a big problem for me to change from my Windows.Forms to GameWindow. Is there something I can do? I am sure that the problem is the Mono Handle in the MAC version.

Thanks!


Comments

Comment viewing options

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

Instead of creating a context directly, you should try to construct a GLControl and attach it to your Form. GLControl is simply a plain WinForms Control + a GraphicsContext that hides the complexity of context construction on different platforms.

Take a look at CarbonGLControl.cs. This is what you need to do if you are using GraphicsContext directly.

Petardo's picture

Thank you, I am going to try it, and I will post the result.