From 7981d94481c82570d944162ca5950d314bfed0c1 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 15 Mar 2023 02:41:53 +0100 Subject: GraphUI: Rename UISceneDemo00 -> UISceneDemo01 --- .../opengl/demos/graph/ui/UISceneDemo00.java | 356 --------------------- .../opengl/demos/graph/ui/UISceneDemo01.java | 356 +++++++++++++++++++++ 2 files changed, 356 insertions(+), 356 deletions(-) delete mode 100644 src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo00.java create mode 100644 src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java (limited to 'src/demos/com/jogamp/opengl') diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo00.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo00.java deleted file mode 100644 index 7ba6c135b..000000000 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo00.java +++ /dev/null @@ -1,356 +0,0 @@ -/** - * Copyright 2010-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.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.Locale; - -import com.jogamp.common.net.Uri; -import com.jogamp.common.util.InterruptSource; -import com.jogamp.graph.curve.Region; -import com.jogamp.graph.curve.opengl.RegionRenderer; -import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.font.Font; -import com.jogamp.graph.font.FontFactory; -import com.jogamp.graph.font.FontSet; -import com.jogamp.graph.geom.SVertex; -import com.jogamp.graph.geom.plane.AffineTransform; -import com.jogamp.graph.ui.gl.Scene; -import com.jogamp.graph.ui.gl.Shape; -import com.jogamp.graph.ui.gl.Shape.EventInfo; -import com.jogamp.graph.ui.gl.shapes.Button; -import com.jogamp.graph.ui.gl.shapes.GLButton; -import com.jogamp.graph.ui.gl.shapes.MediaButton; -import com.jogamp.newt.Window; -import com.jogamp.newt.event.KeyAdapter; -import com.jogamp.newt.event.KeyEvent; -import com.jogamp.newt.event.MouseEvent; -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.GLPipelineFactory; -import com.jogamp.opengl.GLProfile; -import com.jogamp.opengl.GLRunnable; -import com.jogamp.opengl.demos.es2.GearsES2; -import com.jogamp.opengl.demos.graph.MSAATool; -import com.jogamp.opengl.fixedfunc.GLMatrixFunc; -import com.jogamp.opengl.util.Animator; -import com.jogamp.opengl.util.GLReadBufferUtil; -import com.jogamp.opengl.util.PMVMatrix; -import com.jogamp.opengl.util.av.GLMediaPlayer; -import com.jogamp.opengl.util.av.GLMediaPlayerFactory; - -/** - * Basic UIScene demo using a single UIShape. - * - * 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 class UISceneDemo00 implements GLEventListener { - static final boolean DEBUG = false; - static final boolean TRACE = false; - - static private final String defaultMediaPath = "http://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4"; - static private String filmPath = defaultMediaPath; - - public static void main(final String[] args) throws IOException { - Font font = null; - if( 0 != args.length ) { - for(int i=0; i "+sceneSize[0]+" x "+sceneSize[1]+" model"); - final float sw = 1/3f * sceneSize[0]; - final float sh = sw / 2f; - System.err.println("Shape "+sw+" x "+sh); - - if( true ) { - Uri filmUri; - try { - filmUri = Uri.cast( filmPath ); - } catch (final URISyntaxException e1) { - throw new RuntimeException(e1); - } - final GLMediaPlayer mPlayer = GLMediaPlayerFactory.createDefault(); - // mPlayer.setTextureUnit(texUnitMediaPlayer); - final MediaButton b = new MediaButton(SVertex.factory(), renderModes, sw, sh, mPlayer); - b.setVerbose(true); - b.addDefaultEventListener(); - b.setToggleable(true); - b.setToggle(true); - b.setToggleOffColorMod(0f, 1f, 0f, 1.0f); - b.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - mPlayer.setAudioVolume( b.isToggleOn() ? 1f : 0f ); - } } ); - mPlayer.playStream(filmUri, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.TEXTURE_COUNT_DEFAULT); - shape = b; - } else if( true ) { - final GLEventListener glel; - { - final GearsES2 gears = new GearsES2(0); - gears.setVerbose(false); - gears.setClearColor(new float[] { 0.9f, 0.9f, 0.9f, 1f } ); - glel = gears; - } - final int texUnit = 1; - final GLButton b = new GLButton(scene.getVertexFactory(), renderModes, - sw, sh, texUnit, glel, false /* useAlpha */); - b.setToggleable(true); - b.setToggle(true); // toggle == true -> animation - b.setAnimate(true); - b.addMouseListener(shapeGesture); - b.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - b.setAnimate( b.isToggleOn() ); - } } ); - shape = b; - } else { - final Button b = new Button(SVertex.factory(), renderModes, font, "Click me!", sw, sh); - b.setLabelColor(0.0f,0.0f,0.0f); - b.addMouseListener(shapeGesture); - shape = b; - } - shape.move((sceneSize[0] - sw)/2f, (sceneSize[1] - sh)/2f, 0f); // center - scene.addShape(shape); - } - - final Shape.MouseGestureAdapter shapeGesture = new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); - System.err.println("Shape.EventInfo: "+shapeEvent); - final Shape s = shapeEvent.shape; - - final RegionRenderer renderer = scene.getRenderer(); - final PMVMatrix pmv = new PMVMatrix(); - scene.setupMatrix(pmv, 0, 0); - - // flip to GL window coordinates, origin bottom-left - final int[] viewport = renderer.getViewport(new int[4]); - final int glWinX = e.getX(); - final int glWinY = viewport[3] - e.getY() - 1; - { - pmv.glPushMatrix(); - s.setTransform(pmv); - - final float[] objPos = new float[3]; - s.winToObjCoord(renderer, glWinX, glWinY, objPos); - System.err.println("Button: Click: Win "+glWinX+"/"+glWinY+" -> Obj "+objPos[0]+"/"+objPos[1]+"/"+objPos[1]); - - final int[] surfaceSize = new int[2]; - s.getSurfaceSize(renderer, surfaceSize); - System.err.println("Button: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]); - - pmv.glPopMatrix(); - } - } }; - - public final float[] getPosition() { return position; } - - @Override - public void init(final GLAutoDrawable drawable) { - GL2ES2 gl = drawable.getGL().getGL2ES2(); - if(debug) { - gl = gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Debug", null, gl, null) ).getGL2ES2(); - } - if(trace) { - gl = gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Trace", null, gl, new Object[] { System.err } ) ).getGL2ES2(); - } - - if(drawable instanceof GLWindow) { - final GLWindow glw = (GLWindow) drawable; - scene.attachInputListenerTo(glw); - } - gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - - gl.setSwapInterval(1); - gl.glEnable(GL.GL_DEPTH_TEST); - gl.glEnable(GL.GL_POLYGON_OFFSET_FILL); - MSAATool.dump(drawable); - - System.err.println("Init: Shape "+shape); - scene.init(drawable); - } - - @Override - public void reshape(final GLAutoDrawable drawable, final int xstart, final int ystart, final int width, final int height) { - // Layout all shapes: Just stay centered - // - // shape.move(0f, 0f, 0f); - System.err.println("Reshape: Shape "+shape); - - System.err.println("Reshape: Scene Plane.R "+scene.getBounds()); - - scene.reshape(drawable, xstart, ystart, width, height); - - System.err.println("Reshape: Scene Plane.R "+scene.getBounds()); - - if( drawable instanceof Window ) { - ((Window)drawable).setTitle(UISceneDemo00.class.getSimpleName()+": "+drawable.getSurfaceWidth()+" x "+drawable.getSurfaceHeight()); - } - } - - final int[] sampleCount = { 4 }; - - @Override - public void display(final GLAutoDrawable drawable) { - scene.display(drawable); - } - static boolean once = true; - - @Override - public void dispose(final GLAutoDrawable drawable) { - final GL2ES2 gl = drawable.getGL().getGL2ES2(); - scene.dispose(drawable); // disposes all registered UIShapes - - screenshot.dispose(gl); - } - - public void printScreen(final GL gl) { - final RegionRenderer renderer = scene.getRenderer(); - final String modeS = Region.getRenderModeString(renderModes); - final String filename = String.format((Locale)null, "UISceneDemo00-shot%03d-%03dx%03d-S_%s_%02d.png", - shotCount++, renderer.getWidth(), renderer.getHeight(), - modeS, scene.getSampleCount()); - gl.glFinish(); // just make sure rendering finished .. - if(screenshot.readPixels(gl, false)) { - screenshot.write(new File(filename)); - System.err.println("Wrote: "+filename); - } - } - private int shotCount = 0; - - public void setIgnoreInput(final boolean v) { - ignoreInput = v; - } - public boolean getIgnoreInput() { - return ignoreInput; - } -} diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java new file mode 100644 index 000000000..7ba6c135b --- /dev/null +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java @@ -0,0 +1,356 @@ +/** + * Copyright 2010-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.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.Locale; + +import com.jogamp.common.net.Uri; +import com.jogamp.common.util.InterruptSource; +import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.curve.opengl.RenderState; +import com.jogamp.graph.font.Font; +import com.jogamp.graph.font.FontFactory; +import com.jogamp.graph.font.FontSet; +import com.jogamp.graph.geom.SVertex; +import com.jogamp.graph.geom.plane.AffineTransform; +import com.jogamp.graph.ui.gl.Scene; +import com.jogamp.graph.ui.gl.Shape; +import com.jogamp.graph.ui.gl.Shape.EventInfo; +import com.jogamp.graph.ui.gl.shapes.Button; +import com.jogamp.graph.ui.gl.shapes.GLButton; +import com.jogamp.graph.ui.gl.shapes.MediaButton; +import com.jogamp.newt.Window; +import com.jogamp.newt.event.KeyAdapter; +import com.jogamp.newt.event.KeyEvent; +import com.jogamp.newt.event.MouseEvent; +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.GLPipelineFactory; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.GLRunnable; +import com.jogamp.opengl.demos.es2.GearsES2; +import com.jogamp.opengl.demos.graph.MSAATool; +import com.jogamp.opengl.fixedfunc.GLMatrixFunc; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.GLReadBufferUtil; +import com.jogamp.opengl.util.PMVMatrix; +import com.jogamp.opengl.util.av.GLMediaPlayer; +import com.jogamp.opengl.util.av.GLMediaPlayerFactory; + +/** + * Basic UIScene demo using a single UIShape. + * + * 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 class UISceneDemo00 implements GLEventListener { + static final boolean DEBUG = false; + static final boolean TRACE = false; + + static private final String defaultMediaPath = "http://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4"; + static private String filmPath = defaultMediaPath; + + public static void main(final String[] args) throws IOException { + Font font = null; + if( 0 != args.length ) { + for(int i=0; i "+sceneSize[0]+" x "+sceneSize[1]+" model"); + final float sw = 1/3f * sceneSize[0]; + final float sh = sw / 2f; + System.err.println("Shape "+sw+" x "+sh); + + if( true ) { + Uri filmUri; + try { + filmUri = Uri.cast( filmPath ); + } catch (final URISyntaxException e1) { + throw new RuntimeException(e1); + } + final GLMediaPlayer mPlayer = GLMediaPlayerFactory.createDefault(); + // mPlayer.setTextureUnit(texUnitMediaPlayer); + final MediaButton b = new MediaButton(SVertex.factory(), renderModes, sw, sh, mPlayer); + b.setVerbose(true); + b.addDefaultEventListener(); + b.setToggleable(true); + b.setToggle(true); + b.setToggleOffColorMod(0f, 1f, 0f, 1.0f); + b.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + mPlayer.setAudioVolume( b.isToggleOn() ? 1f : 0f ); + } } ); + mPlayer.playStream(filmUri, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.TEXTURE_COUNT_DEFAULT); + shape = b; + } else if( true ) { + final GLEventListener glel; + { + final GearsES2 gears = new GearsES2(0); + gears.setVerbose(false); + gears.setClearColor(new float[] { 0.9f, 0.9f, 0.9f, 1f } ); + glel = gears; + } + final int texUnit = 1; + final GLButton b = new GLButton(scene.getVertexFactory(), renderModes, + sw, sh, texUnit, glel, false /* useAlpha */); + b.setToggleable(true); + b.setToggle(true); // toggle == true -> animation + b.setAnimate(true); + b.addMouseListener(shapeGesture); + b.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + b.setAnimate( b.isToggleOn() ); + } } ); + shape = b; + } else { + final Button b = new Button(SVertex.factory(), renderModes, font, "Click me!", sw, sh); + b.setLabelColor(0.0f,0.0f,0.0f); + b.addMouseListener(shapeGesture); + shape = b; + } + shape.move((sceneSize[0] - sw)/2f, (sceneSize[1] - sh)/2f, 0f); // center + scene.addShape(shape); + } + + final Shape.MouseGestureAdapter shapeGesture = new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); + System.err.println("Shape.EventInfo: "+shapeEvent); + final Shape s = shapeEvent.shape; + + final RegionRenderer renderer = scene.getRenderer(); + final PMVMatrix pmv = new PMVMatrix(); + scene.setupMatrix(pmv, 0, 0); + + // flip to GL window coordinates, origin bottom-left + final int[] viewport = renderer.getViewport(new int[4]); + final int glWinX = e.getX(); + final int glWinY = viewport[3] - e.getY() - 1; + { + pmv.glPushMatrix(); + s.setTransform(pmv); + + final float[] objPos = new float[3]; + s.winToObjCoord(renderer, glWinX, glWinY, objPos); + System.err.println("Button: Click: Win "+glWinX+"/"+glWinY+" -> Obj "+objPos[0]+"/"+objPos[1]+"/"+objPos[1]); + + final int[] surfaceSize = new int[2]; + s.getSurfaceSize(renderer, surfaceSize); + System.err.println("Button: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]); + + pmv.glPopMatrix(); + } + } }; + + public final float[] getPosition() { return position; } + + @Override + public void init(final GLAutoDrawable drawable) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + if(debug) { + gl = gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Debug", null, gl, null) ).getGL2ES2(); + } + if(trace) { + gl = gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Trace", null, gl, new Object[] { System.err } ) ).getGL2ES2(); + } + + if(drawable instanceof GLWindow) { + final GLWindow glw = (GLWindow) drawable; + scene.attachInputListenerTo(glw); + } + gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + + gl.setSwapInterval(1); + gl.glEnable(GL.GL_DEPTH_TEST); + gl.glEnable(GL.GL_POLYGON_OFFSET_FILL); + MSAATool.dump(drawable); + + System.err.println("Init: Shape "+shape); + scene.init(drawable); + } + + @Override + public void reshape(final GLAutoDrawable drawable, final int xstart, final int ystart, final int width, final int height) { + // Layout all shapes: Just stay centered + // + // shape.move(0f, 0f, 0f); + System.err.println("Reshape: Shape "+shape); + + System.err.println("Reshape: Scene Plane.R "+scene.getBounds()); + + scene.reshape(drawable, xstart, ystart, width, height); + + System.err.println("Reshape: Scene Plane.R "+scene.getBounds()); + + if( drawable instanceof Window ) { + ((Window)drawable).setTitle(UISceneDemo00.class.getSimpleName()+": "+drawable.getSurfaceWidth()+" x "+drawable.getSurfaceHeight()); + } + } + + final int[] sampleCount = { 4 }; + + @Override + public void display(final GLAutoDrawable drawable) { + scene.display(drawable); + } + static boolean once = true; + + @Override + public void dispose(final GLAutoDrawable drawable) { + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + scene.dispose(drawable); // disposes all registered UIShapes + + screenshot.dispose(gl); + } + + public void printScreen(final GL gl) { + final RegionRenderer renderer = scene.getRenderer(); + final String modeS = Region.getRenderModeString(renderModes); + final String filename = String.format((Locale)null, "UISceneDemo00-shot%03d-%03dx%03d-S_%s_%02d.png", + shotCount++, renderer.getWidth(), renderer.getHeight(), + modeS, scene.getSampleCount()); + gl.glFinish(); // just make sure rendering finished .. + if(screenshot.readPixels(gl, false)) { + screenshot.write(new File(filename)); + System.err.println("Wrote: "+filename); + } + } + private int shotCount = 0; + + public void setIgnoreInput(final boolean v) { + ignoreInput = v; + } + public boolean getIgnoreInput() { + return ignoreInput; + } +} -- cgit v1.2.3