PDA

View Full Version : threading gtk and openGL



akashiraffee
03-06-2009, 11:49 AM
I imagine I am not the first one to do this as there appears to be some software on my system that does something of that sort. Basically, I'm making a control interface for my experiments as I learn openGL (I'm good with gtk and totally new to pthreads). So I thought I'd check in early, ask a couple questions and see if anyone has 2 cents to contribute.

First, I'm using GLUT to learn with, and it seems that glutInit() must be in main() or else I get a segfault. Fortunately, the gtk_main() loop works in a function called as a thread, so no serious problem -- but is this the case with openGL itself (ie, could I code my own loop to run openGL outside main, sans GLUT?) After all, eventually it would be nice to be able to start and stop seperate openGL and gtk processes via main().

Second, well I don't have a second yet...

S.Seegel
03-06-2009, 12:16 PM
It should be GLUT _or_ Gtk+. You are effectively trying to use two toolkits in one app at the same time. Not a good idea.

You may want to take a look at GtkGlExt (http://gtkglext.sourceforge.net), which essentially allows the use of OpenGL when drawing Gtk+ Widgets.

satan
03-06-2009, 12:19 PM
could I code my own loop to run openGL outside main, sans GLUT?
Yes. So just drop GLUT. Any reason why you do not use a GTK OpenGL widget?

akashiraffee
03-06-2009, 02:55 PM
just drop GLUT. Any reason why you do not use a GTK OpenGL widget?

I know it exists (that is GtkGLExt) but I wanted to find out if this would work, because it seems more versatile and I don't need the openGL stuff inside the gtk window.

Right now it's going great (all I have so far is some sliders to adjust the RGB levels on light0, but hey, it works) Issuing openGL commands in a function which is evoked by a gtk signal handler causes boo-boo. That makes sense, since there isn't any synchronization. I suppose that won't be an issue with GtkGLExt (which makes sense too, me having this versatility issue assbackward), altho it's hard to tell just glancing at the API.

satan
03-07-2009, 09:57 AM
AFAIK OpenGL commands must be issued in the same thread that created the context. So if your gtk signal handler work in their own thread it is supposed to not work.