#include #include #include #include #include typedef GLXContext (*glXCreateContextAttribsARBProc)(Display *, GLXFBConfig, GLXContext, int, const int *); #ifdef VSYNC typedef int (*glXSwapIntervalMESAProc)(int); #endif int main(int argc, char **argv) { Display *display = XOpenDisplay(NULL); static int visual_attribs[] = { GLX_X_RENDERABLE, True, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_DOUBLEBUFFER, True, None }; int fbcount; GLXFBConfig* fbc = glXChooseFBConfig(display, DefaultScreen(display), visual_attribs, &fbcount); XVisualInfo *vi = glXGetVisualFromFBConfig(display, fbc[0]); XSetWindowAttributes swa; Colormap cmap; cmap = XCreateColormap(display, RootWindow(display, vi->screen), vi->visual, AllocNone); swa.colormap = cmap; swa.background_pixmap = None; swa.border_pixel = 0; swa.event_mask = StructureNotifyMask; Window window = XCreateWindow(display, RootWindow(display, vi->screen), 100, 100, 800, 600, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask, &swa); XFree(vi); XStoreName(display, window, "OpenGL"); glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB((const GLubyte *)"glXCreateContextAttribsARB"); int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 2, None }; GLXContext context = glXCreateContextAttribsARB(display, fbc[0], 0, True, attribs); free(fbc); glXMakeCurrent(display, window, context); #ifdef VSYNC glXSwapIntervalMESAProc glXSwapIntervalMESA = 0; glXSwapIntervalMESA = (glXSwapIntervalMESAProc)glXGetProcAddressARB((const GLubyte *)"glXSwapIntervalMESA"); glXSwapIntervalMESA(1); #endif int i; for (i = 0; i < 1000; i++) { #ifndef NOSWAP glXSwapBuffers(display, window); #ifdef SLEEP sleep(1); #endif #endif fprintf(stderr, "loop\n"); } glXMakeCurrent(display, 0, 0); glXDestroyContext(display, context); XDestroyWindow(display, window); XFreeColormap(display, cmap); XCloseDisplay(display); return 0; }