I've been attempting to make an OpenGL ES2.0 (Using OpenTK) renderer for Android that I can also use on iOS. To do this I'm trying to use the latest release of OpenTK on a Xamarin Android project. Only I've hit a problem when trying to use the GL.Clear(...) method. When the code tries to call that method I get a MissingMethodException.
The code seems quite happy when calling:
GL.ClearColor(1.0f, 0.0f, 0.0f, 1.0f);
But then it throws the exception on:
GL.Clear(ClearBufferMask.ColorBufferBit);
The above two function calls are from the OpenTK library, but I also have access to the OpenGL ES20 library that comes with Mono.Android (But I would like to use the OpenTK library so I can build a cross platform renderer). I don't have any problems when using the Mono.Android GL calls but what is interesting is that the program functions properly when I mix calls from the different libraries, like so:
OpenTK.Graphics.ES20.GL.ClearColor(1.0f, 0.0f, 0.0f, 1.0f);
Android.OpenGL.ES20.Clear(GLES20.GlColorBufferBit);
If no one can provide a solution to my problem I'd still like to know what's actually going on here.
Edit: I forgot to mention that I made a test project for desktop using the OpenTK ES2.0 library and the call to GL.Clear(...) works just fine there. Don't know if that helps.
You are hitting this issue: https://bugzilla.xamarin.com/show_bug.cgi?id=18575
In short, Xamarin.Android bundles its own version of OpenTK inside its core library that overrides your reference to OpenTK.dll. Your code is building against OpenTK.dll v1.1.x.y but is trying to run with the Xamarin version of OpenTK.dll v1.0.x.y, which is not ABI compatible.
The solution is the following branch of OpenTK that adds official support for Xamarin.Android and Xamarin.iOS: https://github.com/opentk/opentk/pull/142. This has been tested and is known to work correctly on all platforms (desktop, Android, iOS). If you encounter any issues, please post a bug report.