#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 attribs[] = { GLX_RGBA, GLX_DEPTH_SIZE, 1, None }; Display *dpy; XVisualInfo *visinfo; Pixmap p; GLXPixmap g; GLXContext glCtx; dpy = XOpenDisplay(NULL); if (!dpy) { fprintf(stderr, "Couldn't open default display\n"); return 1; } visinfo = glXChooseVisual(dpy, DefaultScreen(dpy), attribs); 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; } p = XCreatePixmap(dpy, DefaultRootWindow(dpy), width, height, visinfo->depth); g = glXCreateGLXPixmap(dpy, visinfo, p); if (!glXMakeCurrent(dpy, g, glCtx)) { fprintf(stderr, "Failed to make context current\n"); return 1; } printf("Depth: %d, GL_RENDERER = %s\n", visinfo->depth, (char *) glGetString(GL_RENDERER)); glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); while (1) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); glVertex2i(0, 0); glEnd(); glFlush(); // same adding glXWaitX(); } return 0; }