XColor xc; display = XOpenDisplay(0); visual = glXChooseVisual(display, DefaultScreen(display), attributeList); context = glXCreateContext (display, visual, 0, GL_FALSE); colorMap = XCreateColormap (display, RootWindow(display, visual->screen), visual->visual, AllocAll); ... if (ind < visual->colormap_size) { xc.pixel = ind; xc.red = (unsigned short)(red * 65535.0 + 0.5); xc.green = (unsigned short)(green * 65535.0 + 0.5); xc.blue = (unsigned short)(blue * 65535.0 + 0.5); xc.flags = DoRed | DoGreen | DoBlue; XStoreColor (display, colorMap, &xc); }
Caution: Do not use AllocAll on overlay visuals with transparency. If you do, XCreateColormap() fails because the transparent cell is read-only.