[Haskell-beginners] Reading pixels in Haskell SDL

han e at xtendo.org
Tue Feb 9 17:55:13 EST 2010


I'm using SDL (http://hackage.haskell.org/packages/archive/SDL/0.5.9/doc/html/Graphics-UI-SDL.html)

As far as I know, in the original SDL for C, reading and writing
pixels on a surface is done by accessing pointer + y * width + x. In
Pygame, since Python has no such thing as pointer, they have get_at
and set_at function for this task. I thought there would be something
equivalent in Haskell SDL, but couldn't find any.

For writing pixels on the Surface, I've found a couple of functions:

	Graphics.UI.SDL.Video.fillRect
(http://hackage.haskell.org/packages/archive/SDL/0.5.9/doc/html/Graphics-UI-SDL-Video.html#v%3AfillRect)
	Graphics.UI.SDL.Primitives.pixel
(http://hackage.haskell.org/packages/archive/SDL-gfx/0.5.3/doc/html/Graphics-UI-SDL-Primitives.html#v%3Apixel)
	...

However, I can't find one that reads.

Graphics.UI.SDL.Types.surfaceGetPixels
(http://hackage.haskell.org/packages/archive/SDL/0.5.9/doc/html/Graphics-UI-SDL-Types.html#v%3AsurfaceGetPixels)
looks like the one, but I have no idea how I can use it, since it
returns Pixels which is defined as:

	data PixelsData
	type Pixels = Ptr PixelsData

I want to read a pixel at (x, y) of a Surface. Does anyone know how?


More information about the Beginners mailing list