aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-09-02 05:38:39 +0200
committerSven Gothel <[email protected]>2014-09-02 05:38:39 +0200
commit70641322fc8e52417f934b452b573c9b39a734e9 (patch)
tree51db352fa17e6e31a094286d8dcb14db17db9656 /src/test
parent9850c3a91a23983f1261cb38e4734524c67200f2 (diff)
Bug1044: Offscreen drawable AWT/ImageIO results in black image on OSX/[Java7-Java8]
- Using our PNGJ writer results in proper images (RGB and RGBA) on all platforms - Seems to be a bug w/ AWT/ImageIO
Diffstat (limited to 'src/test')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLOffscreenAutoDrawableBug1044AWT.java106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLOffscreenAutoDrawableBug1044AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLOffscreenAutoDrawableBug1044AWT.java
new file mode 100644
index 000000000..18ac7abc2
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLOffscreenAutoDrawableBug1044AWT.java
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2014 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.test.junit.jogl.acore;
+
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDrawable;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.fixedfunc.GLLightingFunc;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.util.GLReadBufferUtil;
+import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestGLOffscreenAutoDrawableBug1044AWT extends UITestCase {
+
+ @Test
+ public void test01GLOffscreenDrawable() throws InterruptedException {
+ final GLReadBufferUtil readBufferUtilRGB888 = new GLReadBufferUtil(false, false);
+ final GLReadBufferUtil readBufferUtilRGBA8888 = new GLReadBufferUtil(true, false);
+ final GLDrawableFactory fac = GLDrawableFactory.getFactory(GLProfile.getDefault());
+ final GLCapabilities glCap = new GLCapabilities(GLProfile.getMaxFixedFunc(true));
+ // Without line below, there is an error on Windows.
+ glCap.setDoubleBuffered(false);
+ //makes a new buffer 100x100
+ final GLDrawable glad = fac.createOffscreenDrawable(null, glCap, null, 100, 100);
+ glad.setRealized(true);
+ final GLContext context = glad.createContext(null);
+ context.makeCurrent();
+
+ System.err.println("Chosen: "+glad.getChosenGLCapabilities());
+
+ final GL2 gl2 = context.getGL().getGL2();
+ gl2.glViewport(0, 0, 100, 100);
+
+ gl2.glShadeModel(GLLightingFunc.GL_SMOOTH);
+ gl2.glClearColor(1.0f, 0.80f, 0.80f, 1); // This Will Clear The Background Color
+ gl2.glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
+ gl2.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ gl2.glLoadIdentity(); // Reset The Projection Matrix
+
+ final AWTGLReadBufferUtil agb = new AWTGLReadBufferUtil(glad.getGLProfile(), true);
+ final BufferedImage image = agb.readPixelsToBufferedImage(context.getGL(), true);
+ try {
+ ImageIO.write(image, "PNG", new File(getSimpleTestName(".")+"-AWTImageIO.png"));
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+
+ if(readBufferUtilRGB888.readPixels(gl2, false)) {
+ readBufferUtilRGB888.write(new File(getSimpleTestName(".")+"-PNGJ-rgb_.png"));
+ }
+ readBufferUtilRGB888.dispose(gl2);
+ if(readBufferUtilRGBA8888.readPixels(gl2, false)) {
+ readBufferUtilRGBA8888.write(new File(getSimpleTestName(".")+"-PNGJ-rgba.png"));
+ }
+ readBufferUtilRGBA8888.dispose(gl2);
+
+ context.destroy();
+ glad.setRealized(false);
+ System.out.println("Done!");
+ }
+
+ public static void main(final String[] args) {
+ org.junit.runner.JUnitCore.main(TestGLOffscreenAutoDrawableBug1044AWT.class.getName());
+ }
+}
+