caps.setSampleBuffers(true);
caps.setNumSamples(antiAliasing);
//Buffer
GLPbuffer pbuffer = GLDrawableFactory.getFactory(profile).createGLPbuffer(device, caps, null, tileWidth, tileHeight, null);
BufferedImage image = null;
if (transparentBackground) {
image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_4BYTE_ABGR);
} else {
image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_3BYTE_BGR);
}
ByteBuffer imageBuffer = ByteBuffer.wrap(((DataBufferByte) image.getRaster().getDataBuffer()).getData());
//Tile rendering
TileRenderer tileRenderer = new TileRenderer();
tileRenderer.setTileSize(tileWidth, tileHeight, 0);
tileRenderer.setImageSize(imageWidth, imageHeight);
if (transparentBackground) {
tileRenderer.setImageBuffer(GL2.GL_BGRA, GL2.GL_UNSIGNED_BYTE, imageBuffer);
} else {
tileRenderer.setImageBuffer(GL2.GL_BGR, GL2.GL_UNSIGNED_BYTE, imageBuffer);
}
tileRenderer.trPerspective(drawable.viewField, (float) imageWidth / (float) imageHeight, drawable.nearDistance, drawable.farDistance);
//Get gl
//GLContext oldContext = GLContext.getCurrent();
GLContext context = pbuffer.getContext();
if (context.makeCurrent() == GLContext.CONTEXT_NOT_CURRENT) {
throw new RuntimeException("Error making pbuffer's context current");
}
System.out.println("Disabling snapshot");
GL2 gl = pbuffer.getGL().getGL2();
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
//Init
drawable.initConfig(gl);
vizConfig.setDisableLOD(true);
engine.initScreenshot(gl, GLAbstractListener.glu);
//Textrender - swap to 3D
textManager.setRenderer3d(true);
//Render in buffer
do {
tileRenderer.beginTile(gl);
drawable.renderScreenshot(pbuffer);
} while (tileRenderer.endTile(gl));
//Clean
context.release();
pbuffer.destroy();
//Textrender - back to 2D
textManager.setRenderer3d(false);
vizConfig.setDisableLOD(false);