How do I use GTK and glut together?

你。 提交于 2019-12-05 18:57:47

You are running the main loops. gtk_main() runs until gtk_quit() is called.

gtk_main() at GTK.org

Runs the main loop until gtk_main_quit() is called. You can nest calls to gtk_main(). In that case gtk_main_quit() will make the innermost invocation of the main loop return.

Also, glutMainLoop() works the same way, it processes GL events forever.

glutMainLoop() at OpenGL.org

glutMainLoop() enters the GLUT event processing loop. This routine should be called at most once in a GLUT program. Once called, this routine will never return. It will call as necessary any callbacks that have been registered.

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

Runs a single iteration of the mainloop. If no events are waiting to be processed GTK+ will block until the next event is noticed. If you don't want to block look at gtk_main_iteration_do() or check if any events are pending with gtk_events_pending() first.

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() using glutIdleFunc(void (*func)(void)) which will run a callback for every frame - glutIdleFunc()..

Or you could give a callback to glutTimerFunc(unsigned int msecs, void (*func)(int value), value) to call and check the return value of 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.

You don't. There's generally no point to it.

GLUT is a library for creating and managing OpenGL windows. GTK already has an OpenGL window in it. If you're using GTK, then there's no point in using GLUT. It's like having two vector math libraries or something.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!