From dbc74b98eb7429cbb51f7af0572ab53ddd0d9edc Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 30 Mar 2011 13:56:48 +0200 Subject: Refactor: Public *Renderer / Unify Region Demos / Using own Screenshot (non AWT, plain GL2ES2) Refactor: Public *Renderer - Sharing common base abstract class Renderer.java - Having public abstract classes RegionRenderer and TextRenderer - Implementation non public, accessed via factory - + shared code - + clean API (same stuff) Unify Region Demos - reduced code / path, sharing common demo/test features Text/Region Using own Screenshot (non AWT, plain GL2ES2) - Remove AWT dependency - Allow GL2ES2 screenshots - Less complex --- src/demo/Screenshot.java | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/demo/Screenshot.java (limited to 'src/demo/Screenshot.java') diff --git a/src/demo/Screenshot.java b/src/demo/Screenshot.java new file mode 100644 index 000000000..8e05b17ea --- /dev/null +++ b/src/demo/Screenshot.java @@ -0,0 +1,39 @@ +package demo; + +import java.io.File; +import java.io.IOException; + +import javax.media.opengl.GL; +import javax.media.opengl.GLAutoDrawable; + +import com.jogamp.opengl.util.texture.TextureIO; + +public class Screenshot { + + ReadBufferUtil readBufferUtil = new ReadBufferUtil(); + + public void dispose() { + readBufferUtil.dispose(); + } + + public void surface2File(GLAutoDrawable drawable, String filename) { + GL gl = drawable.getGL(); + // FIXME glFinish() is an expensive paranoia sync, should not be necessary due to spec + gl.glFinish(); + readBufferUtil.fetchOffscreenTexture(drawable, gl); + gl.glFinish(); + try { + surface2File(filename); + } catch (IOException ex) { + throw new RuntimeException("can not write survace to file", ex); + } + } + + void surface2File(String filename) throws IOException { + File file = new File(filename); + TextureIO.write(readBufferUtil.getTextureData(), file); + System.err.println("Wrote: " + file.getAbsolutePath() + ", ..."); + readBufferUtil.rewindPixelBuffer(); + } + +} -- cgit v1.2.3