/* $ gcc -g glxcontext-xlib.c -o glxcontext-xlib $(pkg-config --cflags --libs x11) -lGL -lGLU */ #include #include #include #include #include #include #include static int handleXError (Display * dpy, XErrorEvent * err) { return 0; } int main(int argc, char *argv[]) { Display *dpy; Window root; GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24 }; XVisualInfo *vi; XSetWindowAttributes swa; Window win; GLXContext glc; XEvent xev; dpy = XOpenDisplay(NULL); if (!dpy) { fprintf(stderr, "Cannot open display\n"); exit(0); } root = DefaultRootWindow(dpy); vi = glXChooseVisual(dpy, 0, att); if (!vi) { fprintf(stderr, "No visual found\n"); exit(0); } swa.colormap = XCreateColormap(dpy, root, vi->visual, AllocNone); win = XCreateWindow(dpy, root, 0, 0, 600, 600, 0, vi->depth, InputOutput, vi->visual, CWColormap, &swa); XMapWindow(dpy, win); XSetErrorHandler (handleXError); glc = glXCreateContext(dpy, vi, NULL, GL_FALSE); if (!glc) { printf("\n\tcannot create gl context\n\n"); exit(0); } glXIsDirect(dpy, glc); glXDestroyContext(dpy, glc); while(1) { XNextEvent(dpy, &xev); } /* while(1) */ XSync (dpy, 0); XCloseDisplay(dpy); exit(0); }