diff options
author | Sven Gothel <[email protected]> | 2012-05-16 09:11:31 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-05-16 09:11:31 +0200 |
commit | cf51a97f04011ce643c42d6872f37cc69f4342aa (patch) | |
tree | 4328dbd3ceecc89b3f81b3486b2c67f935f2f53d | |
parent | 9c1385ba05d8996ecd16d9b9e9e40fc87c97500a (diff) |
Graph/Font Demo: Add simple 'one-file' demo/test 'TestTextRendererNEWT10' w/o GLEventListener
-rwxr-xr-x | make/scripts/tests.sh | 3 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java | 168 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java | 1 |
3 files changed, 170 insertions, 2 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 88c5d2811..a678bdf05 100755 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -339,7 +339,8 @@ function testawtswt() { #testnoawt com.jogamp.opengl.test.junit.jogl.glsl.TestRulerNEWT01 $* #testnoawt com.jogamp.opengl.test.junit.jogl.glsl.TestFBOMRTNEWT01 $* -testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT00 $* +testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT10 $* +#testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT00 $* #testnoawt com.jogamp.opengl.test.junit.graph.TestRegionRendererNEWT01 $* #testnoawt com.jogamp.opengl.test.junit.graph.TestTextRendererNEWT01 $* #testnoawt com.jogamp.opengl.test.junit.graph.demos.ui.UINewtDemo01 $* diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java new file mode 100644 index 000000000..ff7eb4ed1 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java @@ -0,0 +1,168 @@ +/** + * 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.IOException; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLDrawable; +import javax.media.opengl.GLProfile; + +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.opengl.test.junit.util.NEWTGLContext; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.glsl.ShaderState; + + +public class TestTextRendererNEWT10 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 = TestTextRendererNEWT10.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) {} + } + + @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); + + final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(caps, 800, 400, true); + final GLDrawable drawable = winctx.context.getGLDrawable(); + final GL2ES2 gl = winctx.context.getGL().getGL2ES2(); + System.err.println(winctx.context); + + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + System.err.println("Chosen: "+winctx.window.getChosenCapabilities()); + + final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); + final TextRenderer renderer = TextRenderer.create(rs, 0); + + // init + 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); + + // reshape + gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight()); + + // renderer.reshapePerspective(gl, 45.0f, drawable.getWidth(), drawable.getHeight(), 0.1f, 1000.0f); + renderer.reshapeOrtho(gl, drawable.getWidth(), drawable.getHeight(), 0.1f, 1000.0f); + + // display + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + renderString(drawable, gl, renderer, "012345678901234567890123456789", 0, 0, -1000); + renderString(drawable, gl, renderer, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000); + renderString(drawable, gl, renderer, "Hello World", 0, -1, -1000); + renderString(drawable, gl, renderer, "4567890123456", 4, -1, -1000); + renderString(drawable, gl, renderer, "I like JogAmp", 4, -1, -1000); + + int c = 0; + renderString(drawable, gl, renderer, "GlueGen", c++, -1, -1000); + renderString(drawable, gl, renderer, "JOAL", c++, -1, -1000); + renderString(drawable, gl, renderer, "JOGL", c++, -1, -1000); + renderString(drawable, gl, renderer, "JOCL", c++, -1, -1000); + + drawable.swapBuffers(); + sleep(); + + // dispose + renderer.destroy(gl); + + NEWTGLContext.destroyWindow(winctx); + } + int screenshot_num = 0; + + int lastRow = -1; + + void renderString(GLDrawable drawable, GL2ES2 gl, TextRenderer renderer, String text, int column, int row, int z0) { + 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; + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java index 4cbccbda8..87d317037 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java @@ -53,7 +53,6 @@ import javax.media.opengl.GLUniformData; import org.junit.Assert; import org.junit.Test; -import org.junit.BeforeClass; public class TestRulerNEWT01 extends UITestCase { static long durationPerTest = 10; // ms |