using Screenshot class with PBuffer

hello, i am trying to use the Screenshot class to make a PNG from something i have rendered to a PBuffer, but all i see on the resulting PNG is white (the clearcolor).

now i dont know if the Screenshot class doesnt support PBuffers or if i have setup my PBuffer incorrectly.

this is what i do:


	public void makeCharacterScreenshot(GLAutoDrawable drawable) {
		if (!GLDrawableFactory.getFactory().canCreateGLPbuffer()) return;
		
		GLPbuffer pbuffer = GLDrawableFactory.getFactory().createGLPbuffer(new GLCapabilities(), new DefaultGLCapabilitiesChooser(), 1024, 1024, canvas.getContext());
		pbuffer.getContext().makeCurrent();
		GL gl = pbuffer.getGL();
		
// some stuff is rendered here
		
		gl.glFlush();
		pbuffer.swapBuffers();
		
		makeScreenshot(1024,1024);
		
		pbuffer.destroy();
		
		drawable.getContext().makeCurrent();


the makeScreenshot-function basically calls the Screenshot.writeToFile function.

could it be that the textures i have on my original drawable are not available on the pbuffer?

You should set up your GLCapabilities for the pbuffer to disable double-buffering and set the glReadBuffer to GL_FRONT before calling the Screenshot class. Otherwise this should work.

thanks for your reply. actually that was not the only problem. i also figured out that you have to set up all glEnable-flags again for the pBuffer.

thanks!

here is another question related to pbuffers:

how can i get the maximum size that is possible for a pbuffer? is it the same as the maximum texture size?

Unfortunately JOGL doesn’t provide a platform-independent way of querying this value. On Windows you’d need to call GL.getPlatformGLExtensions() and call WGLExt.wglGetPixelFormatAttribivEXT for WGL_MAX_PBUFFER_WIDTH_ARB and WGL_MAX_PBUFFER_HEIGHT_ARB. You can use GLDrawableFactory.canCreateGLPbuffer() to determine the availability of pbuffers, and if they are available, then the maximum texture size is probably a reasonable approximation. You can also just try a given width and height and iteratively divide them by two if pbuffer creation fails. This is probably the best practice anyway since VRAM consumption might make it not possible to allocate a pbuffer of the maximum dimensions.

just FYI: i noticed that the maximum pbuffer i can create is 2048 by 2048 although my GF8600’s maxTextureSize is 8192.

Hi,
That’s not so strange, even if PBuffer are often used as texture they are more like a viewport so this is not texture size limitation that are to be taken into account, if I am not wrong…