GLJPanel screenshot - from outside display(...) method

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

GLJPanel screenshot - from outside display(...) method

mikaelhc
Hi,

Is there a way to take a synchronous screenshot from a GLJPanel component?

I'm using the GLJPanel in a framework, where I need to implement an interface which returns a screenshot. This means, I cannot create the screenshot in the  "display(GLAutoDrawable ...)" method.

I have tried both:
BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
paint(image.createGraphics());
  and  
gl.getContext().makeCurrent();
BufferedImage image = Screenshot.readToBufferedImage(getWidth(), getHeight());
  But the first one fails sometimes (returning messed up images). And I guess I cannot assume that holding a GL2 handle and calling makeCurrent() on its GLContext will succed?

So what is the proper way to get a screenshot outside of the display(...) method?

(I believe the GLJPanel creates a BufferedImage each time it renders to screen - is it possible to get a handle to the last rendered BufferedImage?)
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel screenshot - from outside display(...) method

gouessej
Administrator
You can create a screenshot in display(GLAutoDrawable) and call GLJPanel.display() once in your framework.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel screenshot - from outside display(...) method

mikaelhc
Many thanks, gouessej! That works fine - display() is indeed synchronous!
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel screenshot - from outside display(...) method

gouessej
Administrator
You're welcome. You can use multiple GL event listeners or a flag in a single GL event listener if you don't always need to take a screen capture.
Julien Gouesse | Personal blog | Website