A few questions about Screenshot class usages

Hi,

I want to generate an image from a GLPBuffer instance, and I’ve managed to do it using the new Screenshot class, with the writeToFile method.

My problem is that I want an “offscreen” generation, i.e. I don’t want to display any JOGL widgets, but if I don’t add the GLCanvas in my main frame pane, the init() and display() methods of the GLEventListener are never called…

How should I do this ?
Thanks

Hi

If you create a GLPBuffer somewhere in your program at the point you want to take the screenshot using the GLDrawableFactory, then add the same GLEventListener as you would for your GLCanvas and then call your offscreen to call display() then it should work. Also you would put the Screenshot code in your display() method,

Code something like this should work, where glEventListener is your own GLEventListener:


offScreen = true;
offScreenCanvas = GLDrawableFactory.getFactory().createGLPbuffer(cap, new DefaultGLCapabilitiesChooser(), width, height, null);
offScreenCanvas.addGLEventListener( glEventListener );

outputFile = new File( dumpname );
// this causes all the events to fire
 // Also screen capture is done inside the Display loop.
offScreenCanvas.display();

// tidy up the event listener - upto you to do this
offScreenCanvas.removeGLEventListener(this);
offScreenCanvas.destroy();

Something like this in your display method for glEventListener:


if ( offScreen ) {
  try {
    	Screenshot.writeToFile( outputFile, screenDim.width, screenDim.height );
  }
  catch( IOException ioe ) {
    	System.err.println( "Error Creating File: " + ioe.getMessage() );
  }
}

Hope this is some help

Mike

Thanks Mike

It works fine now !

:slight_smile:

I used the code by Mike, but I only get a black image as result.

My glEventListener’s display method is called by my GLPbuffer object und the jpg file is written to disc by the ScreenShot class with the correct image width and height. When testing with my GLCanvas object and the Screenshot class, the image is all right. Furthermore I set the flag setDoubleBuffered for my GLPbuffer to false. GLDrawableFactory.getFactory().canCreateGLPbuffer() returns true.

Any suggestions why my image is black only?

Thanks,
Jens

If the image is alright when your using GLCanvas it should work fine for pbuffer.

I am not sure what your doing exactly, but there are two ways of doing it that I think should work:

The way I have posted before where you add your glEventListener to the pbuffer, then call display, make sure the Screenshot.writeToFile() function is inside your GLEventListener.display().

The other option is to create your pbuffer with the right capabilities, make the context of the pbuffer current ( pbuffer.getContext().makeCurrent() ) for the thread your working on then call your glEventListener.init( pbuffer ), followed by glEventListener.display( pbuffer ), since this is not using the GLEventListener rendering loop, you can have the Screenshot.writeToFile() outside of the display() and in the same part of the code as the pbuffer creation. You will have to release the context ( pbuffer.getDrawable().release() ) after you have done the writeToFile() though.

If neither of these ways work, I would suggest you post some code, such as your glEventListener and also the code that creates the pbuffer etc. Then someone with more knowledge might be able to point you in the right direction.

I hope this helps.

Mike

Thanks for your comments.

Well, I tried once more with a real simple test application and a basic scene. Then it worked!
When I looked again at my rather complicated application with a camera, I got it working adding

into the init method which was only placed in the reshape method before.

Now testing to export a quad with a texture, it works for the simple test application but with the complicated application I get the quad drawn filled with the currently set color.
I’ve attached my init and display method.

Does this code display a textured quad on a GLCanvas?

I haven’t got any experience of doing offscreen renderering of textured quads.

However there should be someone on these forums who can help you, or at least point you in the right direction.

yes, that’s exactly what I do not really understand.
Using the glCanvas the texture is drawn, but using the pBuffer it is not…