diff options
author | Sven Gothel <[email protected]> | 2011-04-08 18:08:56 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-04-08 18:08:56 +0200 |
commit | 547724c6790db5888bf803ec7e79b5eaa8cc1d87 (patch) | |
tree | 6d41675a8aafe6f7d2dec28ade0813f749388cc2 /src | |
parent | ba47ef11171a8da45c718c89d1e962287b504e36 (diff) | |
parent | f628fc29468b7a6b821b5a47dd93224730222dc4 (diff) |
Merge remote-tracking branch 'rsantina/graph' into graph
Diffstat (limited to 'src')
12 files changed, 830 insertions, 12 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java index e238889e0..cc21af859 100755 --- a/src/jogl/classes/com/jogamp/graph/curve/Region.java +++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java @@ -29,9 +29,9 @@ package com.jogamp.graph.curve; import java.util.ArrayList;
+import com.jogamp.graph.geom.AABBox;
import jogamp.opengl.Debug;
-import com.jogamp.graph.curve.opengl.Renderer;
import com.jogamp.graph.geom.Triangle;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.util.PMVMatrix;
@@ -129,6 +129,8 @@ public interface Region { */
public void destroy();
+ public AABBox getBounds();
+
public boolean isFlipped();
/** Set if the y coordinate of the region should be flipped
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java index aa14bcbd8..ce3e83692 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java @@ -125,6 +125,13 @@ public abstract class Renderer { st.glUniform(gl, mgl_PMVMatrix); } } + + public void scale(GL2ES2 gl, float x, float y, float z) { + pmvMatrix.glScalef(x, y, z); + if(initialized && null != gl && st.inUse()) { + st.glUniform(gl, mgl_PMVMatrix); + } + } public void resetModelview(GL2ES2 gl) { pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java index 4b7299a33..ee8dfb372 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java @@ -48,11 +48,10 @@ public abstract class TextRenderer extends Renderer { * @param sharpness parameter for Region generation of the resulting GlyphString * @return the resulting GlyphString inclusive the generated region */ - protected GlyphString createString(GL2ES2 gl, Font font, int size, String str, float sharpness) { + public GlyphString createString(GL2ES2 gl, Font font, int size, String str, float sharpness) { if(DEBUG) { System.err.println("createString: "+getCacheSize()+"/"+getCacheLimit()+" - "+Font.NAME_UNIQUNAME + " - " + str + " - " + size); } - AffineTransform affineTransform = new AffineTransform(pointFactory); Path2D[] paths = new Path2D[str.length()]; diff --git a/src/jogl/classes/com/jogamp/graph/geom/AABBox.java b/src/jogl/classes/com/jogamp/graph/geom/AABBox.java index 8cd06329e..17a805b31 100644 --- a/src/jogl/classes/com/jogamp/graph/geom/AABBox.java +++ b/src/jogl/classes/com/jogamp/graph/geom/AABBox.java @@ -57,8 +57,8 @@ public class AABBox { public AABBox(float lx, float ly, float lz, float hx, float hy, float hz) { - setLow(lx, ly, lz); - setHigh(hx, hy, hz); + resize(lx, ly, lz); + resize(hx, hy, hz); computeCenter(); } @@ -69,8 +69,8 @@ public class AABBox { */ public AABBox(float[] low, float[] high) { - this.low = low; - this.high = high; + resize(low[0],low[1],low[2]); + resize(high[0],high[1],high[2]); computeCenter(); } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java index 17962a297..81d9d1858 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java @@ -354,4 +354,8 @@ public class VBORegion2PES2 implements Region { public void setFlipped(boolean flipped) { this.flipped = flipped; } + + public AABBox getBounds(){ + return box; + } } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java index 80bf00428..0d68be8ce 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java @@ -34,6 +34,7 @@ import javax.media.opengl.GL2ES2; import javax.media.opengl.GLContext; import com.jogamp.graph.curve.Region; +import com.jogamp.graph.geom.AABBox; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Triangle; import com.jogamp.opengl.util.GLArrayDataServer; @@ -53,11 +54,14 @@ public class VBORegionSPES2 implements Region { private boolean flipped = false; private boolean dirty = false; + private AABBox box = null; + public VBORegionSPES2(GLContext context){ this.context =context; } public void update(){ + box = new AABBox(); GL2ES2 gl = context.getGL().getGL2ES2(); destroy(gl); @@ -96,13 +100,21 @@ public class VBORegionSPES2 implements Region { vertices.size(), GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); verticeAttr.setLocation(Region.VERTEX_ATTR_IDX); for(Vertex v:vertices){ - verticeAttr.putf(v.getX()); + if(flipped){ - verticeAttr.putf(-1*v.getY()); - } else { - verticeAttr.putf(v.getY()); + verticeAttr.putf(v.getX()); + verticeAttr.putf(-1*v.getY()); + verticeAttr.putf(v.getZ()); + + box.resize(v.getX(),-1*v.getY(),v.getZ()); + } + else{ + verticeAttr.putf(v.getX()); + verticeAttr.putf(v.getY()); + verticeAttr.putf(v.getZ()); + + box.resize(v.getX(),v.getY(),v.getZ()); } - verticeAttr.putf(v.getZ()); } verticeAttr.seal(gl, true); @@ -187,4 +199,7 @@ public class VBORegionSPES2 implements Region { public void setFlipped(boolean flipped) { this.flipped = flipped; } + public AABBox getBounds(){ + return box; + } } diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java index 808e3a415..7c7bb816f 100644 --- a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java +++ b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java @@ -29,6 +29,7 @@ package jogamp.graph.curve.text; import java.util.ArrayList; +import com.jogamp.graph.geom.AABBox; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Triangle; import com.jogamp.graph.geom.opengl.SVertex; @@ -160,4 +161,8 @@ public class GlyphString { public void destroy(){ region.destroy(); } + + public AABBox getBounds(){ + return region.getBounds(); + } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java new file mode 100644 index 000000000..4f59b61ec --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/RIButton.java @@ -0,0 +1,204 @@ +/** + * 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.demos.ui; + +import com.jogamp.graph.curve.OutlineShape; +import com.jogamp.graph.font.Font; +import com.jogamp.graph.font.FontFactory; +import com.jogamp.graph.geom.AABBox; +import com.jogamp.graph.geom.Vertex; +import com.jogamp.graph.geom.Vertex.Factory; + +/** GPU based resolution independent Button impl + */ +public class RIButton extends UIControl{ + private float width = 4.0f, height= 3.0f; + private float spacing = 0.3f; + private float[] scale = new float[]{1.0f,1.0f}; + private float corner = 0.5f; + private float labelZOffset = -0.05f; + + private float[] buttonColor = {0.0f, 0.0f, 0.0f}; + private float[] labelColor = {1.0f, 1.0f, 1.0f}; + + public RIButton(Factory<? extends Vertex> factory, String label){ + super(factory); + this.label = label; + setFont(FontFactory.get(FontFactory.UBUNTU).getDefault()); + } + + public RIButton(Factory<? extends Vertex> factory, String label, Font font){ + super(factory); + setLabel(label); + setFont(font); + } + + public float getWidth() { + return width; + } + + public void setDimensions(float width, float height) { + this.width = width; + this.height = height; + setDirty(true); + } + + public float getHeight() { + return height; + } + + public Font getFont() { + return font; + } + + public void generate(AABBox lbox) { +// AABBox lbox = font.getStringBounds(label, 10); + createOutline(factory, lbox); + scale[0] = getWidth()/(2*spacing + lbox.getWidth()); + scale[1] = getHeight()/(2*spacing + lbox.getHeight()); + + //FIXME: generate GlyphString to manipulate before rendering + setDirty(false); + } + + + public float[] getScale() { + return scale; + } + + private void createOutline(Factory<? extends Vertex> factory, AABBox lbox){ + shape = new OutlineShape(factory); + if(corner == 0.0f){ + createSharpOutline(lbox); + } + else{ + createCurvedOutline(lbox); + } + } + private void createSharpOutline(AABBox lbox){ + float th = (2.0f*spacing) + lbox.getHeight(); + float tw = (2.0f*spacing) + lbox.getWidth(); + float minX = lbox.getMinX()-spacing; + float minY = lbox.getMinY()-spacing; + + shape.addVertex(minX, minY, labelZOffset, true); + shape.addVertex(minX+tw, minY, labelZOffset, true); + shape.addVertex(minX+tw, minY + th, labelZOffset, true); + shape.addVertex(minX, minY + th, labelZOffset, true); + shape.closeLastOutline(); + } + + private void createCurvedOutline(AABBox lbox){ + float th = 2.0f*spacing + lbox.getHeight(); + float tw = 2.0f*spacing + lbox.getWidth(); + + float cw = 0.5f*corner*Math.min(tw, th); + float ch = 0.5f*corner*Math.min(tw, th); + + float minX = lbox.getMinX()-spacing; + float minY = lbox.getMinY()-spacing; + + shape.addVertex(minX, minY + ch, labelZOffset, true); + shape.addVertex(minX, minY, labelZOffset, false); + shape.addVertex(minX + cw, minY, labelZOffset, true); + shape.addVertex(minX + tw - cw, minY, labelZOffset, true); + shape.addVertex(minX + tw, minY, labelZOffset, false); + shape.addVertex(minX + tw, minY + ch, labelZOffset, true); + shape.addVertex(minX + tw, minY + th- ch, labelZOffset, true); + shape.addVertex(minX + tw, minY + th, labelZOffset, false); + shape.addVertex(minX + tw - cw, minY + th, labelZOffset, true); + shape.addVertex(minX + cw, minY + th, labelZOffset, true); + shape.addVertex(minX, minY + th, labelZOffset, false); + shape.addVertex(minX, minY + th - ch, labelZOffset, true); + shape.closeLastOutline(); + } + + public float getCorner() { + return corner; + } + + public void setCorner(float corner) { + if(corner > 1.0f){ + this.corner = 1.0f; + } + else if(corner < 0.01f){ + this.corner = 0.0f; + } + else{ + this.corner = corner; + } + setDirty(true); + } + + public float getLabelZOffset() { + return labelZOffset; + } + + public void setLabelZOffset(float labelZOffset) { + this.labelZOffset = -labelZOffset; + setDirty(true); + } + public float getSpacing() { + return spacing; + } + + public void setSpacing(float spacing) { + if(spacing < 0.0f){ + this.spacing = 0.0f; + } + else{ + this.spacing = spacing; + } + setDirty(true); + } + + public float[] getButtonColor() { + return buttonColor; + } + + public void setButtonColor(float r, float g, float b) { + this.buttonColor[0] = r; + this.buttonColor[1] = g; + this.buttonColor[2] = b; + } + + public float[] getLabelColor() { + return labelColor; + } + + public void setLabelColor(float r, float g, float b) { + this.labelColor[0] = r; + this.labelColor[1] = g; + this.labelColor[2] = b; + } + + public String toString(){ + return "RIButton [ label: " + getLabel() + "," + "spacing: " + spacing + + ", " + "corner: " + corner + ", " + "shapeOffset: " + labelZOffset + " ]"; + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIControl.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIControl.java new file mode 100644 index 000000000..ae872fe54 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIControl.java @@ -0,0 +1,80 @@ +/** + * 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.demos.ui; + +import com.jogamp.graph.curve.OutlineShape; +import com.jogamp.graph.font.Font; +import com.jogamp.graph.geom.AABBox; +import com.jogamp.graph.geom.Vertex; +import com.jogamp.graph.geom.Vertex.Factory; + +public abstract class UIControl { + protected Font font = null; + protected OutlineShape shape = null; + protected String label = "Label"; + protected Factory<? extends Vertex> factory; + + protected boolean dirty = true; + + public UIControl(Factory<? extends Vertex> factory){ + this.factory = factory; + } + + public abstract void generate(AABBox lbox); + + public Font getFont() { + return font; + } + + public void setFont(Font font) { + this.font = font; + } + + public OutlineShape getShape(AABBox lbox) { + if(isDirty()){ + generate(lbox); + } + return shape; + } + + public String getLabel(){ + return label; + } + public void setLabel(String label) { + this.label = label; + setDirty(true); + } + + protected boolean isDirty() { + return dirty; + } + + protected void setDirty(boolean dirty) { + this.dirty = dirty; + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java new file mode 100644 index 000000000..cb373d014 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java @@ -0,0 +1,103 @@ +/** + * 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.demos.ui; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAutoDrawable; + +import jogamp.graph.curve.text.GlyphString; + +import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.curve.opengl.TextRenderer; +import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.opengl.test.junit.graph.demos.MSAATool; + +public class UIGLListener01 extends UIListenerBase01 { + + public UIGLListener01 (boolean debug, boolean trace) { + super(RegionRenderer.create(SVertex.factory(), Region.SINGLE_PASS), + TextRenderer.create(SVertex.factory(), Region.SINGLE_PASS), debug, trace); + setMatrix(-20, 00, 0f, -50); + button = new RIButton(SVertex.factory(), "Click me!"); + button.setLabelColor(1.0f,1.0f,1.0f); + button.setButtonColor(0.6f,0.6f,0.6f); + button.setCorner(0.5f); + button.setSpacing(0.3f); + System.err.println(button); + } + + private GlyphString glyphString; + public void init(GLAutoDrawable drawable) { + super.init(drawable); + + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + final RegionRenderer regionRenderer = getRegionRenderer(); + final TextRenderer textRenderer = getTextRenderer(); + + gl.setSwapInterval(1); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + gl.glEnable(GL2ES2.GL_POLYGON_OFFSET_FILL); + + regionRenderer.init(gl); + regionRenderer.setAlpha(gl, 1.0f); + + glyphString = textRenderer.createString(gl, button.getFont(), 10, button.getLabel(), 0.5f); + glyphString.generateRegion(gl.getContext(), 0.5f, regionRenderer.getShaderState(), regionRenderer.getRenderType()); + + button.generate(glyphString.getBounds()); + MSAATool.dump(drawable); + } + + public void display(GLAutoDrawable drawable) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + + final RegionRenderer regionRenderer = getRegionRenderer(); + + regionRenderer.resetModelview(null); + + regionRenderer.translate(null, getXTran(), getYTran(), getZoom()); + regionRenderer.rotate(gl, getAngle(), 0, 1, 0); + float[] bColor = button.getButtonColor(); + regionRenderer.setColor(gl, bColor[0], bColor[1], bColor[2]); + regionRenderer.renderOutlineShape(gl, button.getShape(glyphString.getBounds()), getPosition(), 0); + float[] lColor = button.getLabelColor(); + regionRenderer.setColor(gl, lColor[0], lColor[1], lColor[2]); + glyphString.renderString3D(); + } + public void dispose(GLAutoDrawable drawable) { + super.dispose(drawable); + glyphString.destroy(); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java new file mode 100644 index 000000000..fb4d1015e --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java @@ -0,0 +1,326 @@ +/** + * 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.demos.ui; + +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.GLAnimatorControl; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLException; +import javax.media.opengl.GLPipelineFactory; +import javax.media.opengl.GLRunnable; + +import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.curve.opengl.TextRenderer; +import com.jogamp.newt.event.KeyEvent; +import com.jogamp.newt.event.KeyListener; +import com.jogamp.newt.event.MouseEvent; +import com.jogamp.newt.event.MouseListener; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.graph.demos.Screenshot; + +/** + * + * Action Keys: + * - 1/2: zoom in/out + * - 4/5: increase/decrease shape/text spacing + * - 6/7: increase/decrease corner size + * - 0/9: rotate + * - v: toggle v-sync + * - s: screenshot + */ +public abstract class UIListenerBase01 implements GLEventListener { + private Screenshot screenshot; + private RegionRenderer rRenderer; + private TextRenderer tRenderer; + private boolean debug; + private boolean trace; + + protected RIButton button; + + private KeyAction keyAction; + private MouseAction mouseAction; + + private volatile GLAutoDrawable autoDrawable = null; + + private final float[] position = new float[] {0,0,0}; + + private float xTran = -10; + private float yTran = 10; + private float ang = 0f; + private float zoom = -70f; + + boolean ignoreInput = false; + + public UIListenerBase01(RegionRenderer rRenderer, TextRenderer tRenderer, boolean debug, boolean trace) { + this.rRenderer = rRenderer; + this.tRenderer = tRenderer; + this.debug = debug; + this.trace = trace; + this.screenshot = new Screenshot(); + } + + public final RegionRenderer getRegionRenderer() { return rRenderer; } + public final TextRenderer getTextRenderer() { return tRenderer; } + public final float getZoom() { return zoom; } + public final float getXTran() { return xTran; } + public final float getYTran() { return yTran; } + public final float getAngle() { return ang; } + public final float[] getPosition() { return position; } + + public void setMatrix(float xtrans, float ytrans, float angle, int zoom) { + this.xTran = xtrans; + this.yTran = ytrans; + this.ang = angle; + this.zoom = zoom; + } + + public void init(GLAutoDrawable drawable) { + autoDrawable = drawable; + GL2ES2 gl = drawable.getGL().getGL2ES2(); + if(debug) { + gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", null, gl, null) ).getGL2ES2(); + } + if(trace) { + gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, gl, new Object[] { System.err } ) ).getGL2ES2(); + } + gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + } + + public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + gl.glViewport(xstart, ystart, width, height); + rRenderer.reshapePerspective(gl, 45.0f, width, height, 0.1f, 7000.0f); + tRenderer.reshapePerspective(gl, 45.0f, width, height, 0.1f, 7000.0f); + dumpMatrix(); + } + + public void dispose(GLAutoDrawable drawable) { + autoDrawable = null; + GL2ES2 gl = drawable.getGL().getGL2ES2(); + screenshot.dispose(); + rRenderer.dispose(gl); + tRenderer.dispose(gl); + } + + public void zoom(int v){ + zoom += v; + dumpMatrix(); + } + + public void move(float x, float y){ + xTran += x; + yTran += y; + dumpMatrix(); + } + public void rotate(float delta){ + ang += delta; + ang %= 360.0f; + dumpMatrix(); + } + + void dumpMatrix() { + System.err.println("Matrix: " + xTran + "/" + yTran + " x"+zoom + " @"+ang); + } + + /** Attach the input listener to the window */ + public void attachInputListenerTo(GLWindow window) { + if ( null == keyAction ) { + keyAction = new KeyAction(); + window.addKeyListener(keyAction); + } + if ( null == mouseAction ) { + mouseAction = new MouseAction(); + window.addMouseListener(mouseAction); + } + } + + public void detachFrom(GLWindow window) { + if ( null == keyAction ) { + return; + } + if ( null == mouseAction ) { + return; + } + window.removeGLEventListener(this); + window.removeKeyListener(keyAction); + window.removeMouseListener(mouseAction); + } + + public void printScreen(GLAutoDrawable drawable, String dir, String tech, String objName, boolean exportAlpha) throws GLException, IOException { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + pw.printf("-%03dx%03d-Z%04d-T%04d-%s", drawable.getWidth(), drawable.getHeight(), (int)Math.abs(zoom), 0, objName); + + String filename = dir + tech + sw +".tga"; + screenshot.surface2File(drawable, filename /*, exportAlpha */); + } + + int screenshot_num = 0; + + public void setIgnoreInput(boolean v) { + ignoreInput = v; + } + public boolean getIgnoreInput() { + return ignoreInput; + } + + public class MouseAction implements MouseListener{ + + public void mouseClicked(MouseEvent e) { + + } + + public void mouseEntered(MouseEvent e) { + } + + public void mouseExited(MouseEvent e) { + } + + public void mousePressed(MouseEvent e) { + button.setLabelColor(0.8f,0.8f,0.8f); + button.setButtonColor(0.1f, 0.1f, 0.1f); + } + + public void mouseReleased(MouseEvent e) { + button.setLabelColor(1.0f,1.0f,1.0f); + button.setButtonColor(0.6f,0.6f,0.6f); + } + + @Override + public void mouseMoved(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseDragged(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseWheelMoved(MouseEvent e) { + // TODO Auto-generated method stub + + } + + } + + public class KeyAction implements KeyListener { + public void keyPressed(KeyEvent arg0) { + if(ignoreInput) { + return; + } + + if(arg0.getKeyCode() == KeyEvent.VK_1){ + zoom(10); + } + else if(arg0.getKeyCode() == KeyEvent.VK_2){ + zoom(-10); + } + else if(arg0.getKeyCode() == KeyEvent.VK_UP){ + move(0, -1); + } + else if(arg0.getKeyCode() == KeyEvent.VK_DOWN){ + move(0, 1); + } + else if(arg0.getKeyCode() == KeyEvent.VK_LEFT){ + move(1, 0); + } + else if(arg0.getKeyCode() == KeyEvent.VK_RIGHT){ + move(-1, 0); + } + else if(arg0.getKeyCode() == KeyEvent.VK_4){ + button.setSpacing(button.getSpacing()-0.1f); + System.err.println("Button Spacing: " + button.getSpacing()); + } + else if(arg0.getKeyCode() == KeyEvent.VK_5){ + button.setSpacing(button.getSpacing()+0.1f); + System.err.println("Button Spacing: " + button.getSpacing()); + } + else if(arg0.getKeyCode() == KeyEvent.VK_6){ + button.setCorner(button.getCorner()-0.1f); + System.err.println("Button Corner: " + button.getCorner()); + } + else if(arg0.getKeyCode() == KeyEvent.VK_7){ + button.setCorner(button.getCorner()+0.1f); + System.err.println("Button Corner: " + button.getCorner()); + } + else if(arg0.getKeyCode() == KeyEvent.VK_0){ + rotate(1); + } + else if(arg0.getKeyCode() == KeyEvent.VK_9){ + rotate(-1); + } + else if(arg0.getKeyCode() == KeyEvent.VK_V) { + if(null != autoDrawable) { + autoDrawable.invoke(false, new GLRunnable() { + public void run(GLAutoDrawable drawable) { + GL gl = drawable.getGL(); + int i = gl.getSwapInterval(); + i = i==0 ? 1 : 0; + gl.setSwapInterval(i); + final GLAnimatorControl a = drawable.getAnimator(); + if( null != a ) { + a.resetCounter(); + } + System.err.println("Swap Interval: "+i); + } + }); + } + } + else if(arg0.getKeyCode() == KeyEvent.VK_S){ + rotate(-1); + if(null != autoDrawable) { + autoDrawable.invoke(false, new GLRunnable() { + public void run(GLAutoDrawable drawable) { + try { + final String type = ( 1 == rRenderer.getRenderType() ) ? "r2t0-msaa1" : "r2t1-msaa0" ; + printScreen(drawable, "./", "demo-"+type, "snap"+screenshot_num, false); + screenshot_num++; + } catch (GLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + }); + } + } + } + public void keyTyped(KeyEvent arg0) {} + public void keyReleased(KeyEvent arg0) {} + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java new file mode 100755 index 000000000..98e74e3a6 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java @@ -0,0 +1,73 @@ +/** + * 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.demos.ui; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.util.Animator; + +/** Demonstrate the rendering of multiple outlines into one region/OutlineShape + * These Outlines are not necessary connected or contained. + * The output of this demo shows two identical shapes but the left one + * has some vertices with off-curve flag set to true, and the right allt he vertices + * are on the curve. Demos the Res. Independent Nurbs based Curve rendering + * + */ +public class UINewtDemo01 { + static final boolean DEBUG = false; + static final boolean TRACE = false; + + public static void main(String[] args) { + GLProfile.initSingleton(true); + GLProfile glp = GLProfile.getGL2ES2(); + GLCapabilities caps = new GLCapabilities(glp); + caps.setAlphaBits(4); + caps.setSampleBuffers(true); + caps.setNumSamples(4); + System.out.println("Requested: " + caps); + + GLWindow window = GLWindow.create(caps); + window.setPosition(10, 10); + window.setSize(800, 400); + window.setTitle("GPU UI Newt Demo 01"); + + UIGLListener01 uiGLListener = new UIGLListener01 (DEBUG, TRACE); + uiGLListener.attachInputListenerTo(window); + window.addGLEventListener(uiGLListener); + + window.enablePerfLog(true); + window.setVisible(true); + + Animator animator = new Animator(); + animator.add(window); + animator.start(); + } +} |