/** * gdk_window_set_gl_capability: * @window: the #GdkWindow to be used as the rendering area. * @glconfig: a #GdkGLConfig. * @attrib_list: this must be set to NULL or empty (first attribute of None). * * Set the OpenGL-capability to the @window. * This function creates a new #GdkGLWindow held by the @window. * attrib_list is currently unused. This must be set to NULL or empty * (first attribute of None). * * Return value: the #GdkGLWindow used by the @window if it is successful, * NULL otherwise. **/ GdkGLWindow * gdk_window_set_gl_capability (GdkWindow *window, GdkGLConfig *glconfig, const int *attrib_list) { GdkGLWindow *glwindow; GDK_GL_NOTE_FUNC (); g_return_val_if_fail (GDK_IS_WINDOW (window), NULL); g_return_val_if_fail (GDK_IS_GL_CONFIG (glconfig), NULL); if (quark_gl_window == 0) quark_gl_window = g_quark_from_static_string (quark_gl_window_string); /* If already set */ glwindow = g_object_get_qdata (G_OBJECT (window), quark_gl_window); if (glwindow != NULL) return glwindow; /* * Create GdkGLWindow */ glwindow = gdk_gl_window_new (glconfig, window, attrib_list); if (glwindow == NULL) { g_warning ("cannot create GdkGLWindow\n"); return NULL; } g_object_set_qdata_full (G_OBJECT (window), quark_gl_window, glwindow, (GDestroyNotify) g_object_unref); /* * Set a background of "None" on window to avoid AIX X server crash */ GDK_GL_NOTE (MISC, g_message (" - window->bg_pixmap = %p", (void*)gdk_window_get_background_pattern (window))); gdk_window_set_background_pattern (window, NULL); GDK_GL_NOTE (MISC, g_message (" - window->bg_pixmap = %p", (void*)gdk_window_get_background_pattern (window))); return glwindow; }
static void realize (GtkWidget *widget, gpointer data) { GLUquadricObj *qobj; static GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0}; static GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; /* * Create GdkGLWindow for widget->window. */ glwindow = gdk_gl_window_new (glconfig, widget->window, NULL); /* Set a background of "None" on window to avoid AIX X server crash */ gdk_window_set_back_pixmap (widget->window, NULL, FALSE); /* * Create OpenGL rendering context. */ if (glcontext == NULL) { glcontext = gdk_gl_context_new (GDK_GL_DRAWABLE (glwindow), NULL, TRUE, GDK_GL_RGBA_TYPE); if (glcontext == NULL) { g_print ("Connot create the OpenGL rendering context\n"); exit (1); } g_print ("The OpenGL rendering context is created\n"); } /*** OpenGL BEGIN ***/ if (!gdk_gl_drawable_gl_begin (GDK_GL_DRAWABLE (glwindow), glcontext)) return; qobj = gluNewQuadric (); gluQuadricDrawStyle (qobj, GLU_FILL); glNewList (1, GL_COMPILE); gluSphere (qobj, 1.0, 20, 20); glEndList (); glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv (GL_LIGHT0, GL_POSITION, light_position); glEnable (GL_LIGHTING); glEnable (GL_LIGHT0); glEnable (GL_DEPTH_TEST); glClearColor (1.0, 1.0, 1.0, 1.0); glClearDepth (1.0); glViewport (0, 0, widget->allocation.width, widget->allocation.height); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective (40.0, 1.0, 1.0, 10.0); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); gluLookAt (0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glTranslatef (0.0, 0.0, -3.0); gdk_gl_drawable_gl_end (GDK_GL_DRAWABLE (glwindow)); /*** OpenGL END ***/ }