Ok I am back with one more rant on Lisp.
Because of an idea I have, that is not yet ripe for decision, I was trying to get a graphics library that is portable and has a Common Lisp binding. Finally I got stuck on opengl and cl-opengl binding. I had a hard time getting it to run on Mac OS X so I tried it on Linux first where it worked out of the box. It is pretty nice even if making a mistake sometimes kills your lisp.
To install cl-opengl you need a Common Lisp implementation (I use sbcl), cffi (I used cffi 0.9.1), an opengl library (I used the one shipping with Mac OS X) and GLUT (I used OpenGLUT but more on that later).
First I tried to get cl-opengl running with the native Mac OS X GLUT implementation but it did not work. I found information on the cl-opengl list that you need FreeGLUT. The problem with FreeGLUT is that it does not compile on Mac because of some joistick problems.
So… get the source tarball of OpenGLUT.
Untar it and run “CPPFLAGS=”-I/usr/X11R6/include” ./configure”. You need the CPPFLAGS variable because otherwise the build system will not find the right opengl headers.
Now run make and make install. In my case I added the option –prefix=/opt/mine to configure to not taint the running system with self compiled stuff.
Finally you should end up with OpenGLUT libraries.
Now download cl-opengl (probably using darcs “darcs get http://www.common-lisp.net/project/cl-opengl/darcs/cl-opengl/”)
Link the .asd files to your sbcl systems directory:
# ln -s ~/cl-opengl/*.asd ~/.sbcl/systems
The problem with OpenGLUT is that it uses X11 to create windows. So you have to start the Mac OS X X11 server and start sbcl in the xterm within X11.
After starting sbcl you can run at the repl the following:
* (asdf:operate ‘asdf:load-op ‘cl-glut-examples)
That should compile and load the cl-opengl cl-glut and cl-glu bindings and also cl-glut-examples.
Now you should be able to test it running:
* (cl-glut-examples:gears)
on the sbcl repl.
Conclusion:
cl-opengl binding is really nice. It still needs work so that it catches all errors that may occur. Doing something unpredicted with opengl may cause your lisp process to crash.
It also requires at least FreeGLUT that is not willing to compile on Mac OS X but that is understandable because GLUT itself misses some features that are required to create really dynamic applications what is what you want. OpenGLUT does compile on Mac OS X but seems to be pretty old (2005 last release) and just like FreeGLUT requires X11. That is really nasty. I do not want X11 🙁
It is usable it is pretty nice but there still is a lot to do! I will for sure dive more into that stuff and try to fix at least some of the problems I found.
But nonetheless thanks OpenGLUT and cl-opengl guys for your fine work! Now I can finally create some nice graphical stuff! Woot!
One more thing… the cl-glut-examples:gears demo gives the following frame rates on my MacBook Pro:
23857 frames in 5.0 seconds = 4771.400 FPS
24407 frames in 5.0 seconds = 4881.400 FPS
24316 frames in 5.0 seconds = 4863.200 FPS
24293 frames in 5.0 seconds = 4858.600 FPS
I think it is amazing! Tell me what framerates you get! 😉
i tried cl-opengl under linux too and must agree, its awesome!!! Its cool to rotate objects and set parameters on the repl. After a few hours i had a nice 80ties-style wireframe sin wave wobbling around in space _dynamically_ .
In my opinion, the opengl api fitts well into lisp style programming.
But now its still really unstable, especially while setting up and close opengl windows/sessions.
viel spass!
I did not have real problems with setting up and closing the windows. I made a mistake and used gl:finish in glut:idle what crashed the whole lisp process. I know that one should not do that but still I should get an error and be thrown to the lisp debugger or so.
I have not yet reported that on the cl-opengl-devel mailinglist. I should do it soon.
But I agree the dynamic of this API is amazing. That is exactly what I love about it.
Viel spass, to you too 😉
Hi,
From a previous post, you said you want comments, because it keeps you writing. So here’s one 🙂
I just hit your sit a few minutes ago and find it interesting.
I’m myself interested in trying opengl+lisp.
Thanks for your sharing.
— Thu
Hi!
Thanks a lot for this post, it really got me started..
There is only one thing: Are you receiving keyboard events?
Thanks and viel spass,
Kilian
Yes I am. The problem is that in the example code the variable holding the keyboard code is not being converted to char. you have to enclose the variable with ‘encode-char’ everywhere where you compare the key to a char.
Cheers Esden
> you have to enclose the variable with ‘encode-char’ everywhere where you compare the key to a char.
or better yet, write a macro that does it for you ;-))
This guide was helpful
a couple missing steps (but obvious),
– symlink the cffi *.asd into the .sbcl/systems dir in the same
way that the cl-opengl .asds are,
– setenv DYLD_LIBRARY_PATH to the location of the openglut library
before launching SBCL.
– I also had to modify the cl-opengl/glut/library.lisp file
to look for libopenglut.dylib (rather than libglut.dylib).
However, my frame rates are much lower,
6422 frames in 5.0 seconds = 1284.400 FPS
on a macbook pro core duo 2. I wonder why the lower fps…
Earlier the gears X11 window was partially covered by the
translucent dock, near the finder icon.
When I move the window out from under the doc, the fps
increases to ~4700.
Just found your site while googling for the solution of the same problem: freeglut/openglut on OSX without X.
However, just FYI I’ve been able to compile freeglut 2.4.0 on OSX 10.4.10 without problems with this line:
CFLAGS=”-I/usr/X11R6/include” CXXFLAGS=”-I/usr/X11R6/include” ./configure –disable-warnings
OpenGLUT has a Fink package for OSX users, making it easy to install. I put symlinks in /usr/local/lib to point to the libs’ install dir. OpenGLUT apparently was forked from FreeGLUT, so don’t even worry about that, just use OpenGLUT.
I’m getting 6500 FPS with my MacPro and Nvidia 8800 GT :O
I needed to use
LDFLAGS=”-dylib_file/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib” CPPFLAGS=”-I/usr/X11R6/include” make
as my make command to get the source tarball of openglut to compile (found the LDFLAGS here: http://lists.apple.com/archives/X11-users/2008/Jun/msg00226.html). I am using SBCL 1.0.20, so when I loaded cl-opengl with asdf, it asked me to recompile the fasls, which I let it do, and now the cl-glut-examples seem to be working alright (at least gears anyways; cl-glut-examples:run-examples dies). I also found this page (http://d.hatena.ne.jp/macLisper/?of=5) quite helpful. I’m using a C2D MacBook @ Leopard 10.5.6 along with sbcl 1.0.20.