0

I have a program that uses Glib and glib main loop. Also, it uses openGL for drawing some things and needs to handle inputs from keyboard.

Problem se that I used to make everything separated from eachother, not combining it in one program. As Glib has main loop and openGL uses loop for rendering (with some sleeping). With that all, I need a loop for listening key events.

What is the best way of making all of this work togeather? Should I make three loops in threads or implement other loops to glib main loop and how to do that?

10robinho
  • 520
  • 6
  • 17
  • Perhaps you could use the GLib main loop to schedule your rendering activity, even if the rendering needs to happen on a regular basis (e.g. every 1/15th sec.). Events that GLib doesn't detect itself can be turned into GLib events. I found some code once that integrated X into the GLib loop by turning the X keyboard events into GLib events. – cardiff space man Nov 01 '13 at 17:16

2 Answers2

1

I'm not sure if this is what you are looking for, but I have used an OpenGL extension for GTK+ called gtkglext http://projects.gnome.org/gtkglext/

GTK+ projects also rely on Glib, so no changes there. The advantage with using the GTK+ main loop and gtkglext is that you can mix regular buttons/widgets or custom 2D/3D widgets with an OpenGL window.

hellork
  • 420
  • 2
  • 5
  • I've tough about that but I think that using GTK+ would be overweight because I really don't need any of buttons or anything that GKT+ is primary used for. By the way, if I use such heavyweight lib, but if I use only parts, would my program still be slow? If not, that could be simple solution. – 10robinho Mar 24 '12 at 05:02
  • I've checked [this](http://stackoverflow.com/questions/2247465/does-using-large-libraries-inherently-make-slower-code) and decided to try with your suggestion. – 10robinho Mar 24 '12 at 05:17
0

I don't know about Glib per se, but I suspect what you want to do is have one event loop which can switch and hand off the events to be handled by the appropriate subsystems. Which then return back to the main loop.

blueshift
  • 6,742
  • 2
  • 39
  • 63