Next | Prev | Up | Top | Contents | Index

Colormap Example

Here's a brief example that demonstrates how to store colors into a given colormap cell:

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.


Next | Prev | Up | Top | Contents | Index