#include #include #include /* build: gcc -Wall simple.c -o simple $(pkg-config --cflags --libs gl x11) run: for i in {0..300}; do (./simple &); done */ int main(int argc, char *argv[]) { int width = 128; int height = 128; int glAttribs[] = { GLX_RGBA, GLX_DEPTH_SIZE, 1, None }; Display *dpy; XVisualInfo *visInfo; int scrn; Window root; Window win; XSetWindowAttributes winAttribs; unsigned long winAttribsMask; GLXContext glCtx; dpy = XOpenDisplay(NULL); if (!dpy) { fprintf(stderr, "Couldn't open default display\n"); return 1; } scrn = DefaultScreen(dpy); root = RootWindow(dpy, scrn); visInfo = glXChooseVisual(dpy, scrn, glAttribs); if (!visInfo) { fprintf(stderr, "Failed to select visual\n"); return 1; } glCtx = glXCreateContext(dpy, visInfo, 0, True); if (!glCtx) { fprintf(stderr, "Couldn't create GL context\n"); return 1; } winAttribs.border_pixel = 0; winAttribs.colormap = XCreateColormap(dpy, root, visInfo->visual, AllocNone); winAttribs.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; winAttribsMask = CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow(dpy, root, 0, 0, width, height, 0, visInfo->depth, InputOutput, visInfo->visual, winAttribsMask, &winAttribs); XMapWindow(dpy, win); glXMakeCurrent(dpy, win, glCtx); printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); while (1) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glBegin(GL_LINE); glVertex2f(-1.0, -1.0); glVertex2f( 1.0, -1.0); glVertex2f(1.0, 1.0); glVertex2f(-1.0, 1.0); glEnd(); glFlush(); //same result with glXSwapBuffers(dpy, win); } return 0; }