0
votes

I'm working on a project where I have an opengl window and a gtk window, now I want to be able to control the opengl from gtk.

In Gtk window I have a button which call the image generator and after this I would like to redraw the opengl window so I can see the result, but if I call the display function from the button clicked callback nothing happens. The only think that worked so far was when I set the glutIdleFunc to my display func, that way the opengl window was redrawn constantly, however it seems to me that there must be a better way. Also I tried the glutTimerFunc to check for a conditional variables but again is there any better way.

My idea is to be able to tell/signal/call directly the opengl display function or force the glutMainLoop to do an iteration, whenever I click the button, but I really don't know how to do that.

Any ideas?

2

2 Answers

1
votes

Any ideas?

Don't use GLUT or GLFW or any other OpenGL framework. You're using GTK+ so stick with that. There's a OpenGL widget for GTK+. Use that. Since your OpenGL code is then nicely integrated with GTK+ you can use the normal signal events mechanism of GLib (used by GTK+) without furhter ado.

0
votes

First, I would really recommend you stop using plain GLUT. Once your application has grown into the sort of needs you describe (multiple windows, GTK+, ...), GLUT is not flexible enough to be a workable solution.

Look at, for instance GLFW as a suitable replacement, it is way more flexible and actually good enough for real applications to use.

Second, you mention threads in your title but not in your question body, so it's a bit unclear if you're really using threads. If you are, then you need to look into thread-safe communications. The glib library which GTK+ is built upon has a few APIs for this, check them out. If not using threads, you can probably get away with a few direct function calls and just invalidating the OpenGL state so it re-draws.