42

I basically want to create a full screen window and draw text on it in different colors and sizes (and also update the screen). I've used pygame for this in python and I'm looking for a similar library (should be fairly easy to use).

+1 if it handles input too...

Don Stewart
  • 137,316
  • 36
  • 365
  • 468
akosch
  • 4,326
  • 7
  • 59
  • 80
  • Thanks for all the answers: I'm going to try both haskgame and SDL. – akosch Apr 10 '11 at 20:09
  • http://github.com/snkkid/LazyFooHaskell, http://web.animal-machine.com:8080/blog/2010/04/getting-started-with-sdl-in-haskell – Gerold Meisinger Apr 11 '11 at 16:47
  • 1
    So, after almost 2 years, what did you choose as lib, did you do anything useful, what was a general experience with 2D Haskell...? – CoR Jan 09 '13 at 18:48
  • 2
    @CoR: I used the SDL and the SDL-ttf packages from hackage and the experience was great: I managed to do what I wanted to and it's a lot faster than I expected it to be! Also I have a lot less code, doing the same thing now. – akosch Jan 09 '13 at 20:46
  • Thank you. I am about to do the same 2D thing, so it's good to know that SDL works well in real world :) – CoR Jan 10 '13 at 00:51
  • @CoR: No problem, I want to add that I've only used it on Linux. – akosch Jan 11 '13 at 18:23
  • Yup, that's the difference :) Who ever ported SDL to windows did opposite from nice and easy. Found 3 tutorials how to install sdl on win. None of them seem to work. Sounds like promising start, doesn't it? ;) – CoR Jan 11 '13 at 23:05

4 Answers4

69

Instead of picking individual libraries, I'll have a go at a quick overview at all of them, as listed in the Graphics section on Hackage.

Basic frameworks:

OpenGL

GTK

cabal install cairo

QTHaskell

  • Relatively little use, but when it is used, it is used notably.
  • Not on Hackage, found here, due to C++ issues
  • Notable users: Nikki and the Robots, a commercial game.

SDL

cabal install sdl

X11

cabal install X11

Venerable Unix user interfaces.

Examples: xmonad.

GD

cabal install gd

The GD graphics system. Package on hackage.

Examples: wordcloud, sparklines.

HOgre

cabal install hogre

Bindings to the Ogre game graphics system.

Now, besides these game layers, there are many higher level frameworks and tools:

Diagrams

cabal install diagrams

2D vector diagrams (e.g. for math), built on cairo.

Gloss

cabal install gloss

2D graphics, very easy interface, relatively new. See TomMD's comment.

Cal3D

cabal install cal3d

Bindings to the Cal3D animation package.

Chalkboard

cabal install chalkboard

OpenGL-based combinators for generating images, used in teaching.

TeaHS

cabal install TeaHS

A simple library for use creating 2D games, inspired by the Ruby library Tea.

Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
Don Stewart
  • 137,316
  • 36
  • 365
  • 468
  • I keep forgetting Chalkboard has been updated to compile/run (it was broken for a while). Good work Gill et al., and thanks for the reminder. – Thomas M. DuBuisson Apr 10 '11 at 19:57
  • Great list! Gloss and diagrams look especially interesting and relevant to what I want to make. – Nek Jun 26 '13 at 09:56
21

If you're looking for a specialized game library, you have a number of options that you can find here. FunGEn is probably your best option out of those libraries. However, your question seems to suggest a game library would be a bit overkill, if all you're looking to do is draw text and receive input. In that case, you might opt for something simpler like HOpenGL or hsSDL. There are also several other libraries listed here.

Edit: After a bit more research, you might do well using haskgame. I've never used it myself, but it looks like it's got a few functions here that do exactly what you're looking for.

Jeff Burka
  • 2,571
  • 1
  • 17
  • 30
16

I'd recommend the new Gloss library as an easy way to get good results.

Gloss hides the pain of drawing simple vector graphics behind a nice data type and a few display functions. Gloss uses OpenGL and GLUT under the hood, but you won't have to worry about any of that. Get something cool on the screen in under 10 minutes.

There are also nice examples, such as:

hello world

enter image description here

and a nice example building flocking simulators

Alternatively, if it is vectors and text you want to manipulate, the diagrams package on top of cairo can yield very good results.

Don Stewart
  • 137,316
  • 36
  • 365
  • 468
  • 7
    Gloss is easy, but it's feature incomplete for anything beyond it's intended use of education. I made a simple drawing application in Gloss and found that a few of its bugs (broken text location translation, broken window resize at least in XMonad, 100% CPU use when rendering in a Gnome environment, to name a few) detracted along with it's inability to display and translate images (ex: PNG, JPG). This last one has been partially addressed, it can now display bitmaps. To recap: I found Gloss really neat and easy to use, but it needs a few days of fixes and improvements to the library itself. – Thomas M. DuBuisson Apr 10 '11 at 17:32
  • Is it ok for something really simple? I want to use it to visualize a simple roguelike. What matters most is bugless bitmap drawing (I'm going to use tiles). – Nek Jun 26 '13 at 09:57
3

You could use Qt. That's what the cross platform Nikki And The Robots is using. You can see their source code and take a look at what they're doing.

Theo Belaire
  • 2,980
  • 2
  • 22
  • 33