A better SDL wrapper for Java

I’ve been using SDL for a long time in C++, and I’ve toyed sdljava, which are rather complete bindings for SDL for Java. While the bindings are rather complete, they where created using SWIG, which is a (great) code generator, but still the result is that these bindings are kinda clunky and rather bloated. For example, there are many intermediate classes that are prefixed with SWIG_. This motivated me to write my own, which I call SDLbits.

While it’s not as complete as sdljava, it’s much smaller and is hand written. While the idea of hand-writing lots of C wrapper code seems daunting, it was not much more than writing a class with many native methods, running javah and writing some simple glue. Here is quick rundown of what is supported:

  • Video functions including support for OpenGL bindings. We also provide our own very small GL bindings, GLbits.
  • Audio functions with support for callbacks to generate audio from Java.
  • Event functions (including SDL_SetEventFilter with a callback) and simple class system that allows for use of instanceof.
  • Joystick, Keyboard, and Mouse functions for polling device input.
  • Time functions like SDL_Delay and SDL_GetTicks incase their Java counterparts have undesired affects

However, it’s also important to note what wasn’t implemented:

  • Input/output (RWops) for files, since a java.io.File or java.nio.FileChannel (and variants) should be used instead.
  • Thread functions for SDL, since java.lang.Thread should be used instead.

Comparison of SDLbits and sdljavaWhile the code is not 100% complete, it can easily be thought of as at least 85% completed, and work will continue as warranted. It doesn’t hurt that the code is licensed under the LGPL, so anyone can modify and commit changes. Even though the code isn’t complete I compared the amount of both C and Java code between the projects:

One Comment

Post a Comment

Your email is never shared. Required fields are marked *