static gboolean expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data) { GtkAllocation allocation; GdkGLContext *glcontext = gtk_widget_get_gl_context (widget); GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget); gtk_widget_get_allocation (widget, &allocation); /*** OpenGL BEGIN ***/ if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) return FALSE; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Sync. */ gdk_gl_drawable_wait_gl (gldrawable); /* GDK rendering. */ gdk_draw_rectangle (GDK_DRAWABLE (gldrawable), gtk_widget_get_style (widget)->black_gc, TRUE, allocation.width/10, allocation.height/10, allocation.width*8/10, allocation.height*8/10); /* Sync. */ gdk_gl_drawable_wait_gdk (gldrawable); glCallList (1); glFlush (); gdk_gl_drawable_gl_end (gldrawable); /*** OpenGL END ***/ return TRUE; }
static gboolean configure_event (GtkWidget *widget, GdkEventConfigure *event, gpointer data) { GdkGLDrawable *gldrawable; static gboolean is_initialized = FALSE; /* * Create an OpenGL off-screen rendering area. */ if (pixmap != NULL) g_object_unref (G_OBJECT (pixmap)); pixmap = gdk_pixmap_new (widget->window, widget->allocation.width, widget->allocation.height, -1); /* * Set OpenGL-capability to the pixmap */ gldrawable = GDK_GL_DRAWABLE (gdk_pixmap_set_gl_capability (pixmap, glconfig, NULL)); /* * Create OpenGL rendering context (not direct). */ if (glcontext == NULL) { glcontext = gdk_gl_context_new (gldrawable, NULL, FALSE, GDK_GL_RGBA_TYPE); if (glcontext == NULL) { g_print ("Connot create the OpenGL rendering context\n"); if (gtk_main_level () != 0) gtk_main_quit (); return TRUE; } g_print ("The OpenGL rendering context is created\n"); } /*** OpenGL BEGIN ***/ if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) goto NO_GL; if (!is_initialized) { init (); is_initialized = TRUE; } glViewport (0, 0, widget->allocation.width, widget->allocation.height); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Sync. */ gdk_gl_drawable_wait_gl (gldrawable); /* GDK rendering. */ gdk_draw_rectangle (GDK_DRAWABLE (gldrawable), widget->style->black_gc, TRUE, widget->allocation.width/10, widget->allocation.height/10, widget->allocation.width*8/10, widget->allocation.height*8/10); /* Sync. */ gdk_gl_drawable_wait_gdk (gldrawable); glCallList (1); glFlush (); gdk_gl_drawable_gl_end (gldrawable); /*** OpenGL END ***/ NO_GL: return TRUE; }