Offscreen rendering revisited

Hi,

I’m revisiting a topic from three months ago. I’ve been trying to incorporate the advice I got at this forum at get it to work on my own - and failed!!!

I’m working on a scientific application which shows the evolution of a shape. Every once in a while I want to be able to snap a picture of what’s going on. I don’t want to overload you, potential helpers, with code so I will just present the code for my takeAPicture procedure (with comments) and may be you will be able to spot something. I am very happy to post more code.

Many thanks in advance for any advice.

public BufferedImage takeAPicture(int inWidth, int inHeight) {

if (myOffScreenBuffer == null) { // class member elem
  GLCapabilities pbCaps = new GLCapabilities();
  pbCaps.setDoubleBuffered(false);
  myOffScreenBuffer = myCanvas3D.createOffscreenDrawable(pbCaps, inWidth, inHeight);
  myOffScreenBuffer.addGLEventListener(new OffScreenGLEventListener());

// I have a hard time getting init() to be called in
// OffScreenGLEventListener. I have to resize the live
// window, call takeAPicture again, and only then it
// gets called.

}

BufferedImage pbImage = new BufferedImage(inWidth, inHeight, BufferedImage.TYPE_3BYTE_BGR);
DataBufferByte dbByte = (DataBufferByte) pbImage.getRaster().getDataBuffer();
myOffScreenBuffer.display();

myOffScreenBuffer.getGL().glReadPixels(0, 0, inWidth, inHeight, GL.GL_BGR, GL.GL_UNSIGNED_BYTE, dbByte.getData());

return pbImage; // returns nothing but black pixels

}

Would you like to see my OffScreenGLEventListener?