DaWanderer's picture

Launching an OpenTK game on the Mac

Hello all,

I'm porting my OpenTK-based game from Linux to the Mac (with surprisingly few difficulties!) and have a quick question on how to properly launch my "sub-games". My main application is built in GTK# and houses some common setup routines for all the sub-games. When the user has everything set up, they select a game from the list, click Play, and the program runs the corresponding .NET executable with the appropriate command-line arguments (using Process.Run). All sub-games are just regular GameWindow.Run() applications that use OpenGL.

This works perfectly on Linux, but has some strange behavior on the Mac. If the game is set to be full-screen, it works just fine. If not, though, the game is displayed and runs properly, but the game window cannot receive any input (keyboard/mouse/focus); it just sits behind other windows and ignores me! The same thing happens if I launch the game executable directly from the Mac terminal ("mono game.exe ..."). Once again, setting full-screen remedies the problem (unfortunately, windowed-mode is one of my user requirements).

Here are the things I've tried to remedy this:

  • Repackage the game executables as Mac app bundles - this solves my windowed-mode problem, but I can't pass in command-line arguments anymore (thank you, Apple) via Process.Run
  • Reference the game executables in the main GTK# program and invoke the game's Main method directly like the OpenTK examples launcher - works beautifully, but crashes the main program immediately when the game exits regardless of whether it is launched in a try/catch block, in its own thread, or even in its own AppDomain (this appears to be an issue in GTK# from what I can gather in the stacktrace)

If anyone has some advice, it would be much appreciated!



Comment viewing options

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

Have you tried packaging the whole thing as a single app bundle? Run macpack to create an app bundle for your launcher, and then place all the game exe's in the MyGame.app/Contents/MacOS/Resources folder.

DaWanderer's picture


I've tried it both ways: running the GTK# executable from the command line and using macpack (with the -m:2 option) to bundle up everything (including the game executables as resources). I've analyzed the script that macpack generates to try and figure out if it's making the "magic" happen or if its simply the fact that OS X is recognizing the .app as a GUI application instead of a command-line program. It appears to be OS X alone, since the same windowing problem crops up if I first bundle the game executable and then directly run the generated script (something like "./MyGame.app/Contents/MacOS/MyGame --arg1 --arg2").

Is there some special environment variable or flag that needs to get passed to Mono to get OS X to recognize it as a real GUI application?

kanato's picture

Yeah, unfortunately it appears that OSX has special facilities for recognizing apps, and the only way to get that to work properly and reliably is to bundle your app.

Have you tried staring your games by executing a command like "open MyGame.app"? This will work to make the app recognized by OSX as a desktop application, but I don't know if command line parameters can be passed.

DaWanderer's picture

Oddly enough, the "open" command-line utility doesn't support passing in command-line arguments. It seems the "correct" way of doing it is to actually modify the info.plist file inside the application bundle, but this is an awful solution (in my opinion), especially if multiple instances of a game need to run with different arguments.

Thanks for your suggestions, kanato. I'll keep hacking away and hopefully find a solution.