I know that in order to write a GTK application, I write a bunch of code which describes what is put in the main window, then I call:
gtk_main();
Any code statements after this do not get executed.
Now let’s suppose I’d like my GTK app to display something I wrote with glut, which itself contains a bunch of statements about what graphics need to be set etc. then ends with the statement:
glutMainLoop();
Anything after this is not executed.
So my problem is that either of these two statements prevents me from calling the other.
- Is there a way to execute a glut main loop inside a GTK widget ?
- Is there a way to write a code that could somehow simultaneously call both a GTK main loop and a glut main loop (but called from the main program and rendered in a separate X window, not within a widget)? I’ve got a feeling this could be done with “threads”…
You are running the main loops.
gtk_main()runs untilgtk_quit()is called.gtk_main() at GTK.org
Also,
glutMainLoop()works the same way, it processes GL events forever.glutMainLoop() at OpenGL.org
So, you you wan’t both of these things to execute at the same time (I think they might interfere with each other so you might get unexpected results) then you will need to call
gtk_main_iteration()from inside glut.gtk_main_iteration() at GTK.org
Now.. GLUT doesn’t have an equivalent to
gtk_main_iteration()so you are going to need to register GLUT callbacks.You could register a callback with GLUT that runs
gtk_main_iteration()usingglutIdleFunc(void (*func)(void))which will run a callback for every frame – glutIdleFunc()..Or you could give a callback to
glutTimerFunc(unsigned int msecs,to call and check the return value ofvoid (*func)(int value), value)
gtk_main_iteration()every 200msec or so.I’d probably experiment with both,
glutIdleFunc()might not always get called regularly enough for good responsiveness.It really is worth looking at driving GTK’s GL support though.