[Haskell-cafe] Re: Combining Gtk2hs and Fieldtrip

Andy Stewart lazycat.manatee at gmail.com
Sun Aug 8 06:05:13 EDT 2010


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 <herngyi at gmail.com> writes:

> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list