Fun Lunchbreak Experiment: libgdx + .NET (C#)

Today i spent my lunch break on trying out IKVM, which is a JVM ontop of .NET and a way to get interoperability between Java Bytecode & the CLI. I was interested in the later as i wanted to try out whether i could use libgdx from C#. Well, that wasn’t all that hard 🙂

Download the latest IKVM binaries, the latest libgdx nightlies and away you go with the following command line:

You’ll end up with an assembly called gdx-cli.dll. Create a new C# project in Visual Studio, reference the gdx-cli.dll as well as the IKVM and OpenJDK assemblies in the IKVM bin/ folder. Copy the ikvm-native-win32-x86.dll and ikvm-native-win32-x64.dll files to your project and make sure they are copied to the output folder on every build (or when they change). Here’s a screenshot

I only played around with this for 15 minutes, but all the things i tested work. Note that it uses LWJGL as the backend, so you can’t integrate it with a standard Windows Forms/WPF application. On the other hand you can now use libgdx in C# if you want to work with that instead. Compatibility with Android will be lost of course, but you can still stay cross-platform with Mono.

At some point i’ll probably also host .NET nightlies.

hint: if someone gives me a Mac i can try to make this work on IOS 😀

8 thoughts on “Fun Lunchbreak Experiment: libgdx + .NET (C#)

  1. Awesome ! So then, it dont needs java, right ? MonoTouch will get some fear :p
    I now understand why a lot of people wanted “Mr i created MONO” dead or alive !

  2. Daniel: The core classes of libgdx (Mesh, Texture etc.) rely heavily on JNI stuff, so that obviously works 🙂
    Syl: you can write your app in C# for the desktop if you so wish. For Monotouch i’d have to do a few things that take quite a bit longer than 15 minutes.

  3. No libgdx on iOS is probably my biggest reason for not investigating iOS development (cost of buying a Mac to develop on and being scared of Obj-C syntax are tied for second place). If you get that to work, then I’ll have one less excuse 🙂

  4. Folks, I have tried the whole day to make it work on a mac.
    For some reason I can get the ikvm-native.dll to be used in the mono project.
    With all the debugs of the world turned on, managed to track this down:

    Mono-INFO: DllImport attempting to load: 'ikvm-native'.
    Mono-INFO: DllImport loading location: 'libikvm-native.dylib'.
    Mono-INFO: DllImport error loading library: 'dlopen(libikvm-native.dylib, 9): no suitable image found. Did find:
    libikvm-native.dylib: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00
    /usr/lib/libikvm-native.dylib: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00'.

    Nowhere in the world I could find a native mac library (libikvm-native.dylib). It can’t be added to the references because the dll is a native windows library, not a .net one.
    There are fragments on the net about people using it on mac, but for the world I couldn’t find one.

    As for monotouch, that would be quite straight forward and there is very little Obj-C involved in programming for the iPhone if you don’t want to.
    C++ all the way.

  5. I have sorted out the native lib issue!

    Exception in thread "LWJGL Application" java.lang.IllegalStateException: Function is not supported
    at org.lwjgl.BufferChecks.checkFunctionAddress(
    at org.lwjgl.opengl.GL11.glGetString(
    at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.initiateGLInstances(
    at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setupDisplay(
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.access$000(
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$

    Exciting result…stay tuned.

  6. Wouldn’t this allow a Windows Phone 8 and Playstation Mobile Backend? Or at least Playstation Mobile which afair uses OpenGL.

  7. Needed a slightly different step to generate on Windows 7, running from the root directory of the nightly. Replace the path for IKVM_HOME with the path to the IKVM bin/ directory, I used forward slashes to separate:
    set IKVM_HOME=C:/whatever/ikvm/bin && “%IKVM_HOME%ikvmc” -platform:x86 -target:library -out:gdx-cli.dll gdx.jar gdx-natives.jar gdx-backend-lwjgl.jar gdx-backend-lwjgl-natives.jar

Leave a Reply

Your email address will not be published.