static int lglext_widget_get_gl_config(lua_State* L) { luaL_checktype(L, 1, LUA_TUSERDATA); Object* obj = lua_touserdata(L, 1); GdkGLConfig* ptr = gtk_widget_get_gl_config(GTK_WIDGET(obj->pointer)); object_new(L, ptr, FALSE); return 1; }
static void render_to_file (GtkButton *button, GtkWidget *widget) { GtkAllocation allocation; GdkGLConfig *glconfig; Display *xdisplay; XVisualInfo *xvinfo; GLXFBConfigSGIX fbconfig; GLXPbufferSGIX pbuffer; int pb_attrib_list[] = { GLX_LARGEST_PBUFFER_SGIX, True, GLX_PRESERVED_CONTENTS_SGIX, False, None }; int width, height; GdkGLContext *glcontext; GLXContext glxcontext; g_print ("Render to PPM file...\n"); glconfig = gtk_widget_get_gl_config (widget); xdisplay = gdk_x11_gl_config_get_xdisplay (glconfig); xvinfo = gdk_x11_gl_config_get_xvinfo (glconfig); /* * Get FBConfig. */ g_print ("- get FBConfig\n"); fbconfig = GetFBConfigFromVisualSGIX (xdisplay, xvinfo); if (!fbconfig) { g_print ("cannot get FBConfig\n"); return; } /* * Create GLXPbuffer. */ gtk_widget_get_allocation (widget, &allocation); width = allocation.width; height = allocation.height; g_print ("- create GLXPbuffer\n"); pbuffer = CreateGLXPbufferSGIX (xdisplay, fbconfig, width, height, pb_attrib_list); if (!pbuffer) { g_print ("cannot create GLXPbuffer\n"); return; } /* * Render. */ glcontext = gtk_widget_get_gl_context (widget); glxcontext = gdk_x11_gl_context_get_glxcontext (glcontext); glXMakeCurrent (xdisplay, pbuffer, glxcontext); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glCallList (1); glFlush (); /* * Write to file. */ write_file ("simple-pbuffer-sgix.ppm", width, height); /* * Destroy GLXPbuffer. */ glXMakeCurrent (xdisplay, None, NULL); g_print ("- destroy GLXPbuffer\n"); DestroyGLXPbufferSGIX (xdisplay, pbuffer); g_print ("Done.\n\n"); }