/* * 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 #include static void resize(int w, int h) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, 0, w, h); glOrtho(0, 1, 0, 1, -1, 1); glMatrixMode(GL_MODELVIEW); } static void render(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_LINE_LOOP); glVertex2d(0.1, 0.1); glVertex2d(0.9, 0.1); glVertex2d(0.9, 0.9); glVertex2d(0.1, 0.9); glEnd(); } 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 ctx; Window win; XSetWindowAttributes attr; int screen_width, screen_height; int width = 300, height = 300; int x, y, w, h; int state = 0; int i; dpy = XOpenDisplay (NULL); vi = glXChooseVisual (dpy, DefaultScreen (dpy), rgb_attribs); screen_width = WidthOfScreen (ScreenOfDisplay(dpy, DefaultScreen (dpy))); screen_height = HeightOfScreen (ScreenOfDisplay(dpy, DefaultScreen (dpy))); x = y = 0; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "--single") == 0) { rgb_attribs[7] = None; } else if (strcmp(argv[i], "--offset") == 0) { x = y = 1; } } attr.colormap = XCreateColormap (dpy, RootWindow (dpy, vi->screen), vi->visual, AllocNone); attr.border_pixel = 0; attr.override_redirect = True; win = XCreateWindow (dpy, DefaultRootWindow (dpy), x, y, width, height, 0, vi->depth, InputOutput, vi->visual, CWOverrideRedirect | CWBorderPixel | CWColormap, &attr); XMapWindow (dpy, win); ctx = glXCreateContext (dpy, vi, NULL, True); XFree (vi); w = width, h = height; while (1) { glXMakeCurrent (dpy, win, ctx); resize(w, h); render(); if (rgb_attribs[7]) glXSwapBuffers (dpy, win); else glFinish(); glXMakeCurrent (dpy, 0, 0); if ((state = !state)) w = screen_width, h = screen_height; else w = width, h = height; XResizeWindow (dpy, win, w, h); } return 0; }