#include #include #include #include #include #include #include #include #include int main( int argc, char **argv ) { XVisualInfo *vinfo; XSetWindowAttributes swa; int glxAttrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, None }; Display *display; int screen; Window wnd; GLXContext ctx; Colormap cmap; GLubyte *pixels; display = XOpenDisplay( 0 ); if( !display ) { fprintf( stderr, "glxoutput: Can't open display '%s'.\n", getenv( "DISPLAY" ) ? getenv( "DISPLAY" ) : "" ); return 0; } screen = DefaultScreen( display ); vinfo = glXChooseVisual( display, screen, glxAttrib ); if( !vinfo ) { fprintf( stderr, "glxoutput: No acceptable GL visual available.\n" ); return 0; } fprintf( stderr, "glxoutput: Using visual 0x%x\n", (int) vinfo->visualid ); cmap = XCreateColormap( display, XRootWindow( display, vinfo->screen ), vinfo->visual, AllocNone ); swa.colormap = cmap; swa.border_pixel = 0; wnd = XCreateWindow( display, XRootWindow( display, vinfo->screen ), 0, 0, 512, 512, 0, vinfo->depth, InputOutput, vinfo->visual, CWColormap|CWBorderPixel, &swa ); XMapWindow( display, wnd ); ctx = glXCreateContext( display, vinfo, 0, True ); if( !ctx ) { fprintf( stderr, "glxoutput: Can't create OpenGL context.\n" ); return 0; } if( !glXMakeCurrent( display, wnd, ctx ) ) { fprintf( stderr, "glxoutput: Unable to attach OpenGL to our window!\n"); return 0; } pixels = malloc( 512 * 512 * 4 ); glPixelZoom( 1.0, -1.0 ); glDrawPixels( 512, 512, GL_BGRA, GL_UNSIGNED_BYTE, pixels ); glXSwapBuffers( display, wnd ); }