Re: [GtkGLExt] Infuriating! gtk_widget_get_gl_context() and gtk_widget_get_gl_drawable() returns NULL!



Do you call gtk_widget_set_gl_capability before any other GL related
action?

Le vendredi 08 février 2008 à 10:08 -0800, Rob Stoddard a écrit :
> This is my fourth venture into GtkGL land...  All other times have been 
> smooth sailing, but now I get trouble.
> 
> 
> I am trying to make a mod to the gtk-vnc widget which will allow me to 
> resize the widget.   I chose to use gtkglext and OpenGL to do the 
> resizing.  However, there are two incidents of note here...  First, for 
> some strange reason, the on_configure_event is being called before 
> on_realize.   Is there any reason why this would happen?   Second, when 
> I call gtk_widget_get_gl_context() and gtk_widget_get_gl_drawable(),  
> they both return NULL.   I am initializing the GL library in the 
> application. 
> 
> When I run gdk_gl_context_new I get the following assertion:
> (lt-gvncviewer:2855): GdkGLExt-CRITICAL **: gdk_gl_context_new: 
> assertion `GDK_IS_GL_DRAWABLE (gldrawable)' failed
> even though the widget that I am using is inherited off of a GtkDrawingArea.
> 
> 
> When I try to call gdk_gl_drawable_gl_begin I get the following assertion:
> (lt-gvncviewer:1750): GdkGLExt-CRITICAL **: gdk_gl_drawable_gl_begin: 
> assertion `GDK_IS_GL_DRAWABLE (gldrawable)' failed
> 
> The code I am using for my realize and configure event handlers is:
> 
> 
> static void realize(VncDisplay *obj)
> {
>         printf("Realizing display.\n");
>         GtkWidget *widget = GTK_WIDGET(obj);
> 
> printf("Beginning OGL init.\n");
>   /* Try double-buffered visual */
>   GdkGLConfig *glconfig = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGB    |
>                                                      GDK_GL_MODE_DEPTH  |
>                                                      GDK_GL_MODE_DOUBLE);
>   if (glconfig == NULL)
>     {
>       g_print ("*** Cannot find the double-buffered visual.\n");
>       g_print ("*** Trying single-buffered visual.\n");
> 
>       /* Try single-buffered visual */
>       glconfig = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGB   |
>                                             GDK_GL_MODE_DEPTH);
>       if (glconfig == NULL)
>         {
>           g_print ("*** No appropriate OpenGL-capable visual found.\n");
>           exit (1);
>         }
>     }
> printf("beginning OGL+widget stuff with widget %p.\n", widget);
>   obj->priv->glcontext = gdk_gl_context_new(widget, NULL, True, GL_RGBA);
>   obj->priv->gldrawable = gtk_widget_get_gl_drawable (widget);
> 
> printf("OGL begin(%p, %p).\n", obj->priv->gldrawable, obj->priv->glcontext);
>   /*** OpenGL BEGIN ***/
>   if (!gdk_gl_drawable_gl_begin (obj->priv->gldrawable, 
> obj->priv->glcontext))
>     exit(-1);
> 
> printf("Starting in on the gl code.\n");
> 
>         glMatrixMode(GL_PROJECTION);
>         glLoadIdentity();
>         glOrtho(0, 1, 1, 0, 1, -1);
>         glMatrixMode(GL_MODELVIEW);
>         glLoadIdentity();
>         glDisable(GL_DEPTH_TEST);
>         glActiveTexture(GL_TEXTURE0);
>         glEnable(GL_TEXTURE_RECTANGLE_ARB);
>         glGenTextures(1, &obj->priv->frametex);
>         obj->priv->displist = glGenLists(1);
>         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
> printf("tex id is %d\n", obj->priv->frametex);
> 
>         glActiveTexture(GL_TEXTURE0);
> 
> glClearColor(0xff, 0xff, 0x00, 0x00);
> OGLerror("glClearColor or earlier");
> }
> 
> 
> 
> static void on_configure(VncDisplay *obj)
> {
>         printf("On_configure.\n");
>         GtkWidget *widget = GTK_WIDGET(obj);
>         int width = widget->allocation.width;
>         int height = widget->allocation.height;
> 
> printf("on configure OGL begin(%p, %p).\n", obj->priv->gldrawable, 
> obj->priv->glcontext);
>         if(obj->priv->gldrawable == NULL || obj->priv->glcontext == NULL)
>                 return 0;
> 
>   if (!gdk_gl_drawable_gl_begin (obj->priv->gldrawable, 
> obj->priv->glcontext))
>     return 0;
> 
> printf("calling viewport with %dx%d\n", width, height);
>         glViewport(0, 0, width, height);
>         glBindTexture(GL_TEXTURE_RECTANGLE_ARB, obj->priv->frametex);
> OGLerror("bind");
>         glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, 
> GL_CLAMP_TO_EDGE);
>         glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, 
> GL_CLAMP_TO_EDGE);
> OGLerror("tex param");
>         glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, width, 
> height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
> OGLerror("tex image 2d");
> 
>         glNewList(obj->priv->displist, GL_COMPILE);
>         {
>                 glBegin(GL_QUADS);
>                 glTexCoord2f(0.0f, height);
>                 glVertex2f(0.0f, 1.0f);
> 
>                 glTexCoord2f(width, height);
>                 glVertex2f(1.0f, 1.0f);
> 
>                 glTexCoord2f(width, 0.0f);
>                 glVertex2f(1.0f, 0.0f);
> 
>                 glTexCoord2f(0.0f, 0.0f);
>                 glVertex2f(0.0f, 0.0f);
>                 glEnd();
>         }
>         glEndList();
> OGLerror("list creation and compilation");
> 
>         gdk_gl_drawable_gl_end (obj->priv->gldrawable);
> }
> 
> 
> 
> The error is easy to recreate, all one must do is download the gtk-vnc 
> package, add the gtk_gl_init function to the examples/gvncviewer.c 
> file's main() function, add the code above to the src/vncdisplay.c file, 
> stick the appropriate g_signal_connect calls.
> 
> 
> 
> Thank you for any assistance you may give in this matter.
> 
> R Stoddard
> 
> _______________________________________________
> gtkglext-list mailing list
> gtkglext-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkglext-list
> 



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