From dd84dd3f99648c871d190a97bd813a0d6491849c Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 17 Jun 2012 17:28:20 +0200 Subject: JOGL Texture Util Unit Test merge to 'com.jogamp.opengl.test.junit.jogl.util.texture' --- .../texture/TestGrayTextureFromFileAWTBug417.java | 150 -------------------- .../test/junit/jogl/texture/TestTexture01AWT.java | 154 --------------------- .../test/junit/jogl/texture/grayscale_texture.png | Bin 4873 -> 0 bytes .../TestGLReadBufferUtilTextureIOWrite01NEWT.java | 100 ------------- .../TestGLReadBufferUtilTextureIOWrite02NEWT.java | 146 ------------------- .../TestGLReadBufferUtilTextureIOWrite01NEWT.java | 100 +++++++++++++ .../TestGLReadBufferUtilTextureIOWrite02NEWT.java | 146 +++++++++++++++++++ .../texture/TestGrayTextureFromFileAWTBug417.java | 149 ++++++++++++++++++++ .../junit/jogl/util/texture/TestTexture01AWT.java | 153 ++++++++++++++++++++ .../jogl/util/texture/TextureGL2ListenerDraw1.java | 112 +++++++++++++++ .../util/texture/gl2/TextureGL2ListenerDraw1.java | 112 --------------- .../junit/jogl/util/texture/grayscale_texture.png | Bin 0 -> 4873 bytes 12 files changed, 660 insertions(+), 662 deletions(-) delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/texture/TestGrayTextureFromFileAWTBug417.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java delete mode 100755 src/test/com/jogamp/opengl/test/junit/jogl/texture/grayscale_texture.png delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/TestGLReadBufferUtilTextureIOWrite01NEWT.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/TestGLReadBufferUtilTextureIOWrite02NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGLReadBufferUtilTextureIOWrite01NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGLReadBufferUtilTextureIOWrite02NEWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGrayTextureFromFileAWTBug417.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTexture01AWT.java create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TextureGL2ListenerDraw1.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java create mode 100755 src/test/com/jogamp/opengl/test/junit/jogl/util/texture/grayscale_texture.png (limited to 'src/test/com') diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestGrayTextureFromFileAWTBug417.java b/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestGrayTextureFromFileAWTBug417.java deleted file mode 100644 index d43a3a0c5..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestGrayTextureFromFileAWTBug417.java +++ /dev/null @@ -1,150 +0,0 @@ -/** - * Copyright 2010 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.texture; - -import com.jogamp.opengl.test.junit.jogl.util.texture.gl2.TextureGL2ListenerDraw1; - -import com.jogamp.opengl.test.junit.util.UITestCase; - -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLException; -import javax.media.opengl.GLProfile; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.awt.GLCanvas; -import com.jogamp.opengl.util.texture.TextureIO; -import com.jogamp.opengl.util.Animator; - -import java.awt.Frame; - -import java.io.IOException; -import java.io.InputStream; - -import org.junit.Assert; -import org.junit.After; -import org.junit.Assume; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Unit test for bug 417, which shows a GLException when reading a grayscale texture. - * Couldn't duplicate the failure, so it must have been fixed unknowingly sometime - * after the bug was submitted. - * @author Wade Walker - */ -public class TestGrayTextureFromFileAWTBug417 extends UITestCase { - static GLProfile glp; - static GLCapabilities caps; - InputStream textureStream; - - @BeforeClass - public static void initClass() { - if(!GLProfile.isAvailable(GLProfile.GL2GL3)) { - UITestCase.setTestSupported(false); - return; - } - glp = GLProfile.getGL2GL3(); - Assert.assertNotNull(glp); - caps = new GLCapabilities(glp); - Assert.assertNotNull(caps); - } - - @Before - public void initTest() { - textureStream = TestGrayTextureFromFileAWTBug417.class.getResourceAsStream( "grayscale_texture.png" ); - Assert.assertNotNull(textureStream); - } - - @After - public void cleanupTest() { - textureStream=null; - } - - @Test - public void test1() throws InterruptedException { - final GLCanvas glCanvas = new GLCanvas(caps); - final Frame frame = new Frame("Texture Test"); - Assert.assertNotNull(frame); - frame.add(glCanvas); - frame.setSize( 256, 128 ); - - // load texture from file inside current GL context to match the way - // the bug submitter was doing it - glCanvas.addGLEventListener(new TextureGL2ListenerDraw1( null ) { - @Override - public void init(GLAutoDrawable drawable) { - try { - setTexture( TextureIO.newTexture( textureStream, true, TextureIO.PNG ) ); - } - catch(GLException glexception) { - glexception.printStackTrace(); - Assume.assumeNoException(glexception); - } - catch(IOException ioexception) { - ioexception.printStackTrace(); - Assume.assumeNoException(ioexception); - } - } - }); - - Animator animator = new Animator(glCanvas); - frame.setVisible(true); - animator.start(); - - Thread.sleep(500); // 500 ms - - animator.stop(); - try { - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - frame.setVisible(false); - frame.remove(glCanvas); - frame.dispose(); - }}); - } catch( Throwable throwable ) { - throwable.printStackTrace(); - Assume.assumeNoException( throwable ); - } - } - - public static void main(String args[]) throws IOException { - String tstname = TestGrayTextureFromFileAWTBug417.class.getName(); - org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { - tstname, - "filtertrace=true", - "haltOnError=false", - "haltOnFailure=false", - "showoutput=true", - "outputtoformatters=true", - "logfailedtests=true", - "logtestlistenerevents=true", - "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", - "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); - } -} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java deleted file mode 100644 index 217b8aca3..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestTexture01AWT.java +++ /dev/null @@ -1,154 +0,0 @@ -/** - * Copyright 2010 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.texture; - -import com.jogamp.opengl.test.junit.jogl.util.texture.gl2.TextureGL2ListenerDraw1; - -import com.jogamp.opengl.test.junit.util.UITestCase; - -import javax.media.opengl.GLProfile; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.awt.GLCanvas; -import com.jogamp.opengl.util.texture.TextureData; -import com.jogamp.opengl.util.texture.awt.AWTTextureIO; -import com.jogamp.opengl.util.Animator; - -import java.awt.AlphaComposite; -import java.awt.Color; -import java.awt.Frame; -import java.awt.GradientPaint; -import java.awt.Graphics2D; -import java.awt.image.BufferedImage; - -import java.io.IOException; -import org.junit.Assert; -import org.junit.After; -import org.junit.Assume; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class TestTexture01AWT extends UITestCase { - static GLProfile glp; - static GLCapabilities caps; - BufferedImage textureImage; - - @BeforeClass - public static void initClass() { - if(!GLProfile.isAvailable(GLProfile.GL2GL3)) { - UITestCase.setTestSupported(false); - return; - } - glp = GLProfile.getGL2GL3(); - Assert.assertNotNull(glp); - caps = new GLCapabilities(glp); - Assert.assertNotNull(caps); - } - - @Before - public void initTest() { - // create base image - BufferedImage baseImage = new BufferedImage(256, 256, BufferedImage.TYPE_3BYTE_BGR); - Assert.assertNotNull(baseImage); - Graphics2D g = baseImage.createGraphics(); - Assert.assertNotNull(g); - g.setPaint(new GradientPaint(0, 0, Color.CYAN, - baseImage.getWidth(), baseImage.getHeight(), Color.BLUE)); - g.fillRect(0, 0, baseImage.getWidth(), baseImage.getHeight()); - g.dispose(); - - // create texture image - int imageType = BufferedImage.TYPE_3BYTE_BGR; - textureImage = new BufferedImage(baseImage.getWidth(), - baseImage.getHeight(), - imageType); - Assert.assertNotNull(textureImage); - g = textureImage.createGraphics(); - g.setComposite(AlphaComposite.Src); - g.drawImage(baseImage, 0, 0, null); - g.dispose(); - - baseImage.flush(); - baseImage=null; - } - - @After - public void cleanupTest() { - Assert.assertNotNull(textureImage); - textureImage.flush(); - textureImage=null; - } - - @Test - public void test1() throws InterruptedException { - final GLCanvas glCanvas = new GLCanvas(caps); - final Frame frame = new Frame("Texture Test"); - Assert.assertNotNull(frame); - frame.add(glCanvas); - frame.setSize(512, 512); - - // create texture - TextureData textureData = AWTTextureIO.newTextureData(caps.getGLProfile(), textureImage, false); - glCanvas.addGLEventListener(new TextureGL2ListenerDraw1(textureData)); - - Animator animator = new Animator(glCanvas); - frame.setVisible(true); - animator.start(); - - Thread.sleep(500); // 500 ms - - animator.stop(); - try { - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - frame.setVisible(false); - frame.remove(glCanvas); - frame.dispose(); - }}); - } catch( Throwable throwable ) { - throwable.printStackTrace(); - Assume.assumeNoException( throwable ); - } - } - - public static void main(String args[]) throws IOException { - String tstname = TestTexture01AWT.class.getName(); - org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { - tstname, - "filtertrace=true", - "haltOnError=false", - "haltOnFailure=false", - "showoutput=true", - "outputtoformatters=true", - "logfailedtests=true", - "logtestlistenerevents=true", - "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", - "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); - } -} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/texture/grayscale_texture.png b/src/test/com/jogamp/opengl/test/junit/jogl/texture/grayscale_texture.png deleted file mode 100755 index dac0f13de..000000000 Binary files a/src/test/com/jogamp/opengl/test/junit/jogl/texture/grayscale_texture.png and /dev/null differ diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/TestGLReadBufferUtilTextureIOWrite01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/TestGLReadBufferUtilTextureIOWrite01NEWT.java deleted file mode 100644 index ab8e54246..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/TestGLReadBufferUtilTextureIOWrite01NEWT.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright 2011 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.util; - -import java.io.File; - -import com.jogamp.newt.opengl.GLWindow; - -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLEventListener; -import javax.media.opengl.GLProfile; -import com.jogamp.opengl.util.GLReadBufferUtil; - -import com.jogamp.opengl.test.junit.util.UITestCase; -import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class TestGLReadBufferUtilTextureIOWrite01NEWT extends UITestCase { - static GLProfile glp; - static GLCapabilities caps; - static int width, height; - - @BeforeClass - public static void initClass() { - glp = GLProfile.getDefault(); - Assert.assertNotNull(glp); - caps = new GLCapabilities(glp); - Assert.assertNotNull(caps); - width = 256; - height = 256; - } - - protected void snapshot(GLAutoDrawable drawable, boolean alpha, boolean flip, String filename) { - GLReadBufferUtil screenshot = new GLReadBufferUtil(alpha, false); - if(screenshot.readPixels(drawable.getGL(), drawable, flip)) { - screenshot.write(new File(filename)); - } - } - - @Test - public void testWritePNG_TGA_PAM() throws InterruptedException { - GLWindow glWindow = GLWindow.create(caps); - Assert.assertNotNull(glWindow); - glWindow.setTitle("Shared Gears NEWT Test"); - glWindow.setSize(width, height); - glWindow.addGLEventListener(new GearsES2(1)); - glWindow.addGLEventListener(new GLEventListener() { - public void init(GLAutoDrawable drawable) {} - public void dispose(GLAutoDrawable drawable) {} - public void display(GLAutoDrawable drawable) { - // snapshot(drawable, false, true, getSimpleTestName(".")+"-rgb_-"+drawable.getGLProfile().getName()+".ppm"); - snapshot(drawable, true, false, getSimpleTestName(".")+"-rgba-"+drawable.getGLProfile().getName()+".png"); - snapshot(drawable, true, false, getSimpleTestName(".")+"-rgba-"+drawable.getGLProfile().getName()+".tga"); - snapshot(drawable, true, true, getSimpleTestName(".")+"-rgba-"+drawable.getGLProfile().getName()+".pam"); - snapshot(drawable, false, false, getSimpleTestName(".")+"-rgb_-"+drawable.getGLProfile().getName()+".png"); - snapshot(drawable, false, false, getSimpleTestName(".")+"-rgb_-"+drawable.getGLProfile().getName()+".tga"); - snapshot(drawable, false, true, getSimpleTestName(".")+"-rgb_-"+drawable.getGLProfile().getName()+".pam"); - } - public void reshape(GLAutoDrawable drawable, int x, int y, - int width, int height) { } - }); - glWindow.setVisible(true); - Thread.sleep(60); - glWindow.destroy(); - } - - public static void main(String args[]) { - org.junit.runner.JUnitCore.main(TestGLReadBufferUtilTextureIOWrite01NEWT.class.getName()); - } -} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/TestGLReadBufferUtilTextureIOWrite02NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/TestGLReadBufferUtilTextureIOWrite02NEWT.java deleted file mode 100644 index 79ae31612..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/TestGLReadBufferUtilTextureIOWrite02NEWT.java +++ /dev/null @@ -1,146 +0,0 @@ -/** - * Copyright 2011 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.util; - -import java.io.File; -import java.io.PrintWriter; -import java.io.StringWriter; - -import com.jogamp.newt.opengl.GLWindow; - -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLEventListener; -import javax.media.opengl.GLProfile; -import com.jogamp.opengl.util.GLReadBufferUtil; - -import com.jogamp.opengl.test.junit.util.UITestCase; -import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class TestGLReadBufferUtilTextureIOWrite02NEWT extends UITestCase { - static GLProfile glp; - static GLCapabilities caps; - static int width, height; - - @BeforeClass - public static void initClass() { - glp = GLProfile.getDefault(); - Assert.assertNotNull(glp); - caps = new GLCapabilities(glp); - Assert.assertNotNull(caps); - width = 256; - height = 256; - } - - protected void snapshot(GLAutoDrawable drawable, GLReadBufferUtil screenshot, String filename) { - if(screenshot.readPixels(drawable.getGL(), drawable, false)) { - screenshot.write(new File(filename)); - } - } - - @Test - public void testWriteTGAWithResize() throws InterruptedException { - final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false); - GLWindow glWindow = GLWindow.create(caps); - Assert.assertNotNull(glWindow); - glWindow.setTitle("Shared Gears NEWT Test"); - glWindow.setSize(width, height); - glWindow.addGLEventListener(new GearsES2(1)); - glWindow.addGLEventListener(new GLEventListener() { - int i=0; - public void init(GLAutoDrawable drawable) {} - public void dispose(GLAutoDrawable drawable) {} - public void display(GLAutoDrawable drawable) { - StringWriter filename = new StringWriter(); - { - PrintWriter pw = new PrintWriter(filename); - pw.printf("%s-rgba-%s-%03dx%03d-n%03d.tga", - getSimpleTestName("."), drawable.getGLProfile().getName(), - drawable.getWidth(), drawable.getHeight(), i++); - } - if(screenshot.readPixels(drawable.getGL(), drawable, false)) { - screenshot.write(new File(filename.toString())); - } - } - public void reshape(GLAutoDrawable drawable, int x, int y, - int width, int height) { } - }); - glWindow.setVisible(true); - Thread.sleep(60); - glWindow.setSize(300, 300); - Thread.sleep(60); - glWindow.setSize(400, 400); - Thread.sleep(60); - glWindow.destroy(); - } - - @Test - public void testWritePNGWithResize() throws InterruptedException { - final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false); - GLWindow glWindow = GLWindow.create(caps); - Assert.assertNotNull(glWindow); - glWindow.setTitle("Shared Gears NEWT Test"); - glWindow.setSize(width, height); - glWindow.addGLEventListener(new GearsES2(1)); - glWindow.addGLEventListener(new GLEventListener() { - int i=0; - public void init(GLAutoDrawable drawable) {} - public void dispose(GLAutoDrawable drawable) {} - public void display(GLAutoDrawable drawable) { - StringWriter filename = new StringWriter(); - { - PrintWriter pw = new PrintWriter(filename); - pw.printf("%s-rgba-%s-%03dx%03d-n%03d.png", - getSimpleTestName("."), drawable.getGLProfile().getName(), - drawable.getWidth(), drawable.getHeight(), i++); - } - if(screenshot.readPixels(drawable.getGL(), drawable, false)) { - screenshot.write(new File(filename.toString())); - } - } - public void reshape(GLAutoDrawable drawable, int x, int y, - int width, int height) { } - }); - glWindow.setVisible(true); - Thread.sleep(60); - glWindow.setSize(300, 300); - Thread.sleep(60); - glWindow.setSize(400, 400); - Thread.sleep(60); - glWindow.destroy(); - } - - public static void main(String args[]) { - org.junit.runner.JUnitCore.main(TestGLReadBufferUtilTextureIOWrite02NEWT.class.getName()); - } -} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGLReadBufferUtilTextureIOWrite01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGLReadBufferUtilTextureIOWrite01NEWT.java new file mode 100644 index 000000000..687465a5d --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGLReadBufferUtilTextureIOWrite01NEWT.java @@ -0,0 +1,100 @@ +/** + * Copyright 2011 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.util.texture; + +import java.io.File; + +import com.jogamp.newt.opengl.GLWindow; + +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; +import com.jogamp.opengl.util.GLReadBufferUtil; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TestGLReadBufferUtilTextureIOWrite01NEWT extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + static int width, height; + + @BeforeClass + public static void initClass() { + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + width = 256; + height = 256; + } + + protected void snapshot(GLAutoDrawable drawable, boolean alpha, boolean flip, String filename) { + GLReadBufferUtil screenshot = new GLReadBufferUtil(alpha, false); + if(screenshot.readPixels(drawable.getGL(), drawable, flip)) { + screenshot.write(new File(filename)); + } + } + + @Test + public void testWritePNG_TGA_PAM() throws InterruptedException { + GLWindow glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + glWindow.setTitle("Shared Gears NEWT Test"); + glWindow.setSize(width, height); + glWindow.addGLEventListener(new GearsES2(1)); + glWindow.addGLEventListener(new GLEventListener() { + public void init(GLAutoDrawable drawable) {} + public void dispose(GLAutoDrawable drawable) {} + public void display(GLAutoDrawable drawable) { + // snapshot(drawable, false, true, getSimpleTestName(".")+"-rgb_-"+drawable.getGLProfile().getName()+".ppm"); + snapshot(drawable, true, false, getSimpleTestName(".")+"-rgba-"+drawable.getGLProfile().getName()+".png"); + snapshot(drawable, true, false, getSimpleTestName(".")+"-rgba-"+drawable.getGLProfile().getName()+".tga"); + snapshot(drawable, true, true, getSimpleTestName(".")+"-rgba-"+drawable.getGLProfile().getName()+".pam"); + snapshot(drawable, false, false, getSimpleTestName(".")+"-rgb_-"+drawable.getGLProfile().getName()+".png"); + snapshot(drawable, false, false, getSimpleTestName(".")+"-rgb_-"+drawable.getGLProfile().getName()+".tga"); + snapshot(drawable, false, true, getSimpleTestName(".")+"-rgb_-"+drawable.getGLProfile().getName()+".pam"); + } + public void reshape(GLAutoDrawable drawable, int x, int y, + int width, int height) { } + }); + glWindow.setVisible(true); + Thread.sleep(60); + glWindow.destroy(); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestGLReadBufferUtilTextureIOWrite01NEWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGLReadBufferUtilTextureIOWrite02NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGLReadBufferUtilTextureIOWrite02NEWT.java new file mode 100644 index 000000000..6bb7f3b73 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGLReadBufferUtilTextureIOWrite02NEWT.java @@ -0,0 +1,146 @@ +/** + * Copyright 2011 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.util.texture; + +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; + +import com.jogamp.newt.opengl.GLWindow; + +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; +import com.jogamp.opengl.util.GLReadBufferUtil; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TestGLReadBufferUtilTextureIOWrite02NEWT extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + static int width, height; + + @BeforeClass + public static void initClass() { + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + width = 256; + height = 256; + } + + protected void snapshot(GLAutoDrawable drawable, GLReadBufferUtil screenshot, String filename) { + if(screenshot.readPixels(drawable.getGL(), drawable, false)) { + screenshot.write(new File(filename)); + } + } + + @Test + public void testWriteTGAWithResize() throws InterruptedException { + final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false); + GLWindow glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + glWindow.setTitle("Shared Gears NEWT Test"); + glWindow.setSize(width, height); + glWindow.addGLEventListener(new GearsES2(1)); + glWindow.addGLEventListener(new GLEventListener() { + int i=0; + public void init(GLAutoDrawable drawable) {} + public void dispose(GLAutoDrawable drawable) {} + public void display(GLAutoDrawable drawable) { + StringWriter filename = new StringWriter(); + { + PrintWriter pw = new PrintWriter(filename); + pw.printf("%s-rgba-%s-%03dx%03d-n%03d.tga", + getSimpleTestName("."), drawable.getGLProfile().getName(), + drawable.getWidth(), drawable.getHeight(), i++); + } + if(screenshot.readPixels(drawable.getGL(), drawable, false)) { + screenshot.write(new File(filename.toString())); + } + } + public void reshape(GLAutoDrawable drawable, int x, int y, + int width, int height) { } + }); + glWindow.setVisible(true); + Thread.sleep(60); + glWindow.setSize(300, 300); + Thread.sleep(60); + glWindow.setSize(400, 400); + Thread.sleep(60); + glWindow.destroy(); + } + + @Test + public void testWritePNGWithResize() throws InterruptedException { + final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false); + GLWindow glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + glWindow.setTitle("Shared Gears NEWT Test"); + glWindow.setSize(width, height); + glWindow.addGLEventListener(new GearsES2(1)); + glWindow.addGLEventListener(new GLEventListener() { + int i=0; + public void init(GLAutoDrawable drawable) {} + public void dispose(GLAutoDrawable drawable) {} + public void display(GLAutoDrawable drawable) { + StringWriter filename = new StringWriter(); + { + PrintWriter pw = new PrintWriter(filename); + pw.printf("%s-rgba-%s-%03dx%03d-n%03d.png", + getSimpleTestName("."), drawable.getGLProfile().getName(), + drawable.getWidth(), drawable.getHeight(), i++); + } + if(screenshot.readPixels(drawable.getGL(), drawable, false)) { + screenshot.write(new File(filename.toString())); + } + } + public void reshape(GLAutoDrawable drawable, int x, int y, + int width, int height) { } + }); + glWindow.setVisible(true); + Thread.sleep(60); + glWindow.setSize(300, 300); + Thread.sleep(60); + glWindow.setSize(400, 400); + Thread.sleep(60); + glWindow.destroy(); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestGLReadBufferUtilTextureIOWrite02NEWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGrayTextureFromFileAWTBug417.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGrayTextureFromFileAWTBug417.java new file mode 100644 index 000000000..a1e453fda --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestGrayTextureFromFileAWTBug417.java @@ -0,0 +1,149 @@ +/** + * Copyright 2010 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.util.texture; + + +import com.jogamp.opengl.test.junit.util.UITestCase; + +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.texture.TextureIO; +import com.jogamp.opengl.util.Animator; + +import java.awt.Frame; + +import java.io.IOException; +import java.io.InputStream; + +import org.junit.Assert; +import org.junit.After; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Unit test for bug 417, which shows a GLException when reading a grayscale texture. + * Couldn't duplicate the failure, so it must have been fixed unknowingly sometime + * after the bug was submitted. + * @author Wade Walker + */ +public class TestGrayTextureFromFileAWTBug417 extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + InputStream textureStream; + + @BeforeClass + public static void initClass() { + if(!GLProfile.isAvailable(GLProfile.GL2GL3)) { + UITestCase.setTestSupported(false); + return; + } + glp = GLProfile.getGL2GL3(); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + } + + @Before + public void initTest() { + textureStream = TestGrayTextureFromFileAWTBug417.class.getResourceAsStream( "grayscale_texture.png" ); + Assert.assertNotNull(textureStream); + } + + @After + public void cleanupTest() { + textureStream=null; + } + + @Test + public void test1() throws InterruptedException { + final GLCanvas glCanvas = new GLCanvas(caps); + final Frame frame = new Frame("Texture Test"); + Assert.assertNotNull(frame); + frame.add(glCanvas); + frame.setSize( 256, 128 ); + + // load texture from file inside current GL context to match the way + // the bug submitter was doing it + glCanvas.addGLEventListener(new TextureGL2ListenerDraw1( null ) { + @Override + public void init(GLAutoDrawable drawable) { + try { + setTexture( TextureIO.newTexture( textureStream, true, TextureIO.PNG ) ); + } + catch(GLException glexception) { + glexception.printStackTrace(); + Assume.assumeNoException(glexception); + } + catch(IOException ioexception) { + ioexception.printStackTrace(); + Assume.assumeNoException(ioexception); + } + } + }); + + Animator animator = new Animator(glCanvas); + frame.setVisible(true); + animator.start(); + + Thread.sleep(500); // 500 ms + + animator.stop(); + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(false); + frame.remove(glCanvas); + frame.dispose(); + }}); + } catch( Throwable throwable ) { + throwable.printStackTrace(); + Assume.assumeNoException( throwable ); + } + } + + public static void main(String args[]) throws IOException { + String tstname = TestGrayTextureFromFileAWTBug417.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTexture01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTexture01AWT.java new file mode 100644 index 000000000..da208fc42 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestTexture01AWT.java @@ -0,0 +1,153 @@ +/** + * Copyright 2010 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.util.texture; + + +import com.jogamp.opengl.test.junit.util.UITestCase; + +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.awt.AWTTextureIO; +import com.jogamp.opengl.util.Animator; + +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Frame; +import java.awt.GradientPaint; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; + +import java.io.IOException; +import org.junit.Assert; +import org.junit.After; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TestTexture01AWT extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + BufferedImage textureImage; + + @BeforeClass + public static void initClass() { + if(!GLProfile.isAvailable(GLProfile.GL2GL3)) { + UITestCase.setTestSupported(false); + return; + } + glp = GLProfile.getGL2GL3(); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + } + + @Before + public void initTest() { + // create base image + BufferedImage baseImage = new BufferedImage(256, 256, BufferedImage.TYPE_3BYTE_BGR); + Assert.assertNotNull(baseImage); + Graphics2D g = baseImage.createGraphics(); + Assert.assertNotNull(g); + g.setPaint(new GradientPaint(0, 0, Color.CYAN, + baseImage.getWidth(), baseImage.getHeight(), Color.BLUE)); + g.fillRect(0, 0, baseImage.getWidth(), baseImage.getHeight()); + g.dispose(); + + // create texture image + int imageType = BufferedImage.TYPE_3BYTE_BGR; + textureImage = new BufferedImage(baseImage.getWidth(), + baseImage.getHeight(), + imageType); + Assert.assertNotNull(textureImage); + g = textureImage.createGraphics(); + g.setComposite(AlphaComposite.Src); + g.drawImage(baseImage, 0, 0, null); + g.dispose(); + + baseImage.flush(); + baseImage=null; + } + + @After + public void cleanupTest() { + Assert.assertNotNull(textureImage); + textureImage.flush(); + textureImage=null; + } + + @Test + public void test1() throws InterruptedException { + final GLCanvas glCanvas = new GLCanvas(caps); + final Frame frame = new Frame("Texture Test"); + Assert.assertNotNull(frame); + frame.add(glCanvas); + frame.setSize(512, 512); + + // create texture + TextureData textureData = AWTTextureIO.newTextureData(caps.getGLProfile(), textureImage, false); + glCanvas.addGLEventListener(new TextureGL2ListenerDraw1(textureData)); + + Animator animator = new Animator(glCanvas); + frame.setVisible(true); + animator.start(); + + Thread.sleep(500); // 500 ms + + animator.stop(); + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(false); + frame.remove(glCanvas); + frame.dispose(); + }}); + } catch( Throwable throwable ) { + throwable.printStackTrace(); + Assume.assumeNoException( throwable ); + } + } + + public static void main(String args[]) throws IOException { + String tstname = TestTexture01AWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TextureGL2ListenerDraw1.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TextureGL2ListenerDraw1.java new file mode 100644 index 000000000..cec151584 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TextureGL2ListenerDraw1.java @@ -0,0 +1,112 @@ +/** + * Copyright 2010 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.util.texture; + +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureCoords; +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.TextureIO; +import javax.media.opengl.GL2ES1; +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.glu.GLU; + +public class TextureGL2ListenerDraw1 implements GLEventListener { + private GLU glu = new GLU(); + private TextureData textureData; + private Texture texture; + + public TextureGL2ListenerDraw1(TextureData td) { + this.textureData = td; + } + + public void init(GLAutoDrawable drawable) { + if(null!=textureData) { + this.texture = TextureIO.newTexture(textureData); + } + } + + public void setTexture( Texture texture ) { + this.texture = texture; + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + GL2 gl = drawable.getGL().getGL2(); + gl.glMatrixMode(GL2ES1.GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluOrtho2D(0, 1, 0, 1); + gl.glMatrixMode(GL2ES1.GL_MODELVIEW); + gl.glLoadIdentity(); + } + + public void dispose(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + if(null!=texture) { + texture.disable(gl); + texture.destroy(gl); + } + if(null!=textureData) { + textureData.destroy(); + } + } + + public void display(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + + // need a valid GL context for this .. + + /** OpenGL .. + texture.updateSubImage(textureData, 0, + 20, 20, + 20, 20, + 100, 100); */ + + + // Now draw one quad with the texture + if(null!=texture) { + texture.enable(gl); + texture.bind(gl); + gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE); + TextureCoords coords = texture.getImageTexCoords(); + gl.glBegin(GL2.GL_QUADS); + gl.glTexCoord2f(coords.left(), coords.bottom()); + gl.glVertex3f(0, 0, 0); + gl.glTexCoord2f(coords.right(), coords.bottom()); + gl.glVertex3f(1, 0, 0); + gl.glTexCoord2f(coords.right(), coords.top()); + gl.glVertex3f(1, 1, 0); + gl.glTexCoord2f(coords.left(), coords.top()); + gl.glVertex3f(0, 1, 0); + gl.glEnd(); + texture.disable(gl); + } + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java deleted file mode 100644 index 084caa682..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * Copyright 2010 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.util.texture.gl2; - -import com.jogamp.opengl.util.texture.Texture; -import com.jogamp.opengl.util.texture.TextureCoords; -import com.jogamp.opengl.util.texture.TextureData; -import com.jogamp.opengl.util.texture.TextureIO; -import javax.media.opengl.GL2ES1; -import javax.media.opengl.GL2; -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLEventListener; -import javax.media.opengl.glu.GLU; - -public class TextureGL2ListenerDraw1 implements GLEventListener { - private GLU glu = new GLU(); - private TextureData textureData; - private Texture texture; - - public TextureGL2ListenerDraw1(TextureData td) { - this.textureData = td; - } - - public void init(GLAutoDrawable drawable) { - if(null!=textureData) { - this.texture = TextureIO.newTexture(textureData); - } - } - - public void setTexture( Texture texture ) { - this.texture = texture; - } - - public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { - GL2 gl = drawable.getGL().getGL2(); - gl.glMatrixMode(GL2ES1.GL_PROJECTION); - gl.glLoadIdentity(); - glu.gluOrtho2D(0, 1, 0, 1); - gl.glMatrixMode(GL2ES1.GL_MODELVIEW); - gl.glLoadIdentity(); - } - - public void dispose(GLAutoDrawable drawable) { - GL2 gl = drawable.getGL().getGL2(); - if(null!=texture) { - texture.disable(gl); - texture.destroy(gl); - } - if(null!=textureData) { - textureData.destroy(); - } - } - - public void display(GLAutoDrawable drawable) { - GL2 gl = drawable.getGL().getGL2(); - - // need a valid GL context for this .. - - /** OpenGL .. - texture.updateSubImage(textureData, 0, - 20, 20, - 20, 20, - 100, 100); */ - - - // Now draw one quad with the texture - if(null!=texture) { - texture.enable(gl); - texture.bind(gl); - gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE); - TextureCoords coords = texture.getImageTexCoords(); - gl.glBegin(GL2.GL_QUADS); - gl.glTexCoord2f(coords.left(), coords.bottom()); - gl.glVertex3f(0, 0, 0); - gl.glTexCoord2f(coords.right(), coords.bottom()); - gl.glVertex3f(1, 0, 0); - gl.glTexCoord2f(coords.right(), coords.top()); - gl.glVertex3f(1, 1, 0); - gl.glTexCoord2f(coords.left(), coords.top()); - gl.glVertex3f(0, 1, 0); - gl.glEnd(); - texture.disable(gl); - } - } -} - diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/grayscale_texture.png b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/grayscale_texture.png new file mode 100755 index 000000000..dac0f13de Binary files /dev/null and b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/grayscale_texture.png differ -- cgit v1.2.3