/* * Copyright (C) 2010 Nick Bowler * * License WTFPL2: Do What The Fuck You Want To Public License, version 2. * This is free software: you are free to do what the fuck you want to. * There is NO WARRANTY, to the extent permitted by law. * * In case the above is not acceptable, you may alternately choose the terms * of the MIT license: http://opensource.org/licenses/mit-license.php. */ #include #include #include #include #ifndef M_PI # define M_PI 3.14159265358979323844 #endif static void resize(int w, int h) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, 0, w, h); glOrtho(-1.2, 1.2, -1.2, 1.2, -1, 1); glMatrixMode(GL_MODELVIEW); } static void render(double theta) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_LINE_LOOP); glVertex2d(0, 0); glVertex2d(cos(theta-0.1), sin(theta-0.1)); glVertex2d(cos(theta+0.1), sin(theta+0.1)); glEnd(); glFinish(); } int main(int argc, char **argv) { int rgb_attribs[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None }; Display *dpy; XVisualInfo *vi; GLXContext ctx1, ctx2; Window win, win1, win2; XSetWindowAttributes attr; double theta = 0; dpy = XOpenDisplay(NULL); vi = glXChooseVisual(dpy, DefaultScreen(dpy), rgb_attribs); attr.colormap = XCreateColormap(dpy, RootWindow (dpy, vi->screen), vi->visual, AllocNone); win = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, 600, 300, 0, vi->depth, InputOutput, vi->visual, CWColormap, &attr); XMapWindow(dpy, win); win1 = XCreateWindow(dpy, win, 0, 0, 300, 300, 0, vi->depth, InputOutput, vi->visual, CWColormap, &attr); XSelectInput(dpy, win1, ExposureMask); XMapWindow(dpy, win1); win2 = XCreateWindow(dpy, win, 300, 0, 300, 300, 0, vi->depth, InputOutput, vi->visual, CWColormap, &attr); XSelectInput(dpy, win2, ExposureMask); XMapWindow(dpy, win2); ctx1 = glXCreateContext(dpy, vi, NULL, True); ctx2 = glXCreateContext(dpy, vi, NULL, True); while (1) { /* discard pending events. */ XSync(dpy, True); glXMakeCurrent(dpy, win1, ctx1); resize(300, 300); render(theta); glXSwapBuffers(dpy, win1); /* recreate context to try and trigger lockup */ glXDestroyContext(dpy, ctx2); ctx2 = glXCreateContext(dpy, vi, NULL, True); glXMakeCurrent(dpy, win2, ctx2); resize(300, 300); render(-(theta+M_PI)); glXSwapBuffers(dpy, win2); theta = remainder(theta + M_PI/180, 2*M_PI); } return 0; }