next up previous contents
Next: Allocating Color cells Up: X Windows Version 11.5 Previous: Examples

Using Colour

Windows in X on a color display always have an associated colormap, a collection of color cells (i.e. triples of R, G and B values).

On some high end displays it may be possible to interpret the contents of the colormap in more than one way. These `ways' are called Visuals. The possible classes of visual are:-

If you just use
Visual XDefaultVisual(display,screen)
to find the default Visual and use that, you can't go far wrong. Use
Colormap XDefaultColorMap(display,screen)
to get the default colormap. Colormaps are local to a particular screen and if read-only, may be shared among multiple applications.

Much hardware built today have a single color map, so the primitives are written to encourage sharing of color map entries between applications. If there is not sufficient colormap resources in the display, then some windows may not be displayed in their true colors. If you ask for colors that are named then you're more likely to be able to share an already used colorcell.

Colors can be specified by RGB values or by name. Color information is held in the following structure.

typedef struct         /* the colour structure is used to set  */
{                      /* colour cell mappings for the screen  */
    unsigned long pixel;           /* pixel value    */
    unsigned long red,green,blue;  /* intensity (0 to 65535) */
    char flags;                    /* DoRed, DoGreen, DoBlue */
    char pad;
} XColor;




Tim Love
Mon Mar 11 17:03:18 GMT 1996