Hello,
Don Geddis <
d...@geddis.org> wrote:
> Any recommendations for a library to write a 2D graphics game in Common
> Lisp?
>
> Imagine you wanted to write Pong or Asteroids or Centipede, with the
> logic being in Common Lisp. (Best if it would work on some open source
> CL platform.)
>
> I'm guessing the operating systems have built-in graphics libraries, and
> mostly what one uses is bindings into the OS. Ideally I'd like to
> develop under linux, and perhaps deploy on windows, but maybe that's
> asking too much, as there is little in common between linux and windows.
>
> Anyone have experience in this, and any advice to offer me?
I wrote a small game using Common Lisp a bit ago. I used
lispbuilder-sdl and cl-opengl as my main libraries. They worked
out excellently.
Generally, I'd use lispbuilder-sdl to open the display, run the
physics engine, deal with assets (like texture images), and handle
keyboard/mouse inputs. I'd use cl-opengl for the actual drawing. You
can load a png with lispbuilder-sdl and put it into a sdl buffer
suitable for binding to cl-opengl. This is good enough for a lot
of needs. lispbuilder-sdl has excellent, if almost too verbose,
documentation and cl-opengl, well, isn't so well documented but after
reading of shipped example code and other stuff you'll figure it out.
I'm not saying what I wrote is good code (though a number of people
here helped me write much more idiomatic CLOS), but here's an example
of what I did (though it used line graphics, and not 2d sprites,
but it was 2D).
http://pages.cs.wisc.edu/~psilord/lisp-public/option-9.html
The entirety of the code is explained. The main interest for you
is probably near the bottom of the document, where it shows how to
use lispbuilder-sdl.
Even tough I wrote it for SBCL on linux, a friend got it working
with a _tiny_ patch (that the current sources has and it turned out
to be some nonconforming code that SBCL accepted silently) with CCL
on windows. I was surprised. :) This tells me that as long as you
stick to libraries which exist across linux and windows in Common
Lisp along with as much ANSI stuff as you can, you can have your
portability without too much trouble.
I'm writing another game where I discovered that lispbuilder-sdl and
cl-gtk2 just don't mix very well (and lo, I was sad). I'd avoid using
those at the same time. cl-gtk2 and cl-opengl together will work, but
there is a funny thing about cl-gtkglext (which enables embedding of
an opengl context into a gtk window) and that might not be portable...
I haven't yet explored GPU programming with Common Lisp yet, but I'll
get there...
I hope you find this stuff helpful.
Later,
-pete