I have a small application written in C running on Linux, that creates a simple X window, with a double buffer, writes some pixels and then flushes.
I notice that if I don't add a delay the picture flushed does not appear, what am I making wrong here?
The small application is basically:
Display * dsp = XOpenDisplay(NULL);
Window win = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp), 0, 0, SIZ + 1, SIZ + 1, 1, 0, 0xffffff);
XMapWindow(dsp, win);
GC gc = XCreateGC(dsp, win, 0, NULL);
Pixmap double_buffer = XCreatePixmap(dsp, win, SIZ + 1, SIZ + 1, 24);
// write some pixels:
XSetForeground(dsp, gc, 0);
snprintf(buf, 2, "%c", ord);
text.chars = buf;
text.nchars = 1;
text.delta = text.font = 0;
XDrawText(dsp, double_buffer, gc, i, j, &text, 1);
// switch buffers:
XCopyArea(dsp, double_buffer, win, gc, 0, 0, SIZ, SIZ, 0, 0);
sleep(1); /* if I don't add this nothing is shown */
XFlush(dsp);
My machine is a 64 bit Linux Debian with openbox and a compositor (compton). For X11 I'm using libx11-xcb-dev and the intel driver, with no dedicated GPU.
X11 don't work this simple way. It is event-driven. You should at least wait for an Expose
event for the window to make some drawing on it. See this Equivalent of "Invalidate Rect" / "WM_PAINT" in X11 for example.