[GtkGLExt] OpenGL rendering context - multithreading



Hello,
I am trying to make some OpenGL computer game (of course using "gtkmm +
gtkglextmm").

I have 2 threads so far in my application: the "GUI (Graphical User
Interface) thread", which is in fact the main thread started at the very
beginning of the application (just the "int main(int argc, char* argv[])"
function), and the "game thread". The GUI thread is responsible for "user
interaction" (so when I click to some button, the GUI will response with
some function or do something, etc...; this is the work for the GUI thread)
and the game thread is responsible for "application (or game) logic" - so
there (in the game thread) are some initializations at the beginning, the
game loop and then some cleanup. The game loop could look like this:

====================================
while (shouldFinish != true)
{
    doSomeGameLogicStuff();   // Move players or monsters, do some
calculations, etc...
    renderGraphics();   // Render the OpenGL scene depending on the previous
calculations
    sleepForSomeTime();   // Sleep the thread for some time (to achieve for
example 40 fps)
    displayGraphics();   // If for example double-buffering is enabled, this
means "swap buffers"
}
====================================

Next, all the rendering and drawing commands are done on a
"Gtk::GL::DrawingArea" widget which was created by the GUI thread but I am
using it by the game thread (this could probably be the problem).

So when for example in the game thread (in the game loop) the
"renderGraphics()" function is called, it wants to do some OpenGL rendering
stuff and when it calls for example the "gtkglextmm" function
"Gtk::GL::DrawingArea::get_gl_context()", the application terminates and
throws me this error:

    (openGLGame:8447): GtkGLExt-CRITICAL **: gtk_widget_get_gl_window:
assertion `GTK_WIDGET_REALIZED (widget)' failed

or sometimes

    Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.


I read something about this on other sites and I there was written that I
should create the OpenGL rendering context (e.g. a "Gdk::GL::Context") on
the same thread which I use it on, or something like that.

So how can I solve this? Should I construct the "Gtk::GL::DrawingArea" when
I am in the game thread, or should I create a new OpenGL context for the
game thread or what (and how)?


Thanks in advance.
-- 
View this message in context: http://old.nabble.com/OpenGL-rendering-context---multithreading-tp27396739p27396739.html
Sent from the Gnome - GtkGLExt mailing list archive at Nabble.com.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]