From da3943d26342b8d71aa3fdf0d7f46f96e5b098dd Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 1 Aug 2023 14:08:31 +0200 Subject: Add Graph/GraphUI UISceneDemoU01a, showcase integration and multiple projection settings --- .../opengl/demos/graph/ui/UISceneDemoU01a.java | 351 +++++++++++++++++++++ 1 file changed, 351 insertions(+) create mode 100644 src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemoU01a.java (limited to 'src') diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemoU01a.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemoU01a.java new file mode 100644 index 000000000..a2002ad4a --- /dev/null +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemoU01a.java @@ -0,0 +1,351 @@ +/** + * Copyright 2023 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.demos.graph.ui; + +import java.io.IOException; + +import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.GLRegion; +import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.curve.opengl.TextRegionUtil; +import com.jogamp.graph.font.Font; +import com.jogamp.graph.font.FontFactory; +import com.jogamp.graph.font.FontSet; +import com.jogamp.graph.geom.plane.AffineTransform; +import com.jogamp.graph.ui.Shape; +import com.jogamp.graph.ui.shapes.CrossHair; +import com.jogamp.newt.event.WindowAdapter; +import com.jogamp.newt.event.WindowEvent; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GL2ES2; +import com.jogamp.opengl.GLAutoDrawable; +import com.jogamp.opengl.GLCapabilities; +import com.jogamp.opengl.GLEventListener; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.demos.graph.ui.util.GraphUIDemoArgs; +import com.jogamp.opengl.demos.util.MiscUtils; +import com.jogamp.opengl.fixedfunc.GLMatrixFunc; +import com.jogamp.opengl.math.FloatUtil; +import com.jogamp.opengl.math.Matrix4f; +import com.jogamp.opengl.math.Recti; +import com.jogamp.opengl.math.Vec2f; +import com.jogamp.opengl.math.Vec2i; +import com.jogamp.opengl.math.Vec3f; +import com.jogamp.opengl.math.Vec4f; +import com.jogamp.opengl.math.geom.AABBox; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.PMVMatrix; + +/** + * Res independent Graph + GraphUI integration demo + * using a GraphUI Shape and Graph text rendering + * within a regular GLEventListener, attached to a GLWindow. + *

+ * This demo showcases how to integrate Graph and GraphUI with different projection variations. + *

+ *

+ * Pass '-projPersp' to main-function to use perspective projection, otherwise orthogonal projection is used. + *

+ *

+ * Pass '-projWin' to main-function to use orthogonal projection with window coordinates, otherwise [-0.5, 0.5] is being used + *

+ *

+ * Default projection is orthogonal with width = 1, world-model range [-0.5, 0.5]. + *

+ *

+ * The world-model height is always scaled to window aspect ratio. + *

+ *

+ * 0/0 origin in its bottom-left corner, same as GraphUI + *

+ *

+ * Pass '-x ' and '-y ' widget position in window coordinates (bottom left origin). Default is center, i.e. half window width and height.
+ * Note: Reshape won't adjust and this is merely to demonstrate the coordinate space. + *

+ */ +public class UISceneDemoU01a { + static final GraphUIDemoArgs options = new GraphUIDemoArgs(1432, 770, Region.VBAA_RENDERING_BIT | Region.COLORCHANNEL_RENDERING_BIT); + static final Vec4f fg_color = new Vec4f( 0, 0, 0, 1 ); + static Font font; + static boolean projOrtho = true; + static boolean projOrthoWin = false; + static final Vec2i winOrigin = new Vec2i(options.surface_width/2, options.surface_height/2); + static final float normWidgetSize = 1/4f; + + public static void main(final String[] args) throws IOException { + if( 0 != args.length ) { + final int[] idx = { 0 }; + for(idx[0]=0; idx[0] "+full_width_s); + System.err.println("XXX: full_height: "+worldDim.y()+" / "+txt_box_em.getHeight()+" -> "+full_height_s); + System.err.println("XXX: txt_scale: "+txt_scale); + System.err.println("XXX: txt_box_em "+txt_box_em); + System.err.println("XXX: txt_box_r "+txt_box_r); + final AABBox textPort = txt_box_r.mapToWindow(new AABBox(), pmv.getPMvMat(), renderer.getViewport(), true /* useCenterZ */); + System.err.println("Display.1: Shape TextPort "+textPort); + } + } + private boolean onceAtDisplay = true; + + @Override + public void dispose(final GLAutoDrawable drawable) { + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + shape.destroy(gl, renderer); + renderer.destroy(gl); + System.err.println("Destroyed"); + } + } +} -- cgit v1.2.3