diff options
author | Sven Gothel <[email protected]> | 2011-05-08 05:38:38 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-05-08 05:38:38 +0200 |
commit | 77910075c04d4c86aabf12a2853b381f804bf04a (patch) | |
tree | 2b8ac6015d6e31fc455629d0543be46da773cb44 /src | |
parent | fbb4e5822c2da4458bfaeb728ba0eb2e45184e77 (diff) |
Graph/UI-Demo: Use RegionRenderer for region and text, start data/gl separation
Diffstat (limited to 'src')
5 files changed, 80 insertions, 164 deletions
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 index 2f734ea2c..e9296752e 100644 --- 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 @@ -27,17 +27,16 @@ */ 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; +public class RIButton extends UIShape { + private float width, height; + private Label label; private float spacing = 2.0f; private float[] scale = new float[]{1.0f,1.0f}; private float corner = 1.0f; @@ -46,62 +45,57 @@ public class RIButton extends UIControl{ private float[] buttonColor = {0.6f, 0.6f, 0.6f}; private float[] labelColor = {1.0f, 1.0f, 1.0f}; - public RIButton(Factory<? extends Vertex> factory, String label){ + public RIButton(Factory<? extends Vertex> factory, Font labelFont, String labelText, float width, float height) { + // w 4.0f, h 3.0f + // FontFactory.get(FontFactory.UBUNTU).getDefault() super(factory); - this.label = label; - setFont(FontFactory.get(FontFactory.UBUNTU).getDefault()); + + // FIXME: Determine font size - PMV Matrix relation ? + // this.label = new Label(factory, labelFont, (int)(height - 2f * spacing), labelText); + this.label = new Label(factory, labelFont, 10, labelText); + this.width = width; + this.height = height; } - public RIButton(Factory<? extends Vertex> factory, String label, Font font){ - super(factory); - setLabel(label); - setFont(font); - } - - public float getWidth() { - return width; - } + public final float getWidth() { return width; } + public final float getHeight() { return height; } + public float getCorner() { return corner; } + public float[] getScale() { return scale; } + public Label getLabel() { return label; } - public void setDimensions(float width, float height) { + public void setDimension(int width, int height) { this.width = width; this.height = height; - setDirty(true); + dirty |= DIRTY_SHAPE; } - public float getHeight() { - return height; - } - - public Font getFont() { - return font; + @Override + protected void clearImpl() { + label.clear(); } - public void generate(AABBox lbox) { - createOutline(factory, lbox); - scale[0] = getWidth()/(2*spacing + lbox.getWidth()); - scale[1] = getHeight()/(2*spacing + lbox.getHeight()); + @Override + protected void createShape() { + // FIXME: Only possible if all data (color) is + // is incl. in Outline Shape. + // Until then - draw each separately! + //shape.addOutlinShape( label.getShape() ); + label.updateShape(); - //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){ + final AABBox lbox = label.getBounds(); + if(corner == 0.0f) { createSharpOutline(lbox); - } - else{ + } else { createCurvedOutline(lbox); } + scale[0] = getWidth() / ( 2f*spacing + lbox.getWidth() ); + scale[1] = getHeight() / ( 2f*spacing + lbox.getHeight() ); } - private void createSharpOutline(AABBox lbox){ - float th = (2.0f*spacing) + lbox.getHeight(); - float tw = (2.0f*spacing) + lbox.getWidth(); + + + private void createSharpOutline(AABBox lbox) { + float th = (2f*spacing) + lbox.getHeight(); + float tw = (2f*spacing) + lbox.getWidth(); float minX = lbox.getMinX()-spacing; float minY = lbox.getMinY()-spacing; @@ -137,9 +131,6 @@ public class RIButton extends UIControl{ shape.closeLastOutline(); } - public float getCorner() { - return corner; - } public void setCorner(float corner) { if(corner > 1.0f){ @@ -151,7 +142,7 @@ public class RIButton extends UIControl{ else{ this.corner = corner; } - setDirty(true); + dirty |= DIRTY_SHAPE; } public float getLabelZOffset() { @@ -160,7 +151,7 @@ public class RIButton extends UIControl{ public void setLabelZOffset(float labelZOffset) { this.labelZOffset = -labelZOffset; - setDirty(true); + dirty |= DIRTY_SHAPE; } public float getSpacing() { return spacing; @@ -173,7 +164,7 @@ public class RIButton extends UIControl{ else{ this.spacing = spacing; } - setDirty(true); + dirty |= DIRTY_SHAPE; } public float[] getButtonColor() { @@ -196,8 +187,9 @@ public class RIButton extends UIControl{ this.labelColor[2] = b; } - public String toString(){ - return "RIButton [ label: " + getLabel() + "," + "spacing: " + spacing + public String toString() { + return "RIButton [" + getWidth() + "x" + getHeight() + ", " + + 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 deleted file mode 100644 index a4f1152a3..000000000 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIControl.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * 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 index ce4c07873..2ae7d1f30 100644 --- 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 @@ -34,20 +34,24 @@ import javax.media.opengl.GLAutoDrawable; import jogamp.graph.curve.text.GlyphString; -import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.OutlineShape; +import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RegionRenderer; 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.opengl.SVertex; import com.jogamp.opengl.test.junit.graph.demos.MSAATool; +import com.jogamp.opengl.test.junit.graph.demos.ui.opengl.UIRegion; public class UIGLListener01 extends UIListenerBase01 { public UIGLListener01 (RenderState rs, boolean debug, boolean trace) { - super(RegionRenderer.create(rs, Region.SINGLE_PASS), - TextRenderer.create(rs, Region.SINGLE_PASS), debug, trace); + super(RegionRenderer.create(rs, 0), debug, trace); setMatrix(-20, 00, 0f, -50); - button = new RIButton(SVertex.factory(), "Click me!"); + final Font font = FontFactory.get(FontFactory.UBUNTU).getDefault(); + button = new RIButton(SVertex.factory(), font, "Click me!", 4f, 3f); /** Button defaults ! button.setLabelColor(1.0f,1.0f,1.0f); button.setButtonColor(0.6f,0.6f,0.6f); @@ -57,28 +61,21 @@ public class UIGLListener01 extends UIListenerBase01 { 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); - - glyphString = textRenderer.createString(gl, button.getFont(), 10, button.getLabel()); - glyphString.generateRegion(gl, regionRenderer.getRenderState(), regionRenderer.getRenderType()); - - button.generate(glyphString.getBounds()); MSAATool.dump(drawable); } + UIRegion regionButton; + UIRegion regionLabel; + public void display(GLAutoDrawable drawable) { GL2ES2 gl = drawable.getGL().getGL2ES2(); @@ -86,22 +83,37 @@ public class UIGLListener01 extends UIListenerBase01 { gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); final RegionRenderer regionRenderer = getRegionRenderer(); + final RenderState rs = regionRenderer.getRenderState(); regionRenderer.resetModelview(null); regionRenderer.translate(null, getXTran(), getYTran(), getZoom()); regionRenderer.rotate(gl, getAngle(), 0, 1, 0); - float[] bColor = button.getButtonColor(); + + final float[] bColor = button.getButtonColor(); + final float[] lColor = button.getLabelColor(); + if(null == regionButton) { + regionButton = new UIRegion(button); + regionLabel = new UIRegion(button.getLabel()); + } + regionRenderer.setColorStatic(gl, bColor[0], bColor[1], bColor[2]); - regionRenderer.renderOutlineShape(gl, button.getShape(glyphString.getBounds()), getPosition(), 0); - float[] lColor = button.getLabelColor(); + regionRenderer.draw(gl, regionButton.getRegion(gl, rs, 0), getPosition(), 0); + regionRenderer.setColorStatic(gl, lColor[0], lColor[1], lColor[2]); - glyphString.renderString3D(gl); + regionRenderer.draw(gl, regionLabel.getRegion(gl, rs, 0), getPosition(), 0); } public void dispose(GLAutoDrawable drawable) { GL2ES2 gl = drawable.getGL().getGL2ES2(); - glyphString.destroy(gl, getRegionRenderer().getRenderState()); + if(null != regionButton) { + regionButton.destroy(gl, getRegionRenderer().getRenderState()); + regionButton = null; + } + if(null != regionLabel) { + regionLabel.destroy(gl, getRegionRenderer().getRenderState()); + regionButton = null; + } super.dispose(drawable); } } 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 index 98a7d4531..df2dca4fb 100644 --- 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 @@ -62,7 +62,6 @@ import com.jogamp.opengl.test.junit.graph.demos.Screenshot; public abstract class UIListenerBase01 implements GLEventListener { private Screenshot screenshot; private RegionRenderer rRenderer; - private TextRenderer tRenderer; private boolean debug; private boolean trace; @@ -82,16 +81,14 @@ public abstract class UIListenerBase01 implements GLEventListener { boolean ignoreInput = false; - public UIListenerBase01(RegionRenderer rRenderer, TextRenderer tRenderer, boolean debug, boolean trace) { + public UIListenerBase01(RegionRenderer rRenderer, 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; } @@ -115,6 +112,7 @@ public abstract class UIListenerBase01 implements GLEventListener { 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); + getRegionRenderer().init(gl); } public void reshape(GLAutoDrawable drawable, int xstart, int ystart, int width, int height) { @@ -122,7 +120,6 @@ public abstract class UIListenerBase01 implements GLEventListener { 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(); } @@ -131,7 +128,6 @@ public abstract class UIListenerBase01 implements GLEventListener { GL2ES2 gl = drawable.getGL().getGL2ES2(); screenshot.dispose(gl); rRenderer.destroy(gl); - tRenderer.destroy(gl); } public void zoom(int v){ @@ -218,19 +214,16 @@ public abstract class UIListenerBase01 implements GLEventListener { 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 @@ -307,7 +300,7 @@ public abstract class UIListenerBase01 implements GLEventListener { autoDrawable.invoke(false, new GLRunnable() { public void run(GLAutoDrawable drawable) { try { - final String type = ( 1 == rRenderer.getRenderType() ) ? "r2t0-msaa1" : "r2t1-msaa0" ; + final String type = ( 1 == rRenderer.getRenderModes() ) ? "r2t0-msaa1" : "r2t1-msaa0" ; printScreen(drawable, "./", "demo-"+type, "snap"+screenshot_num, false); screenshot_num++; } catch (GLException e) { 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 index 1f4856426..27b7ecc13 100755 --- 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 @@ -33,7 +33,6 @@ import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.curve.opengl.Renderer; import com.jogamp.graph.geom.opengl.SVertex; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; @@ -67,7 +66,7 @@ public class UINewtDemo01 { window.setPosition(10, 10); window.setSize(800, 400); window.setTitle("GPU UI Newt Demo 01"); - RenderState rs = Renderer.createRenderState(new ShaderState(), SVertex.factory()); + RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); UIGLListener01 uiGLListener = new UIGLListener01 (rs, DEBUG, TRACE); uiGLListener.attachInputListenerTo(window); window.addGLEventListener(uiGLListener); |