
Recently I wrote a 3D graphics viewer using Gtk2hs and Cairo, and it works ok, aside from the fact that it got quite slow when it got to displaying about 1000 polygons. It works something like this: The three-dimensional coordinates of polygons are given, and the program sorts the polygons using a BSP Tree (following the Painter's Algorithm), then it projects the polygons onto the plane of vision and renders each polygon to the screen using Cairo. After some investigation, I realised that my bottleneck was the rendering of polygons, but I could not speed up the rendering using parallel programming since the rendering order is crucial in the Painter's Algorithm. Even if I switched to an algorithm based on Hidden Surface Removal so I could render all my "obscured" polygons at once, Gtk2hs "is single threaded and its functions cannot be called from other threads". Then I heard about FieldTrip, which uses the GPU to process rendering efficiently. I decided to switch to using FieldTrip in conjunction with Gtk2hs to write applications, but it doesn't seem that easy because (i) there doesn't seem to be any version of GHC where Gtk2hs, Glade and Fieldtrip can work together on Windows and (ii) unlike Cairo, there is no Gtk2hs support for Fieldtrip in the sense that there are no Gtk2hs functions that render FieldTrip output to a Gtk2hs widget, like the DrawWindow. The latter would mean that Gtk2hs can't interact easily with FieldTrip. I really like Gtk2hs because it is very comprehensive and its interface can be designed using Glade. Does anyone know if there is a project linking Gtk2hs and FieldTrip? Otherwise, does anyone know if user interfaces can be written using Reactive (since it's linked to FieldTrip) with the usual functionality (e.g. menus, buttons, FieldTrip display reacting to mouseclicks etc)? If that is possible then I might have to switch to Reactive, but I'd miss Glade a lot :) regards, Herng Yi

Gtk2hs has an OepnGL binding. So you can create OpenGL context and draw there. I don't think you will still be able to use parallel threads, but path to hardware renderer will be shorter for sure.

Date: Sun, 8 Aug 2010 12:53:54 +0300 Subject: Re: [Haskell-cafe] Combining Gtk2hs and Fieldtrip From: sergueyz@gmail.com To: herngyi@gmail.com CC: haskell-cafe@haskell.org
Gtk2hs has an OepnGL binding. So you can create OpenGL context and draw there.
I don't think you will still be able to use parallel threads, but path to hardware renderer will be shorter for sure.
Thanks for the info! I looked at the documentation for GtkGLExt (I think you were referring to this), and compared to FieldTrip, I think it's a lot harder to write. As diving into either of these systems would require serious work, I'm not totally sure of this, but it seems that FieldTrip is more high-level with its wrappers and with GtkGLExts you still have to deal with lots of small details. Is it possible that that FieldTrip could export a data structure (Geometry3 ?) that can be read by GtkGLExts? That would solve the problem of interfacing between Gtk2hs and FieldTrip. regards, Herng Yi

Hi Herng,
You can use gtk2hs with OpenGL, then use OpenGL render your 3D graphics.
You can use command
cabal install install gtkglext
to try it, demo at http://code.haskell.org/gtkglext/demo/
About multi-threaded, yes, you must post all *gtk* code to gtk+
main thread, otherwise bad thing will happened.
But you can unsafeInitGUIForThreadedRTS with "-thread" to enable
multi-thread, then use other threads calculate *non-graphics* code,
and use postGUIAsync post all *gtk* code to gtk main-thread.
Of course, if OpenGL still slow, perhaps algorithm problem or hardware
performance problem.
Cheers,
-- Andy
Herng Yi Cheng
Recently I wrote a 3D graphics viewer using Gtk2hs and Cairo, and it works ok, aside from the fact that it got quite slow when it got to displaying about 1000 polygons. It works something like this: The three-dimensional coordinates of polygons are given, and the program sorts the polygons using a BSP Tree (following the Painter's Algorithm), then it projects the polygons onto the plane of vision and renders each polygon to the screen using Cairo. After some investigation, I realised that my bottleneck was the rendering of polygons, but I could not speed up the rendering using parallel programming since the rendering order is crucial in the Painter's Algorithm. Even if I switched to an algorithm based on Hidden Surface Removal so I could render all my "obscured" polygons at once, Gtk2hs "is single threaded and its functions cannot be called from other threads".
Then I heard about FieldTrip, which uses the GPU to process rendering efficiently. I decided to switch to using FieldTrip in conjunction with Gtk2hs to write applications, but it doesn't seem that easy because (i) there doesn't seem to be any version of GHC where Gtk2hs, Glade and Fieldtrip can work together on Windows and (ii) unlike Cairo, there is no Gtk2hs support for Fieldtrip in the sense that there are no Gtk2hs functions that render FieldTrip output to a Gtk2hs widget, like the DrawWindow. The latter would mean that Gtk2hs can't interact easily with FieldTrip.
I really like Gtk2hs because it is very comprehensive and its interface can be designed using Glade. Does anyone know if there is a project linking Gtk2hs and FieldTrip? Otherwise, does anyone know if user interfaces can be written using Reactive (since it's linked to FieldTrip) with the usual functionality (e.g. menus, buttons, FieldTrip display reacting to mouseclicks etc)? If that is possible then I might have to switch to Reactive, but I'd miss Glade a lot :)
regards, Herng Yi
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Andy Stewart
-
Herng Yi Cheng
-
Serguey Zefirov