How to Render OpenGL on Android with C#?

Viewed 169

I have an existing application written in C# for .NET 6 that renders OpenGL with the lightweight OpenTK (v4) OpenGL bindings, which support .NET 5+, Open GL 3+, and OpenGL ES 2+.

According to the OpenTK FAQ:

OpenTK runs on Windows, Linux, and MacOS X.

(Older versions of OpenTK supported Android and iOS as well; current OpenTK might work on these, but it’s untested.)

I am excited by .NET 6's promise of one unified platform, but I have only seen cross-platform mobile projects that use Microsoft's new .NET Multi-platform App UI (.NET MAUI) framework. MAUI appears to be a web view shell that contains a Blazor Web App. I found the code for this shell in the src/Core/AndroidNative folder of the repository, but it seems very bloated for my purposes. I want to be able to access Android-specific functions without the bloat of Blazor and a web view. According to this blog post, Xamarin.Android might be the answer, but I am not sure how to introduce it into my existing project.

All I need is a simple shell that:

  1. Creates an Activity with a GLSurfaceView
  2. Obtains an OpenGL ES 2 context
  3. Runs my current C# code with that context

I would prefer the shell to be in C#, since introducing Java code would complicate my build process and fragment my code base.

  • How can I introduce the needed Android-specific code?
  • How will this change my build process?
  • I know that I need to write OpenGL ES-compatible shaders and that I probably need to change how I save files. What other changes will I need to make to my current code to ensure Android compatibility?
0 Answers
Related