[comp.windows.x] double buffering

mouse@LARRY.MCRCIM.MCGILL.EDU (der Mouse) (06/04/90)

[ This is a little old; I hope it's helpful to someone. ]

> I am writing an X application that does animation, and I would like
> to use double buffering to eliminate flicker.  Is there a prefered
> way to do this in X?

I suppose the preferred way would be to use the double-buffering
extension.  But I suspect that if the server has enough bitplanes and a
modifiable colormap visual, colormap fiddling would be better.

> I want this to work with generic 8 bit color servers.

You'll probably find that most color servers offer a PseudoColor
visual, which is the simplest way of making this work.  (You can also
do it with other visuals, in particular GrayScale and DirectColor.)

> Right now, I am planning on grabbing a bunch of colors, then finding
> four of them that differ in exactly two bits, but this seems pretty
> gross.

Yup.  Particularly when you can use XAllocColorCells to ask for four
colors that have exactly the relationship you need:

unsigned long int planes[2];
unsigned long int basecolor;

XAllocColorCells(disp,cmap,False,&planes[0],2,&basecolor,1);

If it succeeds (remember to check the return code!), this will allocate
four colors with the relationship you need.  (Of course, basecolor will
be the bits they have in common and planes[0] and planes[1] will be the
bits that distinguish them from one another.)  According to the Xlib
documentation I have, this routine works for any modifiable-colormap
visual (of course, with a read-only colormap, you can't do this sort of
colormap-based double-buffering anyway).

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu