0

I'm trying to get into mobile game development with Xamarin; I am using OpenTK for rendering.
My plan is the following:
1. Make a shared library that is actually the game (and has all openTK code).
2. Make a a runnable project for iOS and Android that handles platform specific stuff (e.g. popping up alerts) and uses my shared library.

Is this possible with openTK? Does it have exactly the same API on iOS and on Android, just the linked library is different? If yes, how to avoid code duplication?

Filburt
  • 17,626
  • 12
  • 64
  • 115
sydd
  • 1,824
  • 2
  • 30
  • 54

1 Answers1

3

Your approach sounds very reasonable and will work with a little bit of effort.

The reason is that Xamarin.Android and Xamarin.iOS were forked from an alpha version of the library and have evolved slightly different APIs. Much of the OpenGL ES binding is identical, but some functions have annoying (and unnecessary) differences that you will need to #ifdef in your shared library.

The good news is that the Xamarin fork of OpenTK has now been open-sourced, so we are actively working towards a solution. I already have a private build of library that exposes an identical OpenGL ES API between Android and desktop platforms[1] and I'm working on fixing the differences between the iOS and Android versions.

You can follow the development of OpenTK in the official github repository.

[1] You can execute OpenGL ES code on the desktop using ANGLE or the ARB_ES2_compatibility and ARB_ES3_compatibility extensions. This makes OpenGL ES the first graphics API to work across all major platforms (Windows, Linux, Mac, Android, iOS - and hopefully WinPhone in the future.)

The Fiddler
  • 2,726
  • 22
  • 28
  • thanks! Do you plan to opensource your OpenGL library sometime? And as I need to rewrite stuff for iOS and Android wouldnt it be faster to use the native APIs? – sydd Feb 26 '14 at 10:53
  • OpenTK is open-source - the source code can be found in [opentk/opentk](https://github.com/opentk/opentk). Xamarin developed a closed-source fork based on OpenTK 0.9.9.3, which has now been open-sourced in [mono/opentk](https://github.com/mono/opentk). I am actively working to merge the two versions and will push my code to opentk/opentk as soon as it is ready. – The Fiddler Feb 26 '14 at 17:20
  • I'm not sure what you mean with "native APIs", OpenTK exposes the native APIs directly. AFAICT, the API differences between iOS and Android in mono/opentk stem from the use of different C OpenGL ES headers (Android and Apple versions, respectively.) opentk/opentk uses the Khronos registry directly, so it does not suffer from this issue. The difficulty in merging mono/opentk and opentk/opentk is making sure that existing applications do not break. – The Fiddler Feb 26 '14 at 17:21
  • @TheFiddler: Do you know where in the repo is the iOS/Android code? I downloaded the source tree and cannot find it anywhere... – Panda Pajama Jun 05 '14 at 09:58
  • @PandaPajama: The integrated version can be found at https://github.com/thefiddler/opentk/tree/merge2 (both Android and iOS are done, we are still missing a small number of enumerations to maintain API compatibility.) The Xamarin version is available at https://github.com/mono/opentk/tree/rodo-consolidate-opentk – The Fiddler Jun 05 '14 at 16:05
  • @TheFiddler: Thank you very much, by looking at the source I verified that what I'm doing is correct. You may want to consider offering functionality to resize the renderbuffer of `iPhoneOSGameView` without having to destroy and recreate the entire GL context. At the very least make `Renderbuffer` and `Framebuffer` have public setters. You can find a more thorough reasoning behind this at [this question](http://gamedev.stackexchange.com/questions/75965) I made in the GameDev SE. – Panda Pajama Jun 05 '14 at 16:25
  • @PandaPajama: you should direct feature reports to Xamarin, the Android and iOS ports have been implemented and are being maintained by them. – The Fiddler Jun 05 '14 at 20:03