I've successfully written a lot of C programs over the years using Xlib, for displaying a (static) plot of various curves I'm studying. But for the first time, I needed to make one of those curves (plotted wrt position x, say) move with time t (like a wave propagating in the direction x, with some velocity v as time progresses).

I thought I could just use a usleep function (with a delay of about 1/20 second, to get movies-like motion) between successive snapshots of the evolution of the curve, but when I do an XFlush after doing a bunch of incremental DrawLines to generate a given snapshot of the curve, the display of the snapshot doesn't get displayed instantaneously ... I see the image get drawn over a fraction of a second, enough to be very noticeable ... slow enough per snapshot to greatly exceed the 1/20 second time-lapse between the snapshots, which will mess up the motion-picture effect, I think. (If I do a sleep(2) after all the DrawLines, but before the XFlush, Xlib DOES buffer those DrawLines, and doesn't start the display of the curve until the XFlush, so the problem ISN'T caused by each DrawLine being displayed separately ... the buffering seems to be working as advertised).

The Xlib Programming Manual says that animation may require "double buffering", writing the whole set of DrawLines for a snapshot into a pixmap, and then copying that pixmap into an empty window. That sounded like it might solve my problem (assuming the copy was sufficiently quick), but when I tried to do it for a very trivial test case, I got execution errors. I couldn't find any examples in that book specifically showing how to use a pixmap in that way, and I had to do some guessing about how to do it (and apparently I guessed wrong at least once).

Does anyone have a very simple fragment of code that shows how it's done? I'm looking for bare-bones sort of code fragment ... nothing fancy or generic or portable, etc.