threading gtk and openGL

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…

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, which essentially allows the use of OpenGL when drawing Gtk+ Widgets.

Yes. So 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.

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.