Vertically flipped images with Screenshot

I recently discovered that the Screenshot class was producing vertically flipped images on some configurations.

It only happens under Windows, with the GLJPanel and when pbuffers are not supported (when using Windows through VMware for example or with some old intel GC).

If you are experiencing such a bug here is a workaround I found by looking at the GLJPanel source code. Actually, the GLJPanel is also making some kind of screenShot from its offscreen buffer and display it on a JPanel.

Instead of doing

BufferedImage img = Screenshot.readToBufferedImage(getWidth(), getHeight());

do


// might unecessary flip the image
BufferedImage img = Screenshot.readToBufferedImage(getWidth(), getHeight());

// check if it was the case
boolean needFlip;
try {
  // raises an exception if hardware acceleration is on
  needFlip = !((GLContextImpl)GLContext.getCurrent()).offscreenImageNeedsVerticalFlip();
} catch (GLException e) {
  // hardware acceleration is on
  needFlip = false;
}
if (needFlip) {
  // flip it back
  ImageUtil.flipImageVertically(img);
}


And if you were using Screenshot.writeToFile method, just add ImageIO.write(…) to export the above image.

I also made a bug report for this issue:
https://jogl.dev.java.net/issues/show_bug.cgi?id=367

Does it happen with GLCanvas?

No, it only happens with the GLJPanel.
It’s maybe why the bug has not been noticed until now.

Maybe you’re right. Most of the JOGL users use GLCanvas to get better performance everywhere.