🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Wrap macOS window using .Net Core 3.0

Started by
4 comments, last by BlackJoker 4 years, 9 months ago

Hi,

Sorry if this is not correct branch, but I would like to ask how to wrap macOS window using .Net core 3.0

Which frameworks/dylibs I need to reference and which functions to p/invoke to make minimum framework for running window on macOS.

I dont want to use mono or Xamarin. I want to do it using pure .Net core 3.0

Didnt find any tutorial for this yet.

Could someone help me with this or at least point me to the right direction?

 

Advertisement

376 views and zero replies? Does nobody really know how to accomplish this?

It's not easy, take a look at how SDL works. The difficulty is that MacOS hides the main thread event loop in [NSApplication run], so it is pretty intrusive in your design. In my C++ wrapper, main() calls [NSApplication run], which blocks for the entire lifetime of the program, then gets a callback [applicationDidFinishLaunching], where I spawn a second thread which functions as the main thread of my engine, while the first thread handles event processing. You must also be very careful about what threads you are using. Most Cocoa windows/views require to be used from the main thread only, other threads must use [performSelectorOnMainThread] to run window/view methods on the main thread.

I would use this approach: write a wrapper similar to SDL with a C interface, then pinvoke that library from your managed language. Good luck, this is not an easy task and can take a long time to get it working correctly (my wrapper is 12 years old and still has some problems). You're probably better off finding an existing library that does this for you.

Do you have some code examples that I could see and understand how its all works?

OK, I managed to deal with it by writing custom macOS framework with C functions and callbacks and then p/invoke it in my engine on C# side. It was not so hard. Hopefully .Net core 3 allow to marshal macOS frameworks and dylibs.

This topic is closed to new replies.

Advertisement