tags:

views:

1151

answers:

3

I'd like to experiment with Haskell a bit, and I'm hoping to write a small 2D arcade game (Tetris or Breakout). Can you recommend a simple graphics library that will help me to get started quickly?

Btw, I've been experimenting with SDL and wxWidgets, but haven't yet succeeded in running any samples because of dependency problems, working on it...

+1  A: 

Cairo Is written in C but has haskell bindings, Perhaps trying that might be a good idea. Ive only ever used its python bindings but those seemed to work well.

Fusspawn
+3  A: 

Have you perused the following lists:

Haskell Graphics Libraries: There appears to be quite a few interfaces to OpenGL, SDL, and other graphic libs here.

Haskell GUI: There's some wxWidget libs here as well.

DoxaLogos
+4  A: 

It's not exactly a "simple" library, but there is a lot of information online about OpenGL and GLUT, as well as some very good tutorials and a ton of example code.

The biggest issue you're up against is that the OpenGL and GLUT bindings in Haskell do not include the libraries that they bind to. (This is true for wxWidgets as well.) A lot of Linux distros come with OpenGL binaries bundled, but not Windows. The Haskell Platform was supposed to fix this, but it didn't seem to for me.

So, assuming you're installing on Windows, here's what I'd recommend you try:

  1. Follow the directions in this blog to the letter. They're complicated -- involving installs of MinGW, MSys, and hand-compilation of a GLUT project from SourceForge, but it's the only way I've gotten OpenGL to work. I've now successfully installed on three separate machines, including XP and Vista, so I can safely say that these are very good directions.
  2. Once it does work, check out these two awesome tutorials. They really opened my eyes about just how powerful Haskell can be when it comes to graphics. You'll find the code involved a lot simpler than you may have anticipated.
  3. Check out the sample games on the Haskell OpenGL page. They're very experimental -- which is good, as it means less code to wade through than you'll find in a production system -- but they're also surprisingly sophisticated. (And yes, there's already more than one bare-bones Tetris implementation, but don't let that stop you.)
  4. Another good source of sample code is Haskell's GLUT binding itself. Look for the examples directory and you'll find many ports of sample code from the OpenGL Red Book.

OpenGL is very stateful, so you may find the Haskell code a little daunting if you haven't fully grokked Monads yet. I'm using my OpenGL experiments as motivation to finally wrap my mind around the concept.

Good luck!

rtperson
OpenGL state is all in the IO monad, so practice may help with the basics of dealing with monads, but doesn't help when trying to generalize to other monads which do far more useful things than simply keeping track of the state of the world.
ephemient
I don't mean to complain too much, though; OpenGL/GLUT seems like a good start for OP, though it's not very Haskell-ish. Personally I use Gtk2Hs with its GtkGlArea bindings, as it's nicer than raw GLUT, but it doesn't matter what's handling the windows once you get down to OpenGL itself.
ephemient
I haven't played around with GTK. I got wxWidgets working first, so I did my UI experiments with it. But I will try it out now on your recommendation. I agree with you on the monad thing -- the IO monad is a pretty dull beast, but it is a place to start. My eventual goal is to work my way up to arrows so I can try some reactive programming with Yampa. Right now all the concepts are flying over my head but I'm starting to put the pieces together.
rtperson
The configure step in OpenGL's configuration give me the error "Couldn't reserve space for cygwin's heap", apparently this may be caused by anti-virus software. Disabling Avast on my computer doesn't seem to help the problem. Patience and perseverance are getting well trained in this little project...
StackedCrooked
Actually it's more likely a pathing problem, especially if you have both Cygwin and MinGW installed. For some reason, compiling the freeglut libraries doesn't work with Cygwin's gcc. Type "gcc --version" into the command line and make sure the resulting output looks something like this: "gcc.exe (GCC) 3.4.5 (mingw-vista special r3)"
rtperson