[GtkGLExt] win32 pixmap and drawing area, share context



   I'm having troubles sharing context between a glpixmap
and drawing area. It's works great in linux, and mac
os x, but in win32 it's imposible.


 The problem is in the events of the drawing area. It's looks like a
bug.

here is a sample code, an the error output in the windows console.

-------------------------------------------------------
#include <gtk/gtk.h>
#include <gtk/gtkgl.h>
#include <GL/gl.h>


void
on_gl_area_realize (GtkWidget *widget,
      gpointer   data)
{
 
 GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
 GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);

 
 /*** OpenGL BEGIN ***/
 if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
  return;

 glClearColor (0.5, 0.5, 0.8, 1.0);
 glClearDepth (1.0);

 glEnable (GL_DEPTH_TEST);
 glEnable (GL_CULL_FACE);
 glShadeModel (GL_SMOOTH);
 glEnable (GL_NORMALIZE);

 gdk_gl_drawable_gl_end (gldrawable);
 /*** OpenGL END ***/
}

gboolean
on_gl_area_configure (GtkWidget         *widget,
        GdkEventConfigure *event,
        gpointer           data)
{
 GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
 GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);

 GLfloat w = widget->allocation.width;
 GLfloat h = widget->allocation.height;
 GLfloat aspect;

 /*** OpenGL BEGIN ***/
 if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
  return FALSE;

  glViewport (0, 0, (int)w, (int)h);

 glMatrixMode (GL_PROJECTION);
 glLoadIdentity ();
  if (w > h) {
   aspect = w / h;
   glFrustum (-aspect, aspect, -1.0, 1.0, 2.0, 60.0);
 
 } else {
   aspect = h / w;
   glFrustum (-1.0, 1.0, -aspect, aspect, 2.0, 60.0);
  }
 glMatrixMode (GL_MODELVIEW);

 gdk_gl_drawable_gl_end (gldrawable);
 /*** OpenGL END ***/

 return TRUE;
}

gboolean
on_gl_area_expose (GtkWidget      *widget,
     GdkEventExpose *event,
     gpointer        data)
{
 GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
 GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);
 
 
 /*** OpenGL BEGIN ***/
 if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
  return FALSE;

 g_print( ".");
 
 
  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 glLoadIdentity ();

 glBegin( GL_TRIANGLES );
 {
  glColor3f( 1.0f, 0.0f, 0.0f );

  glVertex3f( 100.0f, 100.0f, 100.0f );
  glVertex3f( 0.0f, 100.0f, 100.0f );
  glVertex3f( 0.0f, 0.0f, -100.0f );
 }
 glEnd();
 
 
 
 /* Swap buffers. */
 if (gdk_gl_drawable_is_double_buffered (gldrawable)) {
  gdk_gl_drawable_swap_buffers (gldrawable);
 
 } else {
  glFlush ();
 }
 
 gdk_gl_drawable_gl_end (gldrawable);
 /*** OpenGL END ***/
 
 return TRUE;
}


 
int
main( int argc, char *argv[] )
{
 GdkPixmap* pixmap;
 GdkGLPixmap*    gl_pixmap;
 GtkWidget* win;
 GtkWidget* gl_area;
 gboolean b;
 GdkGLConfig* gl_config;
 GdkGLContext* gl_context;
 GdkGLDrawable* gl_drawable;
    
 
 gtk_init( &argc, &argv );
 gtk_gl_init( &argc, &argv );
    
 
 // Creation of pixbuf offscreen render.
 pixmap = gdk_pixmap_new( NULL,
     256,
     256,
     24 );
 
 gl_config = gdk_gl_config_new_by_mode( (GdkGLConfigMode)
( GDK_GL_MODE_RGBA  ));
 gl_pixmap = gdk_pixmap_set_gl_capability( pixmap,
        gl_config,
        NULL );
 
 gl_drawable = gdk_pixmap_get_gl_drawable( pixmap );
 gl_context = gdk_gl_context_new( gl_drawable, 
      NULL,
      FALSE, 
      GDK_GL_RGBA_TYPE ); 
 
 gdk_gl_drawable_gl_begin( gl_drawable, gl_context );
    
 // .. use of offscreen ...
 gdk_gl_drawable_gl_end( gl_drawable );
 
 
 
 //creation of the gl window.
 win = gtk_window_new( GTK_WINDOW_TOPLEVEL );
 gtk_window_set_title( GTK_WINDOW( win ), "GtkGLExtTest" );
 
 gl_area = gtk_drawing_area_new();
 gtk_widget_set_size_request( gl_area, 300, 300 );
 b = gtk_widget_set_gl_capability( gl_area,
       gl_config,
       gl_context,  // Share list with
       TRUE,
       GDK_GL_RGBA_TYPE );
 
 g_print( "gl_area drawing gl capability = %d\n", b );
 
 gtk_container_add( GTK_CONTAINER( win ), gl_area );


 //---- Callbacks ----
 g_signal_connect( G_OBJECT(gl_area), "configure_event",
     G_CALLBACK( on_gl_area_configure ), 0 );

 g_signal_connect_after( G_OBJECT(gl_area), "realize",
    G_CALLBACK( on_gl_area_realize ), 0 );

 g_signal_connect( G_OBJECT(gl_area), "expose_event",
     G_CALLBACK( on_gl_area_expose ), 0 ); 



 gtk_widget_show( gl_area );
 gtk_widget_show( win );    
 
 gtk_main();
}

-------------------------------------------------------
Windows output:

(test2.exe:1244): GtkGLExt-WARNING **: cannot create GdkGLContext


(test2.exe:1244): GdkGLExt-CRITICAL **: file gdkglwindow-win32.c: line
297 
(gdk_gl_window_impl_win32_make_context_current): assertion 
`GDK_IS_GL_CONTEXT_IMPL_WIN32 (glcontext)' failed

(test2.exe:1244): GtkGLExt-WARNING **: cannot create GdkGLContext


(test2.exe:1244): GdkGLExt-CRITICAL **: file gdkglwindow-win32.c: line
297 
(gdk_gl_window_impl_win32_make_context_current): assertion 
`GDK_IS_GL_CONTEXT_IMPL_WIN32 (glcontext)' failed

(test2.exe:1244): GtkGLExt-WARNING **: cannot create GdkGLContext


(test2.exe:1244): GdkGLExt-CRITICAL **: file gdkglwindow-win32.c: line
297 
(gdk_gl_window_impl_win32_make_context_current): assertion 
`GDK_IS_GL_CONTEXT_IMPL_WIN32 (glcontext)' failed







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