diff options
author | Sven Gothel <[email protected]> | 2012-05-15 18:04:11 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-05-15 18:04:11 +0200 |
commit | 9729f4408a1f340acd2a49e8f86b397e7a6b1b6f (patch) | |
tree | 34f086d7907d1d10ca24b6672d3c37b25bbaa2e8 /src/test/com/jogamp | |
parent | 26ea5829e72ba4d0e7a5d3136437e9a2894d6e35 (diff) |
Java Source Files: dos -> unix format
Diffstat (limited to 'src/test/com/jogamp')
8 files changed, 1416 insertions, 1416 deletions
diff --git a/src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanelTest1.java b/src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanelTest1.java index 18a432428..9bf492e0f 100644 --- a/src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanelTest1.java +++ b/src/test/com/jogamp/opengl/test/bugs/Bug427GLJPanelTest1.java @@ -1,72 +1,72 @@ -package com.jogamp.opengl.test.bugs;
-
-import javax.swing.*;
-import java.awt.*;
-import javax.media.opengl.*;
-import javax.media.opengl.awt.*;
-
-public class Bug427GLJPanelTest1 extends JFrame implements GLEventListener {
-
- public Bug427GLJPanelTest1() {
- super("Bug427GLJPanelTest1");
-
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setLayout(new BorderLayout());
-
- setSize(600, 600);
- setLocation(40, 40);
- setVisible(true);
-
- GLProfile glp = GLProfile.get(GLProfile.GL2);
- GLCapabilities caps = new GLCapabilities(glp);
- caps.setDoubleBuffered(true);
- caps.setHardwareAccelerated(true);
-
- GLJPanel panel = new GLJPanel(caps);
- panel.addGLEventListener(this);
-
- add(panel, BorderLayout.CENTER);
- }
-
- public static void main(String[] args) {
- Bug427GLJPanelTest1 demo = new Bug427GLJPanelTest1();
- demo.setVisible(true);
- }
-
- public void display(GLAutoDrawable drawable) {
- GL2 gl = drawable.getGL().getGL2();
-
- gl.glClear(GL.GL_COLOR_BUFFER_BIT);
- gl.glBegin(GL.GL_TRIANGLES);
-
- gl.glColor3f(1, 0, 0);
- gl.glVertex3f(0.25f, 0.25f, 0);
-
- gl.glColor3f(0, 1, 0);
- gl.glVertex3f(0.5f, 0.25f, 0);
-
- gl.glColor3f(0, 0, 1);
- gl.glVertex3f(0.25f, 0.5f, 0);
-
- gl.glEnd();
- gl.glFlush();
- }
-
- public void init(GLAutoDrawable drawable) {
- GL2 gl = drawable.getGL().getGL2();
-
- gl.glClearColor(0, 0, 0, 0);
- gl.glMatrixMode(GL2.GL_PROJECTION);
- gl.glLoadIdentity();
- gl.glOrtho(0, 1, 0, 1, -1, 1);
- }
-
- public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {
- }
-
- public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
- }
-
- public void dispose(GLAutoDrawable drawable) {
- }
-}
+package com.jogamp.opengl.test.bugs; + +import javax.swing.*; +import java.awt.*; +import javax.media.opengl.*; +import javax.media.opengl.awt.*; + +public class Bug427GLJPanelTest1 extends JFrame implements GLEventListener { + + public Bug427GLJPanelTest1() { + super("Bug427GLJPanelTest1"); + + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLayout(new BorderLayout()); + + setSize(600, 600); + setLocation(40, 40); + setVisible(true); + + GLProfile glp = GLProfile.get(GLProfile.GL2); + GLCapabilities caps = new GLCapabilities(glp); + caps.setDoubleBuffered(true); + caps.setHardwareAccelerated(true); + + GLJPanel panel = new GLJPanel(caps); + panel.addGLEventListener(this); + + add(panel, BorderLayout.CENTER); + } + + public static void main(String[] args) { + Bug427GLJPanelTest1 demo = new Bug427GLJPanelTest1(); + demo.setVisible(true); + } + + public void display(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + + gl.glClear(GL.GL_COLOR_BUFFER_BIT); + gl.glBegin(GL.GL_TRIANGLES); + + gl.glColor3f(1, 0, 0); + gl.glVertex3f(0.25f, 0.25f, 0); + + gl.glColor3f(0, 1, 0); + gl.glVertex3f(0.5f, 0.25f, 0); + + gl.glColor3f(0, 0, 1); + gl.glVertex3f(0.25f, 0.5f, 0); + + gl.glEnd(); + gl.glFlush(); + } + + public void init(GLAutoDrawable drawable) { + GL2 gl = drawable.getGL().getGL2(); + + gl.glClearColor(0, 0, 0, 0); + gl.glMatrixMode(GL2.GL_PROJECTION); + gl.glLoadIdentity(); + gl.glOrtho(0, 1, 0, 1, -1, 1); + } + + public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) { + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { + } + + public void dispose(GLAutoDrawable drawable) { + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java index d451efb31..a6616945d 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java @@ -1,222 +1,222 @@ -/**
- * 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.graph;
-
-import java.io.IOException;
-
-import javax.media.opengl.GLAutoDrawable;
-import javax.media.opengl.GLCapabilities;
-import javax.media.opengl.GLCapabilitiesImmutable;
-import javax.media.opengl.GLEventListener;
-import javax.media.opengl.GLException;
-import javax.media.opengl.GLProfile;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.jogamp.common.os.Platform;
-import com.jogamp.graph.curve.Region;
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.geom.opengl.SVertex;
-import com.jogamp.newt.opengl.GLWindow;
-import com.jogamp.opengl.test.junit.graph.demos.GPURegionGLListener01;
-import com.jogamp.opengl.test.junit.graph.demos.GPURegionGLListener02;
-import com.jogamp.opengl.test.junit.graph.demos.GPURegionRendererListenerBase01;
-import com.jogamp.opengl.test.junit.util.UITestCase;
-import com.jogamp.opengl.util.glsl.ShaderState;
-
-
-public class TestRegionRendererNEWT01 extends UITestCase {
-
- public static void main(String args[]) throws IOException {
- String tstname = TestRegionRendererNEWT01.class.getName();
- org.junit.runner.JUnitCore.main(tstname);
- }
-
- static void destroyWindow(GLWindow window) {
- if(null!=window) {
- window.destroy();
- }
- }
-
- static GLWindow createWindow(String title, GLCapabilitiesImmutable caps, int width, int height) {
- Assert.assertNotNull(caps);
-
- GLWindow window = GLWindow.create(caps);
- window.setSize(width, height);
- window.setPosition(10, 10);
- window.setTitle(title);
- Assert.assertNotNull(window);
- window.setVisible(true);
-
- return window;
- }
-
- @Test
- public void testRegionRendererR2T01() throws InterruptedException {
- if(Platform.CPUFamily.X86 != Platform.CPU_ARCH.family) { // FIXME
- // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
- System.err.println("disabled on non desktop (x86) arch for now ..");
- return;
- }
- GLProfile glp = GLProfile.getGL2ES2();
-
- GLCapabilities caps = new GLCapabilities(glp);
- //caps.setOnscreen(false);
- caps.setAlphaBits(4);
-
- GLWindow window = createWindow("shape-vbaa1-msaa0", caps, 800,400);
- RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
- GPURegionGLListener02 demo02Listener = new GPURegionGLListener02 (rs, Region.VBAA_RENDERING_BIT, 1140, false, false);
- demo02Listener.attachInputListenerTo(window);
- window.addGLEventListener(demo02Listener);
-
- RegionGLListener listener = new RegionGLListener(demo02Listener, window.getTitle(), "GPURegionNewtDemo02");
- window.addGLEventListener(listener);
-
- listener.setTech(-20, 00, 0f, -300, 400);
- window.display();
-
- listener.setTech(-20, 00, 0f, -150, 800);
- window.display();
-
- listener.setTech(-20, 00, 0f, -50, 1000);
- window.display();
-
- destroyWindow(window);
- }
-
- @Test
- public void testRegionRendererMSAA01() throws InterruptedException {
- GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
- GLCapabilities caps = new GLCapabilities(glp);
- // caps.setOnscreen(false);
- caps.setAlphaBits(4);
- caps.setSampleBuffers(true);
- caps.setNumSamples(4);
-
- GLWindow window = createWindow("shape-vbaa0-msaa1", caps, 800, 400);
- RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
-
- GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, 0, 0, false, false);
- demo01Listener.attachInputListenerTo(window);
- window.addGLEventListener(demo01Listener);
-
- RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion01");
- window.addGLEventListener(listener);
-
- listener.setTech(-20, 00, 0f, -300, 400);
- window.display();
-
- listener.setTech(-20, 00, 0f, -150, 800);
- window.display();
-
- listener.setTech(-20, 00, 0f, -50, 1000);
- window.display();
-
- destroyWindow(window);
- }
-
- @Test
- public void testRegionRendererMSAA02() throws InterruptedException {
- if(Platform.CPUFamily.X86 != Platform.CPU_ARCH.family) { // FIXME
- // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
- // FIXME: Also the GLSL code for VARIABLE_CURVE is not fit for mobile yet!
- System.err.println("disabled on non desktop (x86) arch for now ..");
- return;
- }
- GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
- GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
- caps.setSampleBuffers(true);
- caps.setNumSamples(4);
-
- GLWindow window = createWindow("shape-vbaa0-msaa1", caps, 800, 400);
- RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
-
- GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, Region.VARIABLE_CURVE_WEIGHT_BIT, 0, false, false);
- demo01Listener.attachInputListenerTo(window);
- window.addGLEventListener(demo01Listener);
-
- RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion02");
- window.addGLEventListener(listener);
-
- listener.setTech(-20, 00, 0f, -300, 400);
- window.display();
-
- listener.setTech(-20, 00, 0f, -150, 800);
- window.display();
-
- listener.setTech(-20, 00, 0f, -50, 1000);
- window.display();
-
- destroyWindow(window);
- }
-
- private class RegionGLListener implements GLEventListener {
- String winTitle;
- String name;
- GPURegionRendererListenerBase01 impl;
-
- public RegionGLListener(GPURegionRendererListenerBase01 impl, String title, String name) {
- this.impl = impl;
- this.winTitle = title;
- this.name = name;
- }
-
- public void setTech(float xt, float yt, float angle, int zoom, int fboSize){
- impl.setMatrix(xt, yt, angle, zoom, fboSize);
- }
-
- public void init(GLAutoDrawable drawable) {
- impl.init(drawable);
- }
-
- public void display(GLAutoDrawable drawable) {
- impl.display(drawable);
-
- try {
- impl.printScreen(drawable, "./", winTitle, name, false);
- } catch (GLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public void dispose(GLAutoDrawable drawable) {
- impl.dispose(drawable);
-
- }
-
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
- impl.reshape(drawable, x, y, width, height);
-
- }
- }
-}
+/** + * 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.graph; + +import java.io.IOException; + +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.common.os.Platform; +import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.RenderState; +import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.graph.demos.GPURegionGLListener01; +import com.jogamp.opengl.test.junit.graph.demos.GPURegionGLListener02; +import com.jogamp.opengl.test.junit.graph.demos.GPURegionRendererListenerBase01; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.glsl.ShaderState; + + +public class TestRegionRendererNEWT01 extends UITestCase { + + public static void main(String args[]) throws IOException { + String tstname = TestRegionRendererNEWT01.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + + static void destroyWindow(GLWindow window) { + if(null!=window) { + window.destroy(); + } + } + + static GLWindow createWindow(String title, GLCapabilitiesImmutable caps, int width, int height) { + Assert.assertNotNull(caps); + + GLWindow window = GLWindow.create(caps); + window.setSize(width, height); + window.setPosition(10, 10); + window.setTitle(title); + Assert.assertNotNull(window); + window.setVisible(true); + + return window; + } + + @Test + public void testRegionRendererR2T01() throws InterruptedException { + if(Platform.CPUFamily.X86 != Platform.CPU_ARCH.family) { // FIXME + // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise). + System.err.println("disabled on non desktop (x86) arch for now .."); + return; + } + GLProfile glp = GLProfile.getGL2ES2(); + + GLCapabilities caps = new GLCapabilities(glp); + //caps.setOnscreen(false); + caps.setAlphaBits(4); + + GLWindow window = createWindow("shape-vbaa1-msaa0", caps, 800,400); + RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); + GPURegionGLListener02 demo02Listener = new GPURegionGLListener02 (rs, Region.VBAA_RENDERING_BIT, 1140, false, false); + demo02Listener.attachInputListenerTo(window); + window.addGLEventListener(demo02Listener); + + RegionGLListener listener = new RegionGLListener(demo02Listener, window.getTitle(), "GPURegionNewtDemo02"); + window.addGLEventListener(listener); + + listener.setTech(-20, 00, 0f, -300, 400); + window.display(); + + listener.setTech(-20, 00, 0f, -150, 800); + window.display(); + + listener.setTech(-20, 00, 0f, -50, 1000); + window.display(); + + destroyWindow(window); + } + + @Test + public void testRegionRendererMSAA01() throws InterruptedException { + GLProfile glp = GLProfile.get(GLProfile.GL2ES2); + GLCapabilities caps = new GLCapabilities(glp); + // caps.setOnscreen(false); + caps.setAlphaBits(4); + caps.setSampleBuffers(true); + caps.setNumSamples(4); + + GLWindow window = createWindow("shape-vbaa0-msaa1", caps, 800, 400); + RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); + + GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, 0, 0, false, false); + demo01Listener.attachInputListenerTo(window); + window.addGLEventListener(demo01Listener); + + RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion01"); + window.addGLEventListener(listener); + + listener.setTech(-20, 00, 0f, -300, 400); + window.display(); + + listener.setTech(-20, 00, 0f, -150, 800); + window.display(); + + listener.setTech(-20, 00, 0f, -50, 1000); + window.display(); + + destroyWindow(window); + } + + @Test + public void testRegionRendererMSAA02() throws InterruptedException { + if(Platform.CPUFamily.X86 != Platform.CPU_ARCH.family) { // FIXME + // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise). + // FIXME: Also the GLSL code for VARIABLE_CURVE is not fit for mobile yet! + System.err.println("disabled on non desktop (x86) arch for now .."); + return; + } + GLProfile glp = GLProfile.get(GLProfile.GL2ES2); + GLCapabilities caps = new GLCapabilities(glp); + caps.setAlphaBits(4); + caps.setSampleBuffers(true); + caps.setNumSamples(4); + + GLWindow window = createWindow("shape-vbaa0-msaa1", caps, 800, 400); + RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); + + GPURegionGLListener01 demo01Listener = new GPURegionGLListener01 (rs, Region.VARIABLE_CURVE_WEIGHT_BIT, 0, false, false); + demo01Listener.attachInputListenerTo(window); + window.addGLEventListener(demo01Listener); + + RegionGLListener listener = new RegionGLListener(demo01Listener, window.getTitle(), "GPURegion02"); + window.addGLEventListener(listener); + + listener.setTech(-20, 00, 0f, -300, 400); + window.display(); + + listener.setTech(-20, 00, 0f, -150, 800); + window.display(); + + listener.setTech(-20, 00, 0f, -50, 1000); + window.display(); + + destroyWindow(window); + } + + private class RegionGLListener implements GLEventListener { + String winTitle; + String name; + GPURegionRendererListenerBase01 impl; + + public RegionGLListener(GPURegionRendererListenerBase01 impl, String title, String name) { + this.impl = impl; + this.winTitle = title; + this.name = name; + } + + public void setTech(float xt, float yt, float angle, int zoom, int fboSize){ + impl.setMatrix(xt, yt, angle, zoom, fboSize); + } + + public void init(GLAutoDrawable drawable) { + impl.init(drawable); + } + + public void display(GLAutoDrawable drawable) { + impl.display(drawable); + + try { + impl.printScreen(drawable, "./", winTitle, name, false); + } catch (GLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void dispose(GLAutoDrawable drawable) { + impl.dispose(drawable); + + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + impl.reshape(drawable, x, y, width, height); + + } + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java index e7031f3a0..a09cc76ac 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java @@ -1,236 +1,236 @@ -/**
- * Copyright 2012 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.graph;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import javax.media.opengl.GL;
-import javax.media.opengl.GL2ES2;
-import javax.media.opengl.GLAutoDrawable;
-import javax.media.opengl.GLCapabilities;
-import javax.media.opengl.GLCapabilitiesImmutable;
-import javax.media.opengl.GLEventListener;
-import javax.media.opengl.GLException;
-import javax.media.opengl.GLProfile;
-import javax.media.opengl.GLRunnable;
-
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
-import com.jogamp.graph.font.Font;
-import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.geom.AABBox;
-import com.jogamp.graph.geom.opengl.SVertex;
-import com.jogamp.newt.opengl.GLWindow;
-import com.jogamp.opengl.test.junit.util.UITestCase;
-import com.jogamp.opengl.util.GLReadBufferUtil;
-import com.jogamp.opengl.util.glsl.ShaderState;
-
-
-public class TestTextRendererNEWT00 extends UITestCase {
- static final boolean DEBUG = false;
- static final boolean TRACE = false;
- static long duration = 100; // ms
-
- static final float[] textPosition = new float[] {0,0,0};
- static final int[] texSize = new int[] { 0 };
- static final int fontSize = 24;
- static Font font;
-
- @BeforeClass
- public static void setup() throws IOException {
- font = FontFactory.get(FontFactory.UBUNTU).getDefault();
- }
-
- static int atoi(String a) {
- try {
- return Integer.parseInt(a);
- } catch (Exception ex) { throw new RuntimeException(ex); }
- }
-
- public static void main(String args[]) throws IOException {
- for(int i=0; i<args.length; i++) {
- if(args[i].equals("-time")) {
- i++;
- duration = atoi(args[i]);
- }
- }
- String tstname = TestTextRendererNEWT00.class.getName();
- org.junit.runner.JUnitCore.main(tstname);
- }
-
- static void sleep() {
- try {
- System.err.println("** new frame ** (sleep: "+duration+"ms)");
- Thread.sleep(duration);
- } catch (InterruptedException ie) {}
- }
-
- static void destroyWindow(GLWindow window) {
- if(null!=window) {
- window.destroy();
- }
- }
-
- static GLWindow createWindow(String title, GLCapabilitiesImmutable caps, int width, int height) {
- Assert.assertNotNull(caps);
-
- GLWindow window = GLWindow.create(caps);
- window.setSize(width, height);
- window.setPosition(10, 10);
- window.setTitle(title);
- Assert.assertNotNull(window);
- window.setVisible(true);
-
- return window;
- }
-
- @Test
- public void testTextRendererMSAA01() throws InterruptedException {
- GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
- GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
- caps.setSampleBuffers(true);
- caps.setNumSamples(4);
- System.err.println("Requested: "+caps);
-
- GLWindow window = createWindow("text-vbaa0-msaa1", caps, 800, 400);
- window.display();
- System.err.println("Chosen: "+window.getChosenGLCapabilities());
-
- final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
- final TextRendererListener textGLListener = new TextRendererListener(rs);
- final TextRenderer renderer = textGLListener.getRenderer();
- window.addGLEventListener(textGLListener);
-
- window.invoke(true, new GLRunnable() {
- @Override
- public boolean run(GLAutoDrawable drawable) {
- int c=0;
- renderString(drawable, renderer, "GlueGen", c++, -1, -1000);
- renderString(drawable, renderer, "JOAL", c++, -1, -1000);
- renderString(drawable, renderer, "JOGL", c++, -1, -1000);
- renderString(drawable, renderer, "JOCL", c++, -1, -1000);
- try {
- textGLListener.printScreen(drawable, "./", "TestTextRendererNEWT00-snap"+screenshot_num, false);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return true;
- }
- });
- sleep();
-
- destroyWindow(window);
- }
- int screenshot_num = 0;
-
- int lastRow = -1;
-
- void renderString(GLAutoDrawable drawable, TextRenderer renderer, String text, int column, int row, int z0) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- final int height = drawable.getHeight();
-
- int dx = 0;
- int dy = height;
- if(0>row) {
- row = lastRow + 1;
- }
- AABBox textBox = font.getStringBounds(text, fontSize);
- dx += font.getAdvanceWidth('X', fontSize) * column;
- dy -= (int)textBox.getHeight() * ( row + 1 );
- renderer.resetModelview(null);
- renderer.translate(gl, dx, dy, z0);
- renderer.drawString3D(gl, font, text, textPosition, fontSize, texSize);
-
- lastRow = row;
- }
-
- public class TextRendererListener implements GLEventListener {
- private GLReadBufferUtil screenshot;
- private TextRenderer renderer;
-
- public TextRendererListener(RenderState rs) {
- this.screenshot = new GLReadBufferUtil(false, false);
- this.renderer = TextRenderer.create(rs, 0);
- }
-
- public final TextRenderer getRenderer() { return renderer; }
-
- public void printScreen(GLAutoDrawable drawable, String dir, String objName, boolean exportAlpha) throws GLException, IOException {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- pw.printf("%s-%03dx%03d-T%04d", objName, drawable.getWidth(), drawable.getHeight(), texSize[0]);
-
- final String filename = dir + sw +".png";
- if(screenshot.readPixels(drawable.getGL(), drawable, false)) {
- screenshot.write(new File(filename));
- }
- }
-
- public void init(GLAutoDrawable drawable) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
- renderer.init(gl);
- renderer.setAlpha(gl, 1.0f);
- renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
- }
-
- public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
-
- gl.glViewport(xstart, ystart, width, height);
- // renderer.reshapePerspective(gl, 45.0f, width, height, 0.1f, 1000.0f);
- renderer.reshapeOrtho(gl, width, height, 0.1f, 1000.0f);
- }
-
- public void display(GLAutoDrawable drawable) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
-
- renderString(drawable, renderer, "012345678901234567890123456789", 0, 0, -1000);
- renderString(drawable, renderer, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000);
- renderString(drawable, renderer, "Hello World", 0, -1, -1000);
- renderString(drawable, renderer, "4567890123456", 4, -1, -1000);
- renderString(drawable, renderer, "I like JogAmp", 4, -1, -1000);
- }
-
- public void dispose(GLAutoDrawable drawable) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- screenshot.dispose(gl);
- renderer.destroy(gl);
- }
- }
-
-}
+/** + * Copyright 2012 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.graph; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLRunnable; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.graph.curve.opengl.RenderState; +import com.jogamp.graph.curve.opengl.TextRenderer; +import com.jogamp.graph.font.Font; +import com.jogamp.graph.font.FontFactory; +import com.jogamp.graph.geom.AABBox; +import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.GLReadBufferUtil; +import com.jogamp.opengl.util.glsl.ShaderState; + + +public class TestTextRendererNEWT00 extends UITestCase { + static final boolean DEBUG = false; + static final boolean TRACE = false; + static long duration = 100; // ms + + static final float[] textPosition = new float[] {0,0,0}; + static final int[] texSize = new int[] { 0 }; + static final int fontSize = 24; + static Font font; + + @BeforeClass + public static void setup() throws IOException { + font = FontFactory.get(FontFactory.UBUNTU).getDefault(); + } + + static int atoi(String a) { + try { + return Integer.parseInt(a); + } catch (Exception ex) { throw new RuntimeException(ex); } + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + duration = atoi(args[i]); + } + } + String tstname = TestTextRendererNEWT00.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + + static void sleep() { + try { + System.err.println("** new frame ** (sleep: "+duration+"ms)"); + Thread.sleep(duration); + } catch (InterruptedException ie) {} + } + + static void destroyWindow(GLWindow window) { + if(null!=window) { + window.destroy(); + } + } + + static GLWindow createWindow(String title, GLCapabilitiesImmutable caps, int width, int height) { + Assert.assertNotNull(caps); + + GLWindow window = GLWindow.create(caps); + window.setSize(width, height); + window.setPosition(10, 10); + window.setTitle(title); + Assert.assertNotNull(window); + window.setVisible(true); + + return window; + } + + @Test + public void testTextRendererMSAA01() throws InterruptedException { + GLProfile glp = GLProfile.get(GLProfile.GL2ES2); + GLCapabilities caps = new GLCapabilities(glp); + caps.setAlphaBits(4); + caps.setSampleBuffers(true); + caps.setNumSamples(4); + System.err.println("Requested: "+caps); + + GLWindow window = createWindow("text-vbaa0-msaa1", caps, 800, 400); + window.display(); + System.err.println("Chosen: "+window.getChosenGLCapabilities()); + + final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); + final TextRendererListener textGLListener = new TextRendererListener(rs); + final TextRenderer renderer = textGLListener.getRenderer(); + window.addGLEventListener(textGLListener); + + window.invoke(true, new GLRunnable() { + @Override + public boolean run(GLAutoDrawable drawable) { + int c=0; + renderString(drawable, renderer, "GlueGen", c++, -1, -1000); + renderString(drawable, renderer, "JOAL", c++, -1, -1000); + renderString(drawable, renderer, "JOGL", c++, -1, -1000); + renderString(drawable, renderer, "JOCL", c++, -1, -1000); + try { + textGLListener.printScreen(drawable, "./", "TestTextRendererNEWT00-snap"+screenshot_num, false); + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + }); + sleep(); + + destroyWindow(window); + } + int screenshot_num = 0; + + int lastRow = -1; + + void renderString(GLAutoDrawable drawable, TextRenderer renderer, String text, int column, int row, int z0) { + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + final int height = drawable.getHeight(); + + int dx = 0; + int dy = height; + if(0>row) { + row = lastRow + 1; + } + AABBox textBox = font.getStringBounds(text, fontSize); + dx += font.getAdvanceWidth('X', fontSize) * column; + dy -= (int)textBox.getHeight() * ( row + 1 ); + renderer.resetModelview(null); + renderer.translate(gl, dx, dy, z0); + renderer.drawString3D(gl, font, text, textPosition, fontSize, texSize); + + lastRow = row; + } + + public class TextRendererListener implements GLEventListener { + private GLReadBufferUtil screenshot; + private TextRenderer renderer; + + public TextRendererListener(RenderState rs) { + this.screenshot = new GLReadBufferUtil(false, false); + this.renderer = TextRenderer.create(rs, 0); + } + + public final TextRenderer getRenderer() { return renderer; } + + public void printScreen(GLAutoDrawable drawable, String dir, String objName, boolean exportAlpha) throws GLException, IOException { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + pw.printf("%s-%03dx%03d-T%04d", objName, drawable.getWidth(), drawable.getHeight(), texSize[0]); + + final String filename = dir + sw +".png"; + if(screenshot.readPixels(drawable.getGL(), drawable, false)) { + screenshot.write(new File(filename)); + } + } + + public void init(GLAutoDrawable drawable) { + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + renderer.init(gl); + renderer.setAlpha(gl, 1.0f); + renderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); + } + + public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) { + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + + gl.glViewport(xstart, ystart, width, height); + // renderer.reshapePerspective(gl, 45.0f, width, height, 0.1f, 1000.0f); + renderer.reshapeOrtho(gl, width, height, 0.1f, 1000.0f); + } + + public void display(GLAutoDrawable drawable) { + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + + renderString(drawable, renderer, "012345678901234567890123456789", 0, 0, -1000); + renderString(drawable, renderer, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000); + renderString(drawable, renderer, "Hello World", 0, -1, -1000); + renderString(drawable, renderer, "4567890123456", 4, -1, -1000); + renderString(drawable, renderer, "I like JogAmp", 4, -1, -1000); + } + + public void dispose(GLAutoDrawable drawable) { + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + screenshot.dispose(gl); + renderer.destroy(gl); + } + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java index 72b64c7da..ea02e930c 100755 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java @@ -1,245 +1,245 @@ -/**
- * 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.graph;
-
-import java.io.IOException;
-
-import javax.media.opengl.GL;
-import javax.media.opengl.GL2ES2;
-import javax.media.opengl.GLAutoDrawable;
-import javax.media.opengl.GLCapabilities;
-import javax.media.opengl.GLCapabilitiesImmutable;
-import javax.media.opengl.GLException;
-import javax.media.opengl.GLProfile;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.jogamp.common.os.Platform;
-import com.jogamp.graph.curve.Region;
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.curve.opengl.TextRenderer;
-import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.geom.opengl.SVertex;
-import com.jogamp.newt.opengl.GLWindow;
-import com.jogamp.opengl.test.junit.graph.demos.GPUTextRendererListenerBase01;
-import com.jogamp.opengl.test.junit.util.UITestCase;
-import com.jogamp.opengl.util.glsl.ShaderState;
-
-
-public class TestTextRendererNEWT01 extends UITestCase {
- static final boolean DEBUG = false;
- static final boolean TRACE = false;
- static long duration = 100; // ms
-
- static int atoi(String a) {
- try {
- return Integer.parseInt(a);
- } catch (Exception ex) { throw new RuntimeException(ex); }
- }
-
- public static void main(String args[]) throws IOException {
- for(int i=0; i<args.length; i++) {
- if(args[i].equals("-time")) {
- i++;
- duration = atoi(args[i]);
- }
- }
- String tstname = TestTextRendererNEWT01.class.getName();
- org.junit.runner.JUnitCore.main(tstname);
- }
-
- static void sleep() {
- try {
- System.err.println("** new frame ** (sleep: "+duration+"ms)");
- Thread.sleep(duration);
- } catch (InterruptedException ie) {}
- }
-
- static void destroyWindow(GLWindow window) {
- if(null!=window) {
- window.destroy();
- }
- }
-
- static GLWindow createWindow(String title, GLCapabilitiesImmutable caps, int width, int height) {
- Assert.assertNotNull(caps);
-
- GLWindow window = GLWindow.create(caps);
- window.setSize(width, height);
- window.setPosition(10, 10);
- window.setTitle(title);
- Assert.assertNotNull(window);
- window.setVisible(true);
-
- return window;
- }
-
- @Test
- public void testTextRendererR2T01() throws InterruptedException {
- if(Platform.CPUFamily.X86 != Platform.CPU_ARCH.family) { // FIXME
- // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise).
- System.err.println("disabled on non desktop (x86) arch for now ..");
- return;
- }
- GLProfile glp = GLProfile.getGL2ES2();
-
- GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
- System.err.println("Requested: "+caps);
-
- GLWindow window = createWindow("text-vbaa1-msaa0", caps, 800,400);
- window.display();
- System.err.println("Chosen: "+window.getChosenGLCapabilities());
-
- RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
- TextGLListener textGLListener = new TextGLListener(rs, Region.VBAA_RENDERING_BIT, DEBUG, TRACE);
- textGLListener.attachInputListenerTo(window);
- window.addGLEventListener(textGLListener);
-
- if(textGLListener.setFontSet(FontFactory.UBUNTU, 0, 0)) {
- textGLListener.setTech(-400, -30, 0f, -1000, window.getWidth()*2);
- window.display();
- sleep();
-
- textGLListener.setTech(-400, -30, 0, -380, window.getWidth()*3);
- window.display();
- sleep();
-
- textGLListener.setTech(-400, -20, 0, -80, window.getWidth()*4);
- window.display();
- sleep();
- }
-
- if(textGLListener.setFontSet(FontFactory.JAVA, 0, 0)) {
- textGLListener.setTech(-400, -30, 0f, -1000, window.getWidth()*2);
- window.display();
- sleep();
-
- textGLListener.setTech(-400, -30, 0, -380, window.getWidth()*3);
- window.display();
- sleep();
-
- textGLListener.setTech(-400, -20, 0, -80, window.getWidth()*4);
- window.display();
- sleep();
- }
-
- destroyWindow(window);
- }
-
- @Test
- public void testTextRendererMSAA01() throws InterruptedException {
- GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
- GLCapabilities caps = new GLCapabilities(glp);
- caps.setAlphaBits(4);
- caps.setSampleBuffers(true);
- caps.setNumSamples(4);
- System.err.println("Requested: "+caps);
-
- GLWindow window = createWindow("text-vbaa0-msaa1", caps, 800, 400);
- window.display();
- System.err.println("Chosen: "+window.getChosenGLCapabilities());
-
- RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
- TextGLListener textGLListener = new TextGLListener(rs, 0, DEBUG, TRACE);
- textGLListener.attachInputListenerTo(window);
- window.addGLEventListener(textGLListener);
-
- if(textGLListener.setFontSet(FontFactory.UBUNTU, 0, 0)) {
- textGLListener.setTech(-400, -30, 0f, -1000, 0);
- window.display();
- sleep();
-
- textGLListener.setTech(-400, -30, 0, -380, 0);
- window.display();
- sleep();
-
- textGLListener.setTech(-400, -20, 0, -80, 0);
- window.display();
- sleep();
- }
-
- if(textGLListener.setFontSet(FontFactory.JAVA, 0, 0)) {
- textGLListener.setTech(-400, -30, 0f, -1000, 0);
- window.display();
- sleep();
-
- textGLListener.setTech(-400, -30, 0, -380, 0);
- window.display();
- sleep();
-
- textGLListener.setTech(-400, -20, 0, -80, 0);
- window.display();
- sleep();
- }
-
- destroyWindow(window);
- }
-
- private class TextGLListener extends GPUTextRendererListenerBase01 {
- String winTitle;
-
- public TextGLListener(RenderState rs, int type, boolean debug, boolean trace) {
- super(rs, type, debug, trace);
- }
-
- public void attachInputListenerTo(GLWindow window) {
- super.attachInputListenerTo(window);
- winTitle = window.getTitle();
- }
- public void setTech(float xt, float yt, float angle, int zoom, int fboSize){
- setMatrix(xt, yt, angle, zoom, fboSize);
- }
-
- public void init(GLAutoDrawable drawable) {
- super.init(drawable);
-
- GL2ES2 gl = drawable.getGL().getGL2ES2();
- gl.setSwapInterval(1);
- gl.glEnable(GL.GL_DEPTH_TEST);
-
- final TextRenderer textRenderer = (TextRenderer) getRenderer();
-
- textRenderer.setAlpha(gl, 1.0f);
- textRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
- }
-
- public void display(GLAutoDrawable drawable) {
- super.display(drawable);
-
- try {
- printScreen(drawable, "./", winTitle, false);
- } catch (GLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-}
+/** + * 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.graph; + +import java.io.IOException; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.common.os.Platform; +import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.RenderState; +import com.jogamp.graph.curve.opengl.TextRenderer; +import com.jogamp.graph.font.FontFactory; +import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.graph.demos.GPUTextRendererListenerBase01; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.glsl.ShaderState; + + +public class TestTextRendererNEWT01 extends UITestCase { + static final boolean DEBUG = false; + static final boolean TRACE = false; + static long duration = 100; // ms + + static int atoi(String a) { + try { + return Integer.parseInt(a); + } catch (Exception ex) { throw new RuntimeException(ex); } + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + duration = atoi(args[i]); + } + } + String tstname = TestTextRendererNEWT01.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + + static void sleep() { + try { + System.err.println("** new frame ** (sleep: "+duration+"ms)"); + Thread.sleep(duration); + } catch (InterruptedException ie) {} + } + + static void destroyWindow(GLWindow window) { + if(null!=window) { + window.destroy(); + } + } + + static GLWindow createWindow(String title, GLCapabilitiesImmutable caps, int width, int height) { + Assert.assertNotNull(caps); + + GLWindow window = GLWindow.create(caps); + window.setSize(width, height); + window.setPosition(10, 10); + window.setTitle(title); + Assert.assertNotNull(window); + window.setVisible(true); + + return window; + } + + @Test + public void testTextRendererR2T01() throws InterruptedException { + if(Platform.CPUFamily.X86 != Platform.CPU_ARCH.family) { // FIXME + // FIXME: Disabled for now - since it doesn't seem fit for mobile (performance wise). + System.err.println("disabled on non desktop (x86) arch for now .."); + return; + } + GLProfile glp = GLProfile.getGL2ES2(); + + GLCapabilities caps = new GLCapabilities(glp); + caps.setAlphaBits(4); + System.err.println("Requested: "+caps); + + GLWindow window = createWindow("text-vbaa1-msaa0", caps, 800,400); + window.display(); + System.err.println("Chosen: "+window.getChosenGLCapabilities()); + + RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); + TextGLListener textGLListener = new TextGLListener(rs, Region.VBAA_RENDERING_BIT, DEBUG, TRACE); + textGLListener.attachInputListenerTo(window); + window.addGLEventListener(textGLListener); + + if(textGLListener.setFontSet(FontFactory.UBUNTU, 0, 0)) { + textGLListener.setTech(-400, -30, 0f, -1000, window.getWidth()*2); + window.display(); + sleep(); + + textGLListener.setTech(-400, -30, 0, -380, window.getWidth()*3); + window.display(); + sleep(); + + textGLListener.setTech(-400, -20, 0, -80, window.getWidth()*4); + window.display(); + sleep(); + } + + if(textGLListener.setFontSet(FontFactory.JAVA, 0, 0)) { + textGLListener.setTech(-400, -30, 0f, -1000, window.getWidth()*2); + window.display(); + sleep(); + + textGLListener.setTech(-400, -30, 0, -380, window.getWidth()*3); + window.display(); + sleep(); + + textGLListener.setTech(-400, -20, 0, -80, window.getWidth()*4); + window.display(); + sleep(); + } + + destroyWindow(window); + } + + @Test + public void testTextRendererMSAA01() throws InterruptedException { + GLProfile glp = GLProfile.get(GLProfile.GL2ES2); + GLCapabilities caps = new GLCapabilities(glp); + caps.setAlphaBits(4); + caps.setSampleBuffers(true); + caps.setNumSamples(4); + System.err.println("Requested: "+caps); + + GLWindow window = createWindow("text-vbaa0-msaa1", caps, 800, 400); + window.display(); + System.err.println("Chosen: "+window.getChosenGLCapabilities()); + + RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); + TextGLListener textGLListener = new TextGLListener(rs, 0, DEBUG, TRACE); + textGLListener.attachInputListenerTo(window); + window.addGLEventListener(textGLListener); + + if(textGLListener.setFontSet(FontFactory.UBUNTU, 0, 0)) { + textGLListener.setTech(-400, -30, 0f, -1000, 0); + window.display(); + sleep(); + + textGLListener.setTech(-400, -30, 0, -380, 0); + window.display(); + sleep(); + + textGLListener.setTech(-400, -20, 0, -80, 0); + window.display(); + sleep(); + } + + if(textGLListener.setFontSet(FontFactory.JAVA, 0, 0)) { + textGLListener.setTech(-400, -30, 0f, -1000, 0); + window.display(); + sleep(); + + textGLListener.setTech(-400, -30, 0, -380, 0); + window.display(); + sleep(); + + textGLListener.setTech(-400, -20, 0, -80, 0); + window.display(); + sleep(); + } + + destroyWindow(window); + } + + private class TextGLListener extends GPUTextRendererListenerBase01 { + String winTitle; + + public TextGLListener(RenderState rs, int type, boolean debug, boolean trace) { + super(rs, type, debug, trace); + } + + public void attachInputListenerTo(GLWindow window) { + super.attachInputListenerTo(window); + winTitle = window.getTitle(); + } + public void setTech(float xt, float yt, float angle, int zoom, int fboSize){ + setMatrix(xt, yt, angle, zoom, fboSize); + } + + public void init(GLAutoDrawable drawable) { + super.init(drawable); + + GL2ES2 gl = drawable.getGL().getGL2ES2(); + gl.setSwapInterval(1); + gl.glEnable(GL.GL_DEPTH_TEST); + + final TextRenderer textRenderer = (TextRenderer) getRenderer(); + + textRenderer.setAlpha(gl, 1.0f); + textRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); + } + + public void display(GLAutoDrawable drawable) { + super.display(drawable); + + try { + printScreen(drawable, "./", winTitle, false); + } catch (GLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/OneTriangle.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/OneTriangle.java index a2455e743..8c9f53b82 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/OneTriangle.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/OneTriangle.java @@ -1,78 +1,78 @@ -/**
- * 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.es1;
-
-import javax.media.opengl.GL;
-import javax.media.opengl.GL2ES1;
-import javax.media.opengl.glu.GLU;
-import javax.media.opengl.glu.gl2es1.GLUgl2es1;
-
-import com.jogamp.opengl.util.ImmModeSink;
-
-/**
- * A utility class to encapsulate drawing a single triangle for unit tests.
- * @author Wade Walker
- */
-public class OneTriangle {
-
- public static void setup( GL2ES1 gl, int width, int height ) {
- gl.glMatrixMode( GL2ES1.GL_PROJECTION );
- gl.glLoadIdentity();
-
- // coordinate system origin at lower left with width and height same as the window
- GLU glu = new GLUgl2es1();
- glu.gluOrtho2D( 0.0f, width, 0.0f, height );
-
- gl.glMatrixMode( GL2ES1.GL_MODELVIEW );
- gl.glLoadIdentity();
-
- gl.glViewport( 0, 0, width, height );
- }
-
- public static void render( GL2ES1 gl, int width, int height) {
- gl.glClear( GL.GL_COLOR_BUFFER_BIT );
-
- // draw a triangle filling the window
- gl.glLoadIdentity();
-
- ImmModeSink immModeSink = ImmModeSink.createFixed(gl, GL.GL_STATIC_DRAW, 3,
- 3, GL.GL_FLOAT, // vertex
- 3, GL.GL_FLOAT, // color
- 0, GL.GL_FLOAT,// normal
- 0, GL.GL_FLOAT); // texture
- immModeSink.glBegin(GL.GL_TRIANGLES);
- immModeSink.glColor3f( 1, 0, 0 );
- immModeSink.glVertex2f( 0, 0 );
- immModeSink.glColor3f( 0, 1, 0 );
- immModeSink.glVertex2f( width, 0 );
- immModeSink.glColor3f( 0, 0, 1 );
- immModeSink.glVertex2f( width / 2, height );
- immModeSink.glEnd(gl, true);
- }
-}
+/** + * 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.es1; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES1; +import javax.media.opengl.glu.GLU; +import javax.media.opengl.glu.gl2es1.GLUgl2es1; + +import com.jogamp.opengl.util.ImmModeSink; + +/** + * A utility class to encapsulate drawing a single triangle for unit tests. + * @author Wade Walker + */ +public class OneTriangle { + + public static void setup( GL2ES1 gl, int width, int height ) { + gl.glMatrixMode( GL2ES1.GL_PROJECTION ); + gl.glLoadIdentity(); + + // coordinate system origin at lower left with width and height same as the window + GLU glu = new GLUgl2es1(); + glu.gluOrtho2D( 0.0f, width, 0.0f, height ); + + gl.glMatrixMode( GL2ES1.GL_MODELVIEW ); + gl.glLoadIdentity(); + + gl.glViewport( 0, 0, width, height ); + } + + public static void render( GL2ES1 gl, int width, int height) { + gl.glClear( GL.GL_COLOR_BUFFER_BIT ); + + // draw a triangle filling the window + gl.glLoadIdentity(); + + ImmModeSink immModeSink = ImmModeSink.createFixed(gl, GL.GL_STATIC_DRAW, 3, + 3, GL.GL_FLOAT, // vertex + 3, GL.GL_FLOAT, // color + 0, GL.GL_FLOAT,// normal + 0, GL.GL_FLOAT); // texture + immModeSink.glBegin(GL.GL_TRIANGLES); + immModeSink.glColor3f( 1, 0, 0 ); + immModeSink.glVertex2f( 0, 0 ); + immModeSink.glColor3f( 0, 1, 0 ); + immModeSink.glVertex2f( width, 0 ); + immModeSink.glColor3f( 0, 0, 1 ); + immModeSink.glVertex2f( width / 2, height ); + immModeSink.glEnd(gl, true); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java index 03fed5e41..021e1178a 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java @@ -1,195 +1,195 @@ -/**
- * 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.swt;
-
-import java.awt.Frame;
-import java.lang.reflect.InvocationTargetException;
-
-import javax.media.opengl.GL2ES1;
-import javax.media.opengl.GLAutoDrawable;
-import javax.media.opengl.GLCapabilities;
-import javax.media.opengl.GLEventListener;
-import javax.media.opengl.GLProfile;
-import javax.media.opengl.awt.GLCanvas;
-
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.awt.SWT_AWT;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.After;
-import org.junit.Test;
-
-import com.jogamp.nativewindow.swt.SWTAccessor;
-import com.jogamp.opengl.test.junit.jogl.demos.es1.OneTriangle;
-import com.jogamp.opengl.test.junit.util.UITestCase;
-
-/**
- * Tests that a basic SWT app can open without crashing under different GL profiles. Uses the AWT GL canvas with
- * the SWT_AWT bridge.
- * @author Wade Walker, et.al.
- */
-public class TestSWTAWT01GLn extends UITestCase {
-
- static final int duration = 250;
-
- Display display = null;
- Shell shell = null;
- Composite composite = null;
- Frame frame = null;
- GLCanvas glcanvas = null;
-
- @BeforeClass
- public static void startup() {
- System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() );
- if(!GLProfile.isAvailable(GLProfile.GL2)) {
- setTestSupported(false);
- }
- }
-
- @Before
- public void init() throws InterruptedException, InvocationTargetException {
- SWTAccessor.invoke(true, new Runnable() {
- public void run() {
- display = new Display();
- Assert.assertNotNull( display );
- shell = new Shell( display );
- Assert.assertNotNull( shell );
- shell.setLayout( new FillLayout() );
- composite = new Composite( shell, SWT.EMBEDDED | SWT.NO_BACKGROUND );
- composite.setLayout( new FillLayout() );
- Assert.assertNotNull( composite );
- frame = SWT_AWT.new_Frame( composite );
- Assert.assertNotNull( frame );
- }});
- }
-
- @After
- public void release() throws InterruptedException, InvocationTargetException {
- Assert.assertNotNull( display );
- Assert.assertNotNull( shell );
- Assert.assertNotNull( composite );
- Assert.assertNotNull( glcanvas );
- javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- frame.setVisible(false);
- frame.remove(glcanvas);
- frame.dispose();
- frame = null;
- glcanvas = null;
- }});
-
- SWTAccessor.invoke(true, new Runnable() {
- public void run() {
- composite.dispose();
- shell.close();
- shell.dispose();
- display.dispose();
- display = null;
- shell = null;
- composite = null;
- }});
- }
-
- protected void runTestGL( GLProfile glprofile ) throws InterruptedException {
- GLCapabilities glcapabilities = new GLCapabilities( glprofile );
- glcanvas = new GLCanvas( glcapabilities );
- Assert.assertNotNull( glcanvas );
- frame.add( glcanvas );
-
- glcanvas.addGLEventListener( new GLEventListener() {
- /* @Override */
- public void init( GLAutoDrawable glautodrawable ) {
- }
-
- /* @Override */
- public void dispose( GLAutoDrawable glautodrawable ) {
- }
-
- /* @Override */
- public void display( GLAutoDrawable glautodrawable ) {
- Rectangle rectangle = new Rectangle( 0, 0, glautodrawable.getWidth(), glautodrawable.getHeight() );
- GL2ES1 gl = glautodrawable.getGL().getGL2ES1();
- OneTriangle.render( gl, rectangle.width, rectangle.height );
- }
-
- /* @Override */
- public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {
- Rectangle rectangle = new Rectangle( 0, 0, glautodrawable.getWidth(), glautodrawable.getHeight() );
- GL2ES1 gl = glautodrawable.getGL().getGL2ES1();
- OneTriangle.setup( gl, rectangle.width, rectangle.height );
- }
- });
-
- SWTAccessor.invoke(true, new Runnable() {
- public void run() {
- shell.setText( getClass().getName() );
- shell.setSize( 640, 480 );
- shell.open();
- }});
-
- long lStartTime = System.currentTimeMillis();
- long lEndTime = lStartTime + duration;
- try {
- while( (System.currentTimeMillis() < lEndTime) && !composite.isDisposed() ) {
- SWTAccessor.invoke(true, new Runnable() {
- public void run() {
- if( !display.readAndDispatch() ) {
- // blocks on linux .. display.sleep();
- try {
- Thread.sleep(10);
- } catch (InterruptedException e) { }
- }
- }});
- }
- }
- catch( Throwable throwable ) {
- throwable.printStackTrace();
- Assume.assumeNoException( throwable );
- }
- }
-
- @Test
- public void test() throws InterruptedException {
- GLProfile glprofile = GLProfile.getGL2ES1();
- runTestGL( glprofile );
- }
-
- public static void main(String args[]) {
- org.junit.runner.JUnitCore.main( TestSWTAWT01GLn.class.getName() );
- }
-}
+/** + * 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.swt; + +import java.awt.Frame; +import java.lang.reflect.InvocationTargetException; + +import javax.media.opengl.GL2ES1; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; + + +import org.eclipse.swt.SWT; +import org.eclipse.swt.awt.SWT_AWT; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Test; + +import com.jogamp.nativewindow.swt.SWTAccessor; +import com.jogamp.opengl.test.junit.jogl.demos.es1.OneTriangle; +import com.jogamp.opengl.test.junit.util.UITestCase; + +/** + * Tests that a basic SWT app can open without crashing under different GL profiles. Uses the AWT GL canvas with + * the SWT_AWT bridge. + * @author Wade Walker, et.al. + */ +public class TestSWTAWT01GLn extends UITestCase { + + static final int duration = 250; + + Display display = null; + Shell shell = null; + Composite composite = null; + Frame frame = null; + GLCanvas glcanvas = null; + + @BeforeClass + public static void startup() { + System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() ); + if(!GLProfile.isAvailable(GLProfile.GL2)) { + setTestSupported(false); + } + } + + @Before + public void init() throws InterruptedException, InvocationTargetException { + SWTAccessor.invoke(true, new Runnable() { + public void run() { + display = new Display(); + Assert.assertNotNull( display ); + shell = new Shell( display ); + Assert.assertNotNull( shell ); + shell.setLayout( new FillLayout() ); + composite = new Composite( shell, SWT.EMBEDDED | SWT.NO_BACKGROUND ); + composite.setLayout( new FillLayout() ); + Assert.assertNotNull( composite ); + frame = SWT_AWT.new_Frame( composite ); + Assert.assertNotNull( frame ); + }}); + } + + @After + public void release() throws InterruptedException, InvocationTargetException { + Assert.assertNotNull( display ); + Assert.assertNotNull( shell ); + Assert.assertNotNull( composite ); + Assert.assertNotNull( glcanvas ); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(false); + frame.remove(glcanvas); + frame.dispose(); + frame = null; + glcanvas = null; + }}); + + SWTAccessor.invoke(true, new Runnable() { + public void run() { + composite.dispose(); + shell.close(); + shell.dispose(); + display.dispose(); + display = null; + shell = null; + composite = null; + }}); + } + + protected void runTestGL( GLProfile glprofile ) throws InterruptedException { + GLCapabilities glcapabilities = new GLCapabilities( glprofile ); + glcanvas = new GLCanvas( glcapabilities ); + Assert.assertNotNull( glcanvas ); + frame.add( glcanvas ); + + glcanvas.addGLEventListener( new GLEventListener() { + /* @Override */ + public void init( GLAutoDrawable glautodrawable ) { + } + + /* @Override */ + public void dispose( GLAutoDrawable glautodrawable ) { + } + + /* @Override */ + public void display( GLAutoDrawable glautodrawable ) { + Rectangle rectangle = new Rectangle( 0, 0, glautodrawable.getWidth(), glautodrawable.getHeight() ); + GL2ES1 gl = glautodrawable.getGL().getGL2ES1(); + OneTriangle.render( gl, rectangle.width, rectangle.height ); + } + + /* @Override */ + public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) { + Rectangle rectangle = new Rectangle( 0, 0, glautodrawable.getWidth(), glautodrawable.getHeight() ); + GL2ES1 gl = glautodrawable.getGL().getGL2ES1(); + OneTriangle.setup( gl, rectangle.width, rectangle.height ); + } + }); + + SWTAccessor.invoke(true, new Runnable() { + public void run() { + shell.setText( getClass().getName() ); + shell.setSize( 640, 480 ); + shell.open(); + }}); + + long lStartTime = System.currentTimeMillis(); + long lEndTime = lStartTime + duration; + try { + while( (System.currentTimeMillis() < lEndTime) && !composite.isDisposed() ) { + SWTAccessor.invoke(true, new Runnable() { + public void run() { + if( !display.readAndDispatch() ) { + // blocks on linux .. display.sleep(); + try { + Thread.sleep(10); + } catch (InterruptedException e) { } + } + }}); + } + } + catch( Throwable throwable ) { + throwable.printStackTrace(); + Assume.assumeNoException( throwable ); + } + } + + @Test + public void test() throws InterruptedException { + GLProfile glprofile = GLProfile.getGL2ES1(); + runTestGL( glprofile ); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main( TestSWTAWT01GLn.class.getName() ); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTEclipseGLCanvas01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTEclipseGLCanvas01GLn.java index ce3100a50..f38d5c7dc 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTEclipseGLCanvas01GLn.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTEclipseGLCanvas01GLn.java @@ -1,194 +1,194 @@ -/**
- * 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.swt;
-
-import javax.media.opengl.GL2ES1;
-import javax.media.opengl.GLContext;
-import javax.media.opengl.GLDrawableFactory;
-import javax.media.opengl.GLProfile;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.opengl.GLCanvas;
-import org.eclipse.swt.opengl.GLData;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
-
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.After;
-import org.junit.Test;
-
-import com.jogamp.opengl.test.junit.jogl.demos.es1.OneTriangle;
-import com.jogamp.opengl.test.junit.util.UITestCase;
-
-/**
- * Tests that a basic SWT app can open without crashing under different GL profiles.
- * <p>
- * Uses the SWT GLCanvas <code>org.eclipse.swt.opengl.GLCanvas</code>.
- * </p>
- * @author Wade Walker, et.al.
- */
-public class TestSWTEclipseGLCanvas01GLn extends UITestCase {
-
- static int duration = 250;
-
- static final int iwidth = 640;
- static final int iheight = 480;
-
- Display display = null;
- Shell shell = null;
- Composite composite = null;
-
- @BeforeClass
- public static void startup() {
- System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() );
- }
-
- @Before
- public void init() {
- display = new Display();
- Assert.assertNotNull( display );
- shell = new Shell( display );
- Assert.assertNotNull( shell );
- shell.setLayout( new FillLayout() );
- composite = new Composite( shell, SWT.NONE );
- composite.setLayout( new FillLayout() );
- Assert.assertNotNull( composite );
- }
-
- @After
- public void release() {
- Assert.assertNotNull( display );
- Assert.assertNotNull( shell );
- Assert.assertNotNull( composite );
- try {
- composite.dispose();
- shell.dispose();
- display.dispose();
- }
- catch( Throwable throwable ) {
- throwable.printStackTrace();
- Assume.assumeNoException( throwable );
- }
- display = null;
- shell = null;
- composite = null;
- }
-
- protected void runTestAGL( GLProfile glprofile ) throws InterruptedException {
- GLData gldata = new GLData();
- gldata.doubleBuffer = true;
- // need SWT.NO_BACKGROUND to prevent SWT from clearing the window
- // at the wrong times (we use glClear for this instead)
- final GLCanvas glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );
- Assert.assertNotNull( glcanvas );
- glcanvas.setCurrent();
- final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext();
- Assert.assertNotNull( glcontext );
-
- // fix the viewport when the user resizes the window
- glcanvas.addListener( SWT.Resize, new Listener() {
- public void handleEvent( Event event ) {
- Rectangle rectangle = glcanvas.getClientArea();
- glcanvas.setCurrent();
- glcontext.makeCurrent();
- GL2ES1 gl = glcontext.getGL().getGL2ES1();
- OneTriangle.setup( gl, rectangle.width, rectangle.height );
- glcontext.release();
- System.err.println("resize");
- }
- });
-
- // draw the triangle when the OS tells us that any part of the window needs drawing
- glcanvas.addPaintListener( new PaintListener() {
- public void paintControl( PaintEvent paintevent ) {
- Rectangle rectangle = glcanvas.getClientArea();
- glcanvas.setCurrent();
- glcontext.makeCurrent();
- GL2ES1 gl = glcontext.getGL().getGL2ES1();
- OneTriangle.render( gl, rectangle.width, rectangle.height );
- glcanvas.swapBuffers();
- glcontext.release();
- System.err.println("paint");
- }
- });
-
- shell.setText( getClass().getName() );
- shell.setSize( 640, 480 );
- shell.open();
-
- long lStartTime = System.currentTimeMillis();
- long lEndTime = lStartTime + duration;
- try {
- while( (System.currentTimeMillis() < lEndTime) && !glcanvas.isDisposed() ) {
- if( !display.readAndDispatch() ) {
- // blocks on linux .. display.sleep();
- Thread.sleep(10);
- }
- }
- } catch( Throwable throwable ) {
- throwable.printStackTrace();
- Assume.assumeNoException( throwable );
- }
- glcanvas.dispose();
- }
-
- @Test
- public void test() throws InterruptedException {
- GLProfile glprofile = GLProfile.getGL2ES1();
- runTestAGL( glprofile );
- }
-
- static int atoi(String a) {
- int i=0;
- try {
- i = Integer.parseInt(a);
- } catch (Exception ex) { ex.printStackTrace(); }
- return i;
- }
-
- public static void main(String args[]) {
- for(int i=0; i<args.length; i++) {
- if(args[i].equals("-time")) {
- duration = atoi(args[++i]);
- }
- }
- System.out.println("durationPerTest: "+duration);
- org.junit.runner.JUnitCore.main(TestSWTEclipseGLCanvas01GLn.class.getName());
- }
-}
+/** + * 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.swt; + +import javax.media.opengl.GL2ES1; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLProfile; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.opengl.GLCanvas; +import org.eclipse.swt.opengl.GLData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; + +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Test; + +import com.jogamp.opengl.test.junit.jogl.demos.es1.OneTriangle; +import com.jogamp.opengl.test.junit.util.UITestCase; + +/** + * Tests that a basic SWT app can open without crashing under different GL profiles. + * <p> + * Uses the SWT GLCanvas <code>org.eclipse.swt.opengl.GLCanvas</code>. + * </p> + * @author Wade Walker, et.al. + */ +public class TestSWTEclipseGLCanvas01GLn extends UITestCase { + + static int duration = 250; + + static final int iwidth = 640; + static final int iheight = 480; + + Display display = null; + Shell shell = null; + Composite composite = null; + + @BeforeClass + public static void startup() { + System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() ); + } + + @Before + public void init() { + display = new Display(); + Assert.assertNotNull( display ); + shell = new Shell( display ); + Assert.assertNotNull( shell ); + shell.setLayout( new FillLayout() ); + composite = new Composite( shell, SWT.NONE ); + composite.setLayout( new FillLayout() ); + Assert.assertNotNull( composite ); + } + + @After + public void release() { + Assert.assertNotNull( display ); + Assert.assertNotNull( shell ); + Assert.assertNotNull( composite ); + try { + composite.dispose(); + shell.dispose(); + display.dispose(); + } + catch( Throwable throwable ) { + throwable.printStackTrace(); + Assume.assumeNoException( throwable ); + } + display = null; + shell = null; + composite = null; + } + + protected void runTestAGL( GLProfile glprofile ) throws InterruptedException { + GLData gldata = new GLData(); + gldata.doubleBuffer = true; + // need SWT.NO_BACKGROUND to prevent SWT from clearing the window + // at the wrong times (we use glClear for this instead) + final GLCanvas glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata ); + Assert.assertNotNull( glcanvas ); + glcanvas.setCurrent(); + final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext(); + Assert.assertNotNull( glcontext ); + + // fix the viewport when the user resizes the window + glcanvas.addListener( SWT.Resize, new Listener() { + public void handleEvent( Event event ) { + Rectangle rectangle = glcanvas.getClientArea(); + glcanvas.setCurrent(); + glcontext.makeCurrent(); + GL2ES1 gl = glcontext.getGL().getGL2ES1(); + OneTriangle.setup( gl, rectangle.width, rectangle.height ); + glcontext.release(); + System.err.println("resize"); + } + }); + + // draw the triangle when the OS tells us that any part of the window needs drawing + glcanvas.addPaintListener( new PaintListener() { + public void paintControl( PaintEvent paintevent ) { + Rectangle rectangle = glcanvas.getClientArea(); + glcanvas.setCurrent(); + glcontext.makeCurrent(); + GL2ES1 gl = glcontext.getGL().getGL2ES1(); + OneTriangle.render( gl, rectangle.width, rectangle.height ); + glcanvas.swapBuffers(); + glcontext.release(); + System.err.println("paint"); + } + }); + + shell.setText( getClass().getName() ); + shell.setSize( 640, 480 ); + shell.open(); + + long lStartTime = System.currentTimeMillis(); + long lEndTime = lStartTime + duration; + try { + while( (System.currentTimeMillis() < lEndTime) && !glcanvas.isDisposed() ) { + if( !display.readAndDispatch() ) { + // blocks on linux .. display.sleep(); + Thread.sleep(10); + } + } + } catch( Throwable throwable ) { + throwable.printStackTrace(); + Assume.assumeNoException( throwable ); + } + glcanvas.dispose(); + } + + @Test + public void test() throws InterruptedException { + GLProfile glprofile = GLProfile.getGL2ES1(); + runTestAGL( glprofile ); + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + duration = atoi(args[++i]); + } + } + System.out.println("durationPerTest: "+duration); + org.junit.runner.JUnitCore.main(TestSWTEclipseGLCanvas01GLn.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTJOGLGLCanvas01GLnAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTJOGLGLCanvas01GLnAWT.java index f7e839c50..6abca288b 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTJOGLGLCanvas01GLnAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTJOGLGLCanvas01GLnAWT.java @@ -1,174 +1,174 @@ -/**
- * 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.swt;
-
-import javax.media.opengl.GLAutoDrawable;
-import javax.media.opengl.GLCapabilities;
-import javax.media.opengl.GLCapabilitiesImmutable;
-import javax.media.opengl.GLEventListener;
-import javax.media.opengl.GLProfile;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.After;
-import org.junit.Test;
-
-import com.jogamp.opengl.swt.GLCanvas;
-import com.jogamp.opengl.test.junit.jogl.demos.es1.OneTriangle;
-import com.jogamp.opengl.test.junit.util.UITestCase;
-
-/**
- * Tests that a basic SWT app can open without crashing under different GL profiles.
- * <p>
- * Uses JOGL's new SWT GLCanvas.
- * </p>
- * <p>
- * Holds AWT in it's test name, since our impl. still needs the AWT threading,
- * see {@link GLCanvas}.
- * </p>
- * @author Wade Walker, et.al.
- */
-public class TestSWTJOGLGLCanvas01GLnAWT extends UITestCase {
-
- static int duration = 250;
-
- static final int iwidth = 640;
- static final int iheight = 480;
-
- Display display = null;
- Shell shell = null;
- Composite composite = null;
-
- @BeforeClass
- public static void startup() {
- System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() );
- }
-
- @Before
- public void init() {
- display = new Display();
- Assert.assertNotNull( display );
- shell = new Shell( display );
- Assert.assertNotNull( shell );
- shell.setLayout( new FillLayout() );
- composite = new Composite( shell, SWT.NONE );
- composite.setLayout( new FillLayout() );
- Assert.assertNotNull( composite );
- }
-
- @After
- public void release() {
- Assert.assertNotNull( display );
- Assert.assertNotNull( shell );
- Assert.assertNotNull( composite );
- try {
- composite.dispose();
- shell.dispose();
- display.dispose();
- }
- catch( Throwable throwable ) {
- throwable.printStackTrace();
- Assume.assumeNoException( throwable );
- }
- display = null;
- shell = null;
- composite = null;
- }
-
- protected void runTestAGL( GLProfile glprofile ) throws InterruptedException {
- // need SWT.NO_BACKGROUND to prevent SWT from clearing the window
- // at the wrong times (we use glClear for this instead)
- final GLCapabilitiesImmutable caps = new GLCapabilities( glprofile );
-
- final GLCanvas canvas = new GLCanvas( composite, SWT.NO_BACKGROUND, caps, null, null);
- Assert.assertNotNull( canvas );
-
- canvas.addGLEventListener(new GLEventListener() {
- public void init(final GLAutoDrawable drawable) { }
- public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
- OneTriangle.setup( drawable.getGL().getGL2(), width, height );
- }
- public void display(final GLAutoDrawable drawable) {
- OneTriangle.render( drawable.getGL().getGL2(), drawable.getWidth(), drawable.getHeight());
- }
- public void dispose(final GLAutoDrawable drawable) {}
- });
-
- shell.setText( getClass().getName() );
- shell.setSize( 640, 480 );
- shell.open();
-
- long lStartTime = System.currentTimeMillis();
- long lEndTime = lStartTime + duration;
- try {
- while( (System.currentTimeMillis() < lEndTime) && !canvas.isDisposed() ) {
- if( !display.readAndDispatch() ) {
- // blocks on linux .. display.sleep();
- Thread.sleep(10);
- }
- }
- } catch( Throwable throwable ) {
- throwable.printStackTrace();
- Assume.assumeNoException( throwable );
- }
- canvas.dispose();
- }
-
- @Test
- public void test() throws InterruptedException {
- GLProfile glprofile = GLProfile.getGL2ES1();
- runTestAGL( glprofile );
- }
-
- static int atoi(String a) {
- int i=0;
- try {
- i = Integer.parseInt(a);
- } catch (Exception ex) { ex.printStackTrace(); }
- return i;
- }
-
- public static void main(String args[]) {
- for(int i=0; i<args.length; i++) {
- if(args[i].equals("-time")) {
- duration = atoi(args[++i]);
- }
- }
- System.out.println("durationPerTest: "+duration);
- org.junit.runner.JUnitCore.main(TestSWTJOGLGLCanvas01GLnAWT.class.getName());
- }
-}
+/** + * 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.swt; + +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Test; + +import com.jogamp.opengl.swt.GLCanvas; +import com.jogamp.opengl.test.junit.jogl.demos.es1.OneTriangle; +import com.jogamp.opengl.test.junit.util.UITestCase; + +/** + * Tests that a basic SWT app can open without crashing under different GL profiles. + * <p> + * Uses JOGL's new SWT GLCanvas. + * </p> + * <p> + * Holds AWT in it's test name, since our impl. still needs the AWT threading, + * see {@link GLCanvas}. + * </p> + * @author Wade Walker, et.al. + */ +public class TestSWTJOGLGLCanvas01GLnAWT extends UITestCase { + + static int duration = 250; + + static final int iwidth = 640; + static final int iheight = 480; + + Display display = null; + Shell shell = null; + Composite composite = null; + + @BeforeClass + public static void startup() { + System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() ); + } + + @Before + public void init() { + display = new Display(); + Assert.assertNotNull( display ); + shell = new Shell( display ); + Assert.assertNotNull( shell ); + shell.setLayout( new FillLayout() ); + composite = new Composite( shell, SWT.NONE ); + composite.setLayout( new FillLayout() ); + Assert.assertNotNull( composite ); + } + + @After + public void release() { + Assert.assertNotNull( display ); + Assert.assertNotNull( shell ); + Assert.assertNotNull( composite ); + try { + composite.dispose(); + shell.dispose(); + display.dispose(); + } + catch( Throwable throwable ) { + throwable.printStackTrace(); + Assume.assumeNoException( throwable ); + } + display = null; + shell = null; + composite = null; + } + + protected void runTestAGL( GLProfile glprofile ) throws InterruptedException { + // need SWT.NO_BACKGROUND to prevent SWT from clearing the window + // at the wrong times (we use glClear for this instead) + final GLCapabilitiesImmutable caps = new GLCapabilities( glprofile ); + + final GLCanvas canvas = new GLCanvas( composite, SWT.NO_BACKGROUND, caps, null, null); + Assert.assertNotNull( canvas ); + + canvas.addGLEventListener(new GLEventListener() { + public void init(final GLAutoDrawable drawable) { } + public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { + OneTriangle.setup( drawable.getGL().getGL2(), width, height ); + } + public void display(final GLAutoDrawable drawable) { + OneTriangle.render( drawable.getGL().getGL2(), drawable.getWidth(), drawable.getHeight()); + } + public void dispose(final GLAutoDrawable drawable) {} + }); + + shell.setText( getClass().getName() ); + shell.setSize( 640, 480 ); + shell.open(); + + long lStartTime = System.currentTimeMillis(); + long lEndTime = lStartTime + duration; + try { + while( (System.currentTimeMillis() < lEndTime) && !canvas.isDisposed() ) { + if( !display.readAndDispatch() ) { + // blocks on linux .. display.sleep(); + Thread.sleep(10); + } + } + } catch( Throwable throwable ) { + throwable.printStackTrace(); + Assume.assumeNoException( throwable ); + } + canvas.dispose(); + } + + @Test + public void test() throws InterruptedException { + GLProfile glprofile = GLProfile.getGL2ES1(); + runTestAGL( glprofile ); + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + duration = atoi(args[++i]); + } + } + System.out.println("durationPerTest: "+duration); + org.junit.runner.JUnitCore.main(TestSWTJOGLGLCanvas01GLnAWT.class.getName()); + } +} |