#include #include #include #include #include #include #include // // gcc -g -Wall -o makecurrenttest makecurrenttest.c -lX11 -lGL // static Window make_rgb_db_window( Display *dpy, XVisualInfo *visinfo, unsigned int width, unsigned int height ) { int scrnum; XSetWindowAttributes attr; unsigned long mask; Window root; Window win; scrnum = DefaultScreen( dpy ); root = RootWindow( dpy, scrnum ); /* window attributes */ attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow( dpy, root, 0, 0, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr ); return win; } int main() { int i; // Open the display Display *dpy = XOpenDisplay(NULL); assert(dpy); int attrib[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None }; XVisualInfo *visinfo; visinfo = glXChooseVisual( dpy, DefaultScreen(dpy), attrib ); if (!visinfo) { printf("Error: couldn't get an RGB, Double-buffered visual\n"); assert(0); } // Create the window Window w = make_rgb_db_window(dpy,visinfo,200,100); // Map the window XMapWindow(dpy, w); XFlush(dpy); for (i=0; i < 2; i++) { // Create context GLXContext ctx = glXCreateContext(dpy, visinfo, NULL, True ); if (!ctx) { printf("Error: glXCreateContext failed\n"); assert(0); } // Make current glXMakeCurrent(dpy, w, ctx); // Destroy context glXDestroyContext(dpy, ctx); XFlush(dpy); } return 0; }