gtk + glxcontext/opengl



Hi -

I'm developing an OpenGL app on RedHat Linux WS 4 that uses freeglut to
manage the underlying windowing system. I'm also using multiple
rendering contexts with multi threads.

This is my first GTK code and my goal is to use GTK to display a file
browser dialog box to open/save files. This is the GTK code:

//----------------------------------------------------------------------
-------------
// gtk
bool
OpenFileNames ( std::vector<std::string> &vFileNames ) { char *filename;
GtkWidget *dialog = NULL; dialog = gtk_file_chooser_dialog_new ("Open
File",
             NULL,      
             GTK_FILE_CHOOSER_ACTION_OPEN,
             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
             GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
             NULL);
if( !dialog ) return false;

bool bSuccess = false;
if( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) {
    filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER ( dialog
) );
    vFileNames.push_back( filename );
    g_free( filename );
    bSuccess = true;
}
gtk_widget_destroy( dialog );

// Make sure widget gets removed from screen while( gtk_events_pending()
) gtk_main_iteration();

// flush X events
gdk_flush();

return bSuccess;
}
//----------------------------------------------------------------------
-------------

After OpenFileNames() returns, a loading thread is then launched. Inside
this loader thread, a call to glxMakeCurrent() is made to change
rendering contexts for multithreaded OpenGL operation.

The X error I receive is:

The error was 'GLXBadContextTag'. (Details: serial 1481 error_code 161
request_code 144 minor_code 5)

I used gdb with --sync and broke on gdk_x_error() and the backtrace is:

#0 gdk_x_error
#1 _XError
#2 _XReply
#3 glxChannelRectSyncSGIX

My questions are:

0) is using gtk in this way (ie: integrating with freeglut) a good thing
to do? Freeglut uses X11 code but it manages everything in a black box.
Have any other people had success with this combo?

1) is it kosher to user gtk_main_iteration() like this? Since I don't
need any other gtk widgets, I want to avoid using gtk_main(). 

2) I commented out the glxMakeCurrent() and gtk seems happy, although
nothing loads of course. I also added a sleep function before the load
thread launches and it works periodically but still crashes sometimes.
So what I am thinking is that some gdk events are being processed by X
after the rendering context switch. Hence, I added gdk_flush() but it
doesn't help. Is there another way to force all the gdk events to be
processed by X?

Not sure it matters but I'm using nVidia driver 97.46.

Thanks,
Daren






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