Rendering on pixmap

Hi all,

I am beginner in opengl.
I am trying to render with opengl ontop of an existing image.

In brief I am creating a pixmap and the glxpixmap
Using direct rendering in the context (otherwise X11 doesn’t like it)
with single buffer.

and then I paste my image on the pixmap generated by some routine
XPutImage(display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);

I clear the depth buffer (since the color is already set from the XPutImage)

and I start the normal rendering

at the end I do

and finally copy the image on the window
XCopyArea(display, pixmap, window, gc, 0, 0, ximage->width, ximage->height, 0, 0);

The problem now is that I get almost what I want the opengl render ontop of my ximage
but only on the top ~80% of the height.
The remaining, bottom lines show only the ximage and not the opengl render.

The effect is random. Sometimes I do get the full opengl render, but most of the time not.

I through that maybe opengl didn’t finish yet rendering
I tried instead of the glFlush, glFinish and glXWaitGL()
and all of them together, but always the same.

What am I doing wrong?

Thank you in advance