Screenshot class doesn't always capture properly

I’ve noticed some strange behavior with the screenshot utility class. I have a program that has various modules rendering different scenes, but they share a common GLEventListener (i.e. each module renders different geometry, but they have the same windowing, setup, and GUI code). In that listener, if a flag is set, the screenshot is taken, and if not, the normal render occurs. This works fine for some of the modules in certain modes. But in one case, the screenshots came out either blank (the background color), or heavily scrambled (i.e. the parts of the frame buffer were shifted to the wrong place, and other areas were blank, etc). I managed to solve the problem by rendering the scene once immediately before the screenshot is taken, but I don’t see why this is necessary… stranger still, this problem only occurs with one of the modules… is there a known issue with the screenshot class(perhaps with the accumulation buffer or programmable shaders, both of which are used, although in both modules)?

The Screenshot class uses the current read buffer (glReadBuffer) which defaults to GL_BACK for double-buffered contexts. This means that you should perform a full render, without causing a buffer swap, just before using the Screenshot class. I wouldn’t recommend switching the read buffer to GL_FRONT because on most OSs if you overlap the window on-screen you will lose that portion of the results which are read back.

Ah, that would explain it… it’s still strange that it works properly for some of the modules and not others, but with this in mind, it certainly seems possible. Thanks for the explanation.