summaryrefslogtreecommitdiffstats
path: root/src/test/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/com')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Teapot.java124
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestTeapotNEWT.java159
2 files changed, 283 insertions, 0 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Teapot.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Teapot.java
new file mode 100644
index 000000000..ae5a0b3ba
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Teapot.java
@@ -0,0 +1,124 @@
+package com.jogamp.opengl.test.junit.jogl.demos.gl2;
+
+import java.net.URLConnection;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+
+import com.jogamp.common.util.IOUtil;
+import com.jogamp.opengl.util.gl2.GLUT;
+import com.jogamp.opengl.util.texture.Texture;
+import com.jogamp.opengl.util.texture.TextureIO;
+
+/**
+ * Adapted from
+ * http://www.java-tips.org/other-api-tips/jogl/how-to-draw-a-texture-mapped-teapot-with-automatically-generated-texture-coordi.html
+ */
+public class Teapot implements GLEventListener {
+
+ private GLUT glut;
+
+ /* glTexGen stuff: */
+ private float sgenparams[] = { 1.0f, 1.0f, 1.0f, 0.0f };
+
+ private Texture tex = null;
+
+ @Override
+ public void init(GLAutoDrawable drawable) {
+ GL2 gl = drawable.getGL().getGL2();
+ glut = new GLUT();
+
+ gl.glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
+
+ try {
+ URLConnection urlConn = IOUtil.getResource("jogl/util/data/av/test-ntsc01-160x90.png", this.getClass().getClassLoader());
+ tex = TextureIO.newTexture(gl, TextureIO.newTextureData(gl.getGLProfile(), urlConn.getInputStream(), false, TextureIO.PNG));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ tex.bind(gl);
+
+ // uncomment this and comment the above to see a working texture
+ // makeStripeImage();
+ // gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
+ // gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE,
+ // GL2.GL_MODULATE);
+ // gl.glTexParameterf(GL2.GL_TEXTURE_1D, GL.GL_TEXTURE_WRAP_S,
+ // GL.GL_REPEAT);
+ // gl.glTexParameterf(GL2.GL_TEXTURE_1D, GL.GL_TEXTURE_MAG_FILTER,
+ // GL.GL_LINEAR);
+ // gl.glTexParameterf(GL2.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER,
+ // GL.GL_LINEAR);
+ // gl.glTexImage1D(GL2.GL_TEXTURE_1D, 0, 3, stripeImageWidth, 0,
+ // GL.GL_RGB, GL.GL_UNSIGNED_BYTE, stripeImageBuf);
+
+ gl.glTexParameterf(GL2.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
+
+ // gl.glTexGeni(GL2.GL_S, GL2.GL_TEXTURE_GEN_MODE, GL2.GL_OBJECT_LINEAR);
+ // gl.glTexGenfv(GL2.GL_S, GL2.GL_OBJECT_PLANE, sgenparams, 0);
+
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ gl.glDepthFunc(GL.GL_LESS);
+ // gl.glEnable(GL2.GL_TEXTURE_GEN_S);
+ // gl.glEnable(GL2.GL_TEXTURE_1D);
+ gl.glEnable(GL2.GL_TEXTURE_2D);
+ gl.glEnable(GL2.GL_CULL_FACE);
+ gl.glEnable(GL2.GL_LIGHTING);
+ gl.glEnable(GL2.GL_LIGHT0);
+ gl.glEnable(GL2.GL_AUTO_NORMAL);
+ gl.glEnable(GL2.GL_NORMALIZE);
+ gl.glFrontFace(GL.GL_CW);
+ gl.glCullFace(GL.GL_BACK);
+ gl.glMaterialf(GL.GL_FRONT, GL2.GL_SHININESS, 64.0f);
+ }
+
+ float angleZ = 0.0f;
+ float rotDir = 1.0f;
+ public float rotIncr = 0.4f;
+
+ @Override
+ public void display(GLAutoDrawable gLDrawable) {
+ final GL2 gl = gLDrawable.getGL().getGL2();
+
+ tex.bind(gl);
+ gl.glEnable(GL2.GL_TEXTURE_2D);
+
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ gl.glPushMatrix();
+ gl.glRotatef(angleZ, 0.0f, 1.0f, 0.0f);
+ gl.glRotatef(45.0f, 0.0f, 0.0f, 1.0f);
+ glut.glutSolidTeapot(2.0f);
+ gl.glPopMatrix();
+ gl.glFlush();
+ if( angleZ >= 180.0f ) {
+ rotDir = -1.0f;
+ } else if (angleZ <= 0.0f ) {
+ rotDir = +1.0f;
+ }
+ angleZ += rotIncr * rotDir;
+ }
+
+ @Override
+ public void reshape(GLAutoDrawable gLDrawable, int x, int y, int w, int h) {
+ GL2 gl = gLDrawable.getGL().getGL2();
+
+ gl.glViewport(0, 0, w, h);
+ gl.glMatrixMode(GL2.GL_PROJECTION);
+ gl.glLoadIdentity();
+ if (w <= h) {
+ gl.glOrtho(-3.5, 3.5, -3.5 * (float) h / (float) w,
+ 3.5 * (float) h / (float) w, -3.5, 3.5);
+ } else {
+ gl.glOrtho(-3.5 * (float) w / (float) h,
+ 3.5 * (float) w / (float) h, -3.5, 3.5, -3.5, 3.5);
+ }
+ gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ }
+
+ @Override
+ public void dispose(GLAutoDrawable gLDrawable) {
+ }
+} \ No newline at end of file
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestTeapotNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestTeapotNEWT.java
new file mode 100644
index 000000000..ddde837ab
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestTeapotNEWT.java
@@ -0,0 +1,159 @@
+/**
+ * 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.demos.gl2.newt;
+
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.QuitAdapter;
+
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.Teapot;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+public class TestTeapotNEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ if(GLProfile.isAvailable(GLProfile.GL2)) {
+ glp = GLProfile.get(GLProfile.GL2);
+ Assert.assertNotNull(glp);
+ width = 640;
+ height = 480;
+ } else {
+ setTestSupported(false);
+ }
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected void runTestGL(GLCapabilities caps, boolean withAnimator) throws InterruptedException {
+ final GLWindow glWindow = GLWindow.create(caps);
+
+ glWindow.setTitle("Teapot NEWT Test");
+ Teapot demo = new Teapot();
+ if( !withAnimator ) {
+ demo.rotIncr *= 10f;
+ }
+ glWindow.addGLEventListener(demo);
+ final SnapshotGLEventListener snap = new SnapshotGLEventListener();
+ glWindow.addGLEventListener(snap);
+
+ final Animator animator = withAnimator ? new Animator(glWindow) : null;
+ final QuitAdapter quitAdapter = new QuitAdapter();
+
+ //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
+ //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
+ glWindow.addKeyListener(quitAdapter);
+ glWindow.addWindowListener(quitAdapter);
+
+ glWindow.setSize(width, height);
+ glWindow.setVisible(true);
+ if( withAnimator ) {
+ animator.setUpdateFPSFrames(60, System.err);
+ animator.start();
+ }
+
+ final long t0 = System.currentTimeMillis();
+ long t1 = t0;
+ int snaps=3;
+ while(!quitAdapter.shouldQuit() && t1-t0<duration) {
+ Thread.sleep(100);
+ t1 = System.currentTimeMillis();
+ if( snaps-- > 0 ) {
+ snap.setMakeSnapshot();
+ }
+ if( !withAnimator ) {
+ glWindow.display();
+ }
+ }
+
+ if( withAnimator ) {
+ animator.stop();
+ }
+ glWindow.destroy();
+ }
+
+ @Test
+ public void test01_DefCaps_Anim() throws InterruptedException {
+ final GLCapabilities caps = new GLCapabilities(GLProfile.getMaxFixedFunc(true));
+ runTestGL(caps, true);
+ }
+
+ @Test
+ public void test02_DefCaps_NoAnim() throws InterruptedException {
+ final GLCapabilities caps = new GLCapabilities(GLProfile.getMaxFixedFunc(true));
+ runTestGL(caps, false);
+ }
+
+ @Test
+ public void test12_FBOCaps_NoAnim() throws InterruptedException {
+ final GLCapabilities caps = new GLCapabilities(GLProfile.getMaxFixedFunc(true));
+ caps.setHardwareAccelerated(true);
+ caps.setDoubleBuffered(true);
+ caps.setAlphaBits(8);
+ caps.setDepthBits(8);
+ caps.setNumSamples(0);
+ caps.setSampleBuffers(false);
+ caps.setStencilBits(0);
+ caps.setRedBits(8);
+ caps.setBlueBits(8);
+ caps.setGreenBits(8);
+
+ // caps.setPBuffer(true);
+ caps.setFBO(true);
+
+ runTestGL(caps, false);
+ }
+
+ static long duration = 500; // ms
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ duration = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestTeapotNEWT.class.getName());
+ }
+}