#include #include #include #include int main() { static int width = 100; static int height = 100; Display* DisplayId = XOpenDisplay(NULL); if(!DisplayId) { printf("couldn't open display\n"); return 1; } XSynchronize(DisplayId, true); static int attributes[50]; int index = 0; attributes[index++] = GLX_DRAWABLE_TYPE; attributes[index++] = GLX_PBUFFER_BIT; attributes[index++] = GLX_RENDER_TYPE; attributes[index++] = GLX_RGBA_BIT; attributes[index++] = GLX_RED_SIZE; attributes[index++] = 1; attributes[index++] = GLX_GREEN_SIZE; attributes[index++] = 1; attributes[index++] = GLX_BLUE_SIZE; attributes[index++] = 1; attributes[index++] = GLX_DEPTH_SIZE; attributes[index++] = 1; attributes[index++] = None; int numfb; GLXFBConfig* fb = glXChooseFBConfig(DisplayId, DefaultScreen(DisplayId), attributes, &numfb); if(!fb) { printf("couldn't find FBConfig\n"); return 1; } GLXContext ContextId = glXCreateNewContext(DisplayId, fb[0], GLX_RGBA_TYPE, NULL, true); if(!ContextId) { printf("couldn't make context\n"); return 1; } int pbuffer_atts [] = { GLX_PBUFFER_WIDTH, width, GLX_PBUFFER_HEIGHT, height, 0 }; GLXPbuffer Pbuffer = glXCreatePbuffer(DisplayId, fb[0], pbuffer_atts); if(Pbuffer == None) { printf("couldn't make pbuffer\n"); return 1; } XFree(fb); glXMakeCurrent(DisplayId, Pbuffer, ContextId); // sometimes get an X error here from Mesa w/ DRI glXDestroyPbuffer(DisplayId, Pbuffer); glXDestroyContext(DisplayId, ContextId); return 0; }