
I write a lot of programs that build bitmapped images. (Some of you may remember the Chaos Pendulum Simulator...) Currently, all of these programs work by writing the final image data to a PPM file on disk. (Because that's the only way I can figure out to do something *useful* with the data!) What I'd *like* to be able to do, in priority order: 1. Display images on the screen. 2. Save images as PNG files. (PPM eats too much space!) 3. Animate images on the screen. 4. With double-buffering. 5. Not break horribly when rendering in multiple threads. As far as I know, all of this is *possible* with Gtk2hs right now - it's just vastly more complex than making a single function call. So what I'd like to do is write a small library which will enable me to do each of the above tasks in 1 function call. However, I'm getting nowhere fast with this. Anybody have any suggestions? PS. I've investigated existing APIs and I'm not seeing anything that looks useful. Lots of support for drawing lines and arcs and so on, but not for plotting individual pixels.

On Sunday 14 October 2007 13:31:56 Andrew Coppin wrote:
PS. I've investigated existing APIs and I'm not seeing anything that looks useful. Lots of support for drawing lines and arcs and so on, but not for plotting individual pixels.
I highly recommend OpenGL. Even if you are just filling texture maps for now, you have a future proof way to do far more sophisticated graphics. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e

Jon Harrop wrote:
On Sunday 14 October 2007 13:31:56 Andrew Coppin wrote:
PS. I've investigated existing APIs and I'm not seeing anything that looks useful. Lots of support for drawing lines and arcs and so on, but not for plotting individual pixels.
I highly recommend OpenGL. Even if you are just filling texture maps for now, you have a future proof way to do far more sophisticated graphics.
...just... the irony of using OpenGL to write a software ray tracer. ;-) Oh, and the irony of using OpenGL (an API of unimaginable complexity) just to write pixels to the screen. Isn't that kind of like using a thermonuclear device to crack a nut?

On 14/10/2007, Andrew Coppin
Jon Harrop wrote:
On Sunday 14 October 2007 13:31:56 Andrew Coppin wrote:
PS. I've investigated existing APIs and I'm not seeing anything that looks useful. Lots of support for drawing lines and arcs and so on, but not for plotting individual pixels.
I highly recommend OpenGL. Even if you are just filling texture maps for now, you have a future proof way to do far more sophisticated graphics.
...just... the irony of using OpenGL to write a software ray tracer. ;-)
Oh, and the irony of using OpenGL (an API of unimaginable complexity) just to write pixels to the screen. Isn't that kind of like using a thermonuclear device to crack a nut?
OpenGL is used as a pixel-plotting mechanism relatively often. You wouldn't be doing anything new if you did it that way. I say someone binds SDL[1]. (If it hasn't been done already.) - Jeremy [1] - http://libsdl.org

I say someone binds SDL[1]. (If it hasn't been done already.)
Ask and you shall receive: http://darcs.haskell.org/~lemmih/hsSDL/ I use those SDL bindings to plot pixels with OpenGL and play with 3D stuff in Haskell.

Interesting! I just wanted to reply (although Andrew Coppin must have unsubscribed by now...) that I have an application that plots pixels using OpenGL (it's actually not that hard, just visit the new Haskell OpenGL page, and look at the examples given, e.g. http://darcs.haskell.org/packages/GLUT/examples/RedBook/Image.hs). But the SDL stuff seems easier... Thanks, Peter Verswyvelen Roel van Dijk wrote:
I say someone binds SDL[1]. (If it hasn't been done already.)
Ask and you shall receive:
http://darcs.haskell.org/~lemmih/hsSDL/
I use those SDL bindings to plot pixels with OpenGL and play with 3D stuff in Haskell. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

YEEESSS!! W00t11 I've been looking for that for a long time. I
get so sick of glut... Thanks.
Luke
On 10/14/07, Roel van Dijk
I say someone binds SDL[1]. (If it hasn't been done already.)
Ask and you shall receive:
http://darcs.haskell.org/~lemmih/hsSDL/
I use those SDL bindings to plot pixels with OpenGL and play with 3D stuff in Haskell. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

I tried this library on Win32. A very nice initiative indeed. Currently, I found the following problems: - as mentioned in the WIN32 readme file, the library does not seem to work with GHCI. Firstly, it seems to look for incorrect DLLs. When I copy SDL.DLL to both SDLmain.DLL and SDL.DLL.DLL, then GHCI starts the Test app, but it hangs as soon as the window is displayed. This behavior is similar to what I initially had with SOE/Gtk, but that got fixed in the latest release of Gtk2HS. Maybe the author of Gtk2HS (Duncan?) and HSSDL ("lemmih") could exchange information on how to get it running under GHCI? - the documentation contains links to non-existing files. I had to rename Graphics.IO.SDL.<name>.html to Graphics-IO-SDL-<name>.html, then the docs worked. Cheers, Peter Verswyvelen Luke Palmer wrote:
YEEESSS!! W00t11 I've been looking for that for a long time. I get so sick of glut... Thanks.
Luke
On 10/14/07, Roel van Dijk
wrote: I say someone binds SDL[1]. (If it hasn't been done already.)
Ask and you shall receive:
http://darcs.haskell.org/~lemmih/hsSDL/
I use those SDL bindings to plot pixels with OpenGL and play with 3D stuff in Haskell. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Andrew said:
Oh, and the irony of using OpenGL (an API of unimaginable complexity) just to write pixels to the screen. Isn't that kind of like using a thermonuclear device to crack a nut?
Saying that using OpenGL to write pixels to the screen is like using a thermonuclear device to crack a nut, is like saying that using a computer to edit files is like using a thermal lance to slice butter. (Do you like my higher order simile?) Incidentally, people raytrace with OpenGL all the time via GPGPU: http://www.gpgpu.org/cgi-bin/blosxom.cgi/Advanced%20Rendering/index.html I'm looking forward to someone implementing a nice Haskell API to all that yummy GPGPU stuff, like Python's http://www.cs.lth.se/home/Calle_Lejdfors/pygpu/ (I've heard rumours...) -- Dan

Andrew Coppin:
As far as I know, all of this is *possible* with Gtk2hs right now - it's just vastly more complex than making a single function call. So what I'd like to do is write a small library which will enable me to do each of the above tasks in 1 function call. However, I'm getting nowhere fast with this. Anybody have any suggestions?
Despite having a large API gtk2hs is pretty easy to use for these kind of tasks. You can look at this library [1] (for plotting charts) to see simple examples of opening windows, saving images etc. It uses the (nice) 2D cairo API for drawing, though it's not too hard to work with raw pixels via the functions in Graphics.UI.Gtk.Gdk.Pixbuf. You'll need to restrict your drawing calls to a single thread - most GUI toolkits will require this. Haskell makes this easy through its ability to pass drawing actions from thread to thread. Tim [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Chart-2007.8.8
participants (8)
-
Andrew Coppin
-
Dan Piponi
-
Jon Harrop
-
Luke Palmer
-
nornagon
-
Peter Verswyvelen
-
Roel van Dijk
-
Tim Docker