+Visual *
+createVisual(bool doubleBuffer, Profile profile) {
+ if (profile != PROFILE_COMPAT &&
+ profile != PROFILE_CORE) {
+ return NULL;
+ }
+
+ GlxVisual *visual = new GlxVisual;
+
+ if (glxVersion >= 0x0103) {
+ Attributes<int> attribs;
+ attribs.add(GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT);
+ attribs.add(GLX_RENDER_TYPE, GLX_RGBA_BIT);
+ attribs.add(GLX_RED_SIZE, 1);
+ attribs.add(GLX_GREEN_SIZE, 1);
+ attribs.add(GLX_BLUE_SIZE, 1);
+ attribs.add(GLX_ALPHA_SIZE, 1);
+ attribs.add(GLX_DOUBLEBUFFER, doubleBuffer ? GL_TRUE : GL_FALSE);
+ attribs.add(GLX_DEPTH_SIZE, 1);
+ attribs.add(GLX_STENCIL_SIZE, 1);
+ attribs.end();
+
+ int num_configs = 0;
+ GLXFBConfig * fbconfigs;
+ fbconfigs = glXChooseFBConfig(display, screen, attribs, &num_configs);
+ assert(num_configs && fbconfigs);
+ visual->fbconfig = fbconfigs[0];
+ assert(visual->fbconfig);
+ visual->visinfo = glXGetVisualFromFBConfig(display, visual->fbconfig);
+ assert(visual->visinfo);
+ } else {
+ Attributes<int> attribs;
+ attribs.add(GLX_RGBA);
+ attribs.add(GLX_RED_SIZE, 1);
+ attribs.add(GLX_GREEN_SIZE, 1);
+ attribs.add(GLX_BLUE_SIZE, 1);
+ attribs.add(GLX_ALPHA_SIZE, 1);
+ if (doubleBuffer) {
+ attribs.add(GLX_DOUBLEBUFFER);
+ }
+ attribs.add(GLX_DEPTH_SIZE, 1);
+ attribs.add(GLX_STENCIL_SIZE, 1);
+ attribs.end();