[Haskell-cafe] [C Binding] Turning the mutable to immutable?
limestrael at gmail.com
Mon Jul 5 17:48:56 EDT 2010
I don't know if some of you are familiar with the SFML library (stands for
Simple and Fast Multimedia Library) --> http://sfml-dev.org
As SDL, SFML is a 2D graphics library, but conversely to SDL it provides a
hardware-accelerated drawing, through OpenGL.
Well, I'm currently writing its Haskell binding, and I'm stuck with design
What I'm heading to is a full IO binding, and that's what I'd like to avoid.
I particularly like the way HGL works, with the Draw monad which (IMO)
enables powerful composability of the drawings.
But HGL is simpler in the way that, for instance, it doesn't deal with
So that's why I would like to pick up advice concerning the design of such a
First, this is how SFML (in C/C++) works:
The main types are RenderWindow, Drawable, Image, Sprite, Shape, Font and
An Image basically represents an array of pixels. It is just a resource, and
is not directly drawable. An image is loaded from a file, and provides
methods for accessing/altering its pixels. Its main purpose is to be bound
as an OpenGL texture.
A RenderWindow is the window on which the Drawables are... well... drawn.
A Sprite, now, is a Drawable. One Sprite is linked to one Image. A Sprite
NEVER alters its Image, it just provides
positionning/rotation/resizing/colorizing methods that will be translated,
when drawing on the RenderWindow, to glTranslate/glRotate/glScale/glColor,
So we can see a Sprite as an instance of an Image, since if a same Image is
to be drawn 3 times on the same frame, we are advised to create three
Sprites of it, which will differ by their position.
A Font is loaded from a file, it is a simple resource, just like Image.
Text and Shape are Drawables.
So, now, questions:
1) For those who know HGL, can the monad Draw principle be adapted to my
case? Or am I heading for disaster?
2) How would I handle images? SFML API enables the user to alter the pixels
of the image, and I obviously don't wanna copy the entire Image each time a
pixel is changed.
3) Is there another library on hackage that handles images in a functional
way? (I mean not *all in IO*)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe