summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/texture/TestGrayTextureFromFileAWTBug417.java146
-rwxr-xr-xsrc/test/com/jogamp/opengl/test/junit/jogl/texture/grayscale_texture.pngbin0 -> 4873 bytes
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java5
3 files changed, 150 insertions, 1 deletions
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
new file mode 100644
index 000000000..8b47d5598
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestGrayTextureFromFileAWTBug417.java
@@ -0,0 +1,146 @@
+/**
+ * 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.imageio.ImageIO;
+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.TextureData;
+import com.jogamp.opengl.util.texture.TextureIO;
+import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
+import com.jogamp.opengl.util.Animator;
+
+import java.awt.Frame;
+import java.awt.image.BufferedImage;
+
+import java.io.File;
+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;
+
+/**
+ * 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;
+ File textureFile;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.get(GLProfile.GL2GL3);
+ Assert.assertNotNull(glp);
+ caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ }
+
+ @Before
+ public void initTest() {
+ textureFile = new File( "src/test/com/jogamp/opengl/test/junit/jogl/texture/grayscale_texture.png" );
+ Assert.assertNotNull(textureFile);
+ }
+
+ @After
+ public void cleanupTest() {
+ textureFile=null;
+ }
+
+ @Test
+ public void test1() throws InterruptedException {
+ GLCanvas glCanvas = new GLCanvas(caps);
+
+ 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( textureFile, true ) );
+ }
+ 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();
+ frame.setVisible(false);
+ frame.remove(glCanvas);
+ glCanvas=null;
+ Assert.assertNotNull(frame);
+ frame.dispose();
+ frame=null;
+ }
+
+ 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/grayscale_texture.png b/src/test/com/jogamp/opengl/test/junit/jogl/texture/grayscale_texture.png
new file mode 100755
index 000000000..dac0f13de
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/texture/grayscale_texture.png
Binary files differ
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
index b41dde645..649a3b19a 100644
--- 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
@@ -32,7 +32,6 @@ 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.GL;
import javax.media.opengl.GL2ES1;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
@@ -54,6 +53,10 @@ public class TextureGL2ListenerDraw1 implements GLEventListener {
}
}
+ 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);