pixel manipulation between buffers

I am trying to learn the concept of pixel manipulation within/between the front and back buffers. To do that I wrote a small program where

  1. draw a triangle in the first quadrant of the back buffer
  2. I swap the buffers (glSwapBuffers()
  3. I (try to) copy the triangle from the front buffer’s 1st quadrant to the the back buffer’s second quadrant (inverted).
  4. swap the buffers again

For some reason the copying process (glCopyPixels) copies the content UNDERNEATH the window (i.e the desktop) starting at the lower left
corner of the window (short program below).

I could not add the short program since the tool would not allow me. I will be glad to mail it to anyone.


Watch out, there are two different kinds of swap buffer algorithms, swap_copy and swap_exchange.
If you want to rely on the back buffer to be intact after a swap (which is a bad idea in general) you MUST get a pixelformat which has the PFD_SWAP_COPY bit set in the dwFlags field. Check it with DescribePixelFormat(), ChoosePixelFormat() is too dumb to match it.
If you have got a swap-exchange pixelformat your back buffer is undefined after each swap.

Just a hint to another pitfall: Reading pixels (copypixels, readpixels) tests the pixel ownership, that means you won’t get defined pixels (for any bit of the full vector: front, back, depth, stencil, etc.!) for window areas which are overlapped by other windows.