Friday, April 4, 2008

GLFW Derelictified

I started looking again at the GLFW library yesterday. I do really like the API. Somehow it's nicer than SDL's. The only thing missing is a better support for image loading.

I remembered using a D binding for GLFW once and tried to find it. In the end I found it in the Schooner project in dsource, but it hasn't been updated in a long time. Plus it uses Phobos. I thought about trying to update and convert it to Tango for about a second or two, and then decided to do Derelict bindings for it instead. They are easier to maintain, but the downside is that you need to lug around the shared library for it.

I used the latest release of GLFW (2.6), and only tested things with a simple test application on Windows XP.

So if you like the framework go grab the D bindings from here.

Windows users please read the readme file.

2 comments:

Codepoet said...

Hi!

I tried to use your GLFW bindings under Linux but compilation using rebuild + gdc failed. I got the following error:
glfw.s: Assembler messages:
glfw.s:3264: Error: symbol `_D14TypeInfo_FiiZv6__initZ' is already defined
glfw.s:3290: Error: symbol `_D14TypeInfo_FiiZv6__initZ' is already defined
glfw.s:3342: Error: symbol `_D14TypeInfo_FiiZv6__initZ' is already defined
glfw.s:3367: Error: symbol `_D14TypeInfo_FiiZv6__initZ' is already defined

All I did so far was importing glfw...
I fixed this problem by changing the function pointer types in glfw.d.

Another change was needed to get derelict loading the .so:
"libGLFW.so" to "libglfw.so" in the setup call.

Patch:
--- odefu-read-only/DerelictGLFW/derelict/glfw/glfw.d 2008-04-14 01:38:24.000000000 +0200
+++ derelict/glfw/glfw.d 2008-04-14 12:52:41.000000000 +0200
@@ -108,7 +108,7 @@
static this() {
DerelictGLFW.setup(
"glfw.dll",
- "libGLFW.so",
+ "libglfw.so",
"",
&load
);
@@ -532,15 +532,15 @@
alias void* GLFWcond;

//Function pointer types
-typedef void (GLFWwindowsizefun)(int, int);
-typedef int (GLFWwindowclosefun)();
-typedef void (GLFWwindowrefreshfun)();
-typedef void (GLFWmousebuttonfun)(int, int);
-typedef void (GLFWmouseposfun)(int, int);
-typedef void (GLFWmousewheelfun)(int);
-typedef void (GLFWkeyfun)(int, int);
-typedef void (GLFWcharfun)(int, int);
-typedef void (GLFWthreadfun)(void*);
+typedef void function(int, int) GLFWwindowsizefun;
+typedef int function() GLFWwindowclosefun;
+typedef void function() GLFWwindowrefreshfun;
+typedef void function(int, int) GLFWmousebuttonfun;
+typedef void function(int, int) GLFWmouseposfun;
+typedef void function(int) GLFWmousewheelfun;
+typedef void function(int, int) GLFWkeyfun;
+typedef void function(int, int) GLFWcharfun;
+typedef void function(void*) GLFWthreadfun;

OdeFu said...

Hi and thanks for testing the bindings under linux. I don't have one at the moment so cannot test anything. I committed the changes you provided. Hopefully things work now, but let me know if there are still problems.