From 033c96fc22912c48539c5473283455c0179543ef Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 21 Mar 2023 11:00:42 +0100 Subject: GraphUI UISceneDemo20: Consolidate the actual implementation and main launcher to our new UISceneDemo naming series --- make/scripts/tests.sh | 12 +- .../demos/android/NEWTGraphUI1pActivity.java | 4 +- .../demos/android/NEWTGraphUI2pActivity.java | 4 +- .../demos/graph/ui/GPUUISceneGLListener0A.java | 938 ----------------- .../opengl/demos/graph/ui/GPUUISceneNewtDemo.java | 204 ---- .../opengl/demos/graph/ui/UISceneDemo20.java | 1110 ++++++++++++++++++++ 6 files changed, 1121 insertions(+), 1151 deletions(-) delete mode 100644 src/demos/com/jogamp/opengl/demos/graph/ui/GPUUISceneGLListener0A.java delete mode 100644 src/demos/com/jogamp/opengl/demos/graph/ui/GPUUISceneNewtDemo.java create mode 100644 src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 4bbfa980f..cc29f36f4 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -508,8 +508,7 @@ function testawtswt() { #testswt com.jogamp.opengl.test.junit.jogl.swt.TestGLCanvasSWTNewtCanvasSWTPosInTabs $* #testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsAWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.glsl.TestRulerNEWT01 $* -#testnoawt com.jogamp.opengl.demos.graph.ui.GPUUISceneNewtDemo $* -#testawt com.jogamp.opengl.demos.graph.ui.GPUUISceneNewtCanvasAWTDemo $* +#testnoawt com.jogamp.opengl.demos.graph.ui.UISceneDemo20 $* #testawt com.jogamp.opengl.test.junit.jogl.awt.ManualHiDPIBufferedImage01AWT $* # @@ -969,8 +968,11 @@ function testawtswt() { #testnoawt com.jogamp.opengl.demos.graph.GPURegionNewtDemo $* #testnoawt com.jogamp.opengl.demos.graph.ui.UIShapeDemo01 $* #testnoawt com.jogamp.opengl.demos.graph.ui.UITypeDemo01 $* +#testnoawt com.jogamp.opengl.demos.graph.ui.UISceneDemo00 $* #testnoawt com.jogamp.opengl.demos.graph.ui.UISceneDemo01 $* -#testnoawt com.jogamp.opengl.demos.graph.ui.GPUUISceneNewtDemo $* +#testnoawt com.jogamp.opengl.demos.graph.ui.UISceneDemo02 $* +#testnoawt com.jogamp.opengl.demos.graph.ui.UISceneDemo10 $* +#testnoawt com.jogamp.opengl.demos.graph.ui.UISceneDemo20 $* #testnoawt com.jogamp.opengl.demos.av.MovieCube $* #testnoawt com.jogamp.opengl.demos.av.MovieSimple $* @@ -1010,8 +1012,8 @@ function testawtswt() { #testnoawt com.jogamp.opengl.demos.graph.ui.UISceneDemo00 $* #testnoawt com.jogamp.opengl.demos.graph.ui.UISceneDemo01 $* #testnoawt com.jogamp.opengl.demos.graph.ui.UISceneDemo02 $* - -testnoawt com.jogamp.opengl.demos.graph.ui.GPUUISceneNewtDemo $* +#testnoawt com.jogamp.opengl.demos.graph.ui.UISceneDemo10 $* +testnoawt com.jogamp.opengl.demos.graph.ui.UISceneDemo20 $* #testnoawt com.jogamp.opengl.demos.av.MovieCube $* #testnoawt com.jogamp.opengl.demos.av.MovieSimple $* diff --git a/src/demos/com/jogamp/opengl/demos/android/NEWTGraphUI1pActivity.java b/src/demos/com/jogamp/opengl/demos/android/NEWTGraphUI1pActivity.java index ea512375f..09f9356e8 100644 --- a/src/demos/com/jogamp/opengl/demos/android/NEWTGraphUI1pActivity.java +++ b/src/demos/com/jogamp/opengl/demos/android/NEWTGraphUI1pActivity.java @@ -29,7 +29,7 @@ package com.jogamp.opengl.demos.android; import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLProfile; -import com.jogamp.opengl.demos.graph.ui.GPUUISceneGLListener0A; +import com.jogamp.opengl.demos.graph.ui.UISceneDemo20; import jogamp.newt.driver.android.NewtBaseActivity; @@ -59,7 +59,7 @@ public class NEWTGraphUI1pActivity extends NewtBaseActivity { glWindow.setFullscreen(true); setContentView(getWindow(), glWindow); - glWindow.addGLEventListener(new GPUUISceneGLListener0A(0)); + glWindow.addGLEventListener(new UISceneDemo20(0)); glWindow.getScreen().addMonitorModeListener(new MonitorModeListener() { @Override public void monitorModeChangeNotify(final MonitorEvent me) { } diff --git a/src/demos/com/jogamp/opengl/demos/android/NEWTGraphUI2pActivity.java b/src/demos/com/jogamp/opengl/demos/android/NEWTGraphUI2pActivity.java index ede8a5d31..cf54c2890 100644 --- a/src/demos/com/jogamp/opengl/demos/android/NEWTGraphUI2pActivity.java +++ b/src/demos/com/jogamp/opengl/demos/android/NEWTGraphUI2pActivity.java @@ -29,7 +29,7 @@ package com.jogamp.opengl.demos.android; import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLProfile; -import com.jogamp.opengl.demos.graph.ui.GPUUISceneGLListener0A; +import com.jogamp.opengl.demos.graph.ui.UISceneDemo20; import jogamp.newt.driver.android.NewtBaseActivity; @@ -58,7 +58,7 @@ public class NEWTGraphUI2pActivity extends NewtBaseActivity { glWindow.setFullscreen(true); setContentView(getWindow(), glWindow); - glWindow.addGLEventListener(new GPUUISceneGLListener0A(Region.VBAA_RENDERING_BIT)); + glWindow.addGLEventListener(new UISceneDemo20(Region.VBAA_RENDERING_BIT)); glWindow.getScreen().addMonitorModeListener(new MonitorModeListener() { @Override public void monitorModeChangeNotify(final MonitorEvent me) { } diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/GPUUISceneGLListener0A.java b/src/demos/com/jogamp/opengl/demos/graph/ui/GPUUISceneGLListener0A.java deleted file mode 100644 index 2fcdeb592..000000000 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/GPUUISceneGLListener0A.java +++ /dev/null @@ -1,938 +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.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; - -import com.jogamp.opengl.GL; -import com.jogamp.opengl.GL2ES2; -import com.jogamp.opengl.GLAnimatorControl; -import com.jogamp.opengl.GLAutoDrawable; -import com.jogamp.opengl.GLEventListener; -import com.jogamp.opengl.GLPipelineFactory; -import com.jogamp.opengl.GLRunnable; -import com.jogamp.opengl.JoglVersion; -import com.jogamp.opengl.demos.es2.GearsES2; -import com.jogamp.opengl.demos.graph.FontSetDemos; -import com.jogamp.opengl.demos.graph.MSAATool; -import com.jogamp.opengl.fixedfunc.GLMatrixFunc; -import com.jogamp.common.net.Uri; -import com.jogamp.common.util.IOUtil; -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.FontScale; -import com.jogamp.graph.ui.gl.Scene; -import com.jogamp.graph.ui.gl.Shape; -import com.jogamp.graph.ui.gl.Scene.PMVMatrixSetup; -import com.jogamp.graph.ui.gl.shapes.Button; -import com.jogamp.graph.ui.gl.shapes.GLButton; -import com.jogamp.graph.ui.gl.shapes.ImageButton; -import com.jogamp.graph.ui.gl.shapes.Label; -import com.jogamp.graph.ui.gl.shapes.MediaButton; -import com.jogamp.graph.ui.gl.shapes.RoundButton; -import com.jogamp.newt.MonitorDevice; -import com.jogamp.newt.Window; -import com.jogamp.newt.event.MouseEvent; -import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.math.FloatUtil; -import com.jogamp.opengl.math.VectorUtil; -import com.jogamp.opengl.math.geom.AABBox; -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; -import com.jogamp.opengl.util.texture.ImageSequence; -import com.jogamp.opengl.util.texture.TextureIO; - -public class GPUUISceneGLListener0A implements GLEventListener { - static private final String defaultMediaURL = "http://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4"; - - private boolean debug = false; - private boolean trace = false; - - private final float noAADPIThreshold; - private final Scene scene; - - /** -1 == AUTO, TBD @ init(..) */ - private int renderModes; - - private final Font font; - private final Font fontFPS; - private final Uri filmURL; - - private final float relTop = 80f/100f; - private final float relMiddle = 22f/100f; - private final float relLeft = 11f/100f; - - /** Relative Button Size to Window Height, normalized to 1. */ - private static final float buttonXSizeNorm = 0.084f; - private static final float fontSizePt = 10f; - /** Relative Font Size to Window Height for Main Text, normalized to 1. */ - private static final float fontSizeFixedNorm = 0.04f; - /** Relative Font Size to Window Height for FPS Status Line, normalized to 1. */ - private static final float fontSizeFpsNorm = 0.03f; // 1/18f; - private float dpiV = 96; - - /** - * Default DPI threshold value to disable {@link Region#VBAA_RENDERING_BIT VBAA}: {@value} dpi - * @see #GPUUISceneGLListener0A(float) - * @see #GPUUISceneGLListener0A(float, boolean, boolean) - */ - public static final float DefaultNoAADPIThreshold = 200f; - - private int currentText = 0; - - private String actionText = null; - private Label[] labels = null; - private String[] strings = null; - private final List buttons = new ArrayList(); - private int buttonsLeftCount = 0; - private Label truePtSizeLabel = null; - private Label jogampLabel = null; - private Label fpsLabel = null; - - private GLAutoDrawable cDrawable; - - private final GLReadBufferUtil screenshot; - - private final String jogamp = "JogAmp - Jogl Graph Module Demo"; - private final String truePtSize = fontSizePt+" pt font size label - true scale!"; - - private final String longText = "JOGL: Java™ Binding for the OpenGL® API.\n\n"+ - "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec \n"+ - "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel\n"+ - "quam iaculis urna cursus ornare. Nullam ut felis a ante ultrices\n"+ - "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia\n"+ - "Morbi quis bibendum nibh. Donec lectus orci, sagittis in consequat\n"+ - "Donec ut dolor et nulla tristique varius. In nulla magna, fermentum\n"+ - "in lorem. Maecenas in ipsum ac justo scelerisque sollicitudin.\n"+ - "\n"+ - "Lyford’s in Texas & L’Anse-aux-Griffons in Québec;\n"+ - "Kwikpak on the Yukon delta, Kvæven in Norway, Kyulu in Kenya, not Rwanda.…\n"+ - "Ytterbium in the periodic table. Are Toussaint L’Ouverture, Wölfflin, Wolfe,\n"+ - "\n"+ - "The quick brown fox jumps over the lazy dog\n"; - - /** - * @param renderModes - */ - public GPUUISceneGLListener0A(final int renderModes) { - this(null, null, renderModes, false, false); - } - - /** - * @param filmURL TODO - * @param renderModes - * @param debug - * @param trace - */ - public GPUUISceneGLListener0A(final String fontfilename, final String filmURL, final int renderModes, final boolean debug, final boolean trace) { - this(fontfilename, filmURL, 0f, renderModes, debug, trace); - } - - /** - * @param filmURL TODO - * @param noAADPIThreshold see {@link #DefaultNoAADPIThreshold} - * @param debug - * @param trace - */ - public GPUUISceneGLListener0A(final String fontfilename, final String filmURL, final float noAADPIThreshold, final boolean debug, final boolean trace) { - this(fontfilename, filmURL, noAADPIThreshold, 0, debug, trace); - } - - private GPUUISceneGLListener0A(final String fontfilename, final String filmURL, final float noAADPIThreshold, final int renderModes, final boolean debug, final boolean trace) { - this.noAADPIThreshold = noAADPIThreshold; - this.debug = debug; - this.trace = trace; - - this.renderModes = renderModes; - - try { - if( null == fontfilename ) { - font = FontFactory.get(IOUtil.getResource("fonts/freefont/FreeSerif.ttf", - FontSetDemos.class.getClassLoader(), FontSetDemos.class).getInputStream(), true); - } else { - font = FontFactory.get( new File( fontfilename ) ); - } - System.err.println("Font "+font.getFullFamilyName()); - - fontFPS = FontFactory.get(IOUtil.getResource("fonts/freefont/FreeMonoBold.ttf", - FontSetDemos.class.getClassLoader(), FontSetDemos.class).getInputStream(), true); - System.err.println("Font FPS "+fontFPS.getFullFamilyName()); - - } catch (final IOException ioe) { - throw new RuntimeException(ioe); - } - try { - this.filmURL = Uri.cast( null != filmURL ? filmURL : defaultMediaURL ); - } catch (final URISyntaxException e1) { - throw new RuntimeException(e1); - } - scene = new Scene(); - scene.setPMVMatrixSetup(new MyPMVMatrixSetup()); - scene.getRenderState().setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED); - // scene.setSampleCount(3); // easy on embedded devices w/ just 3 samples (default is 4)? - - screenshot = new GLReadBufferUtil(false, false); - } - - private void rotateButtons(float[] angdeg) { - angdeg = VectorUtil.scaleVec3(angdeg, angdeg, FloatUtil.PI / 180.0f); - for(int i=0; i0); - button.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - cDrawable.invoke(false, new GLRunnable() { - @Override - public boolean run(final GLAutoDrawable drawable) { - final GL gl = drawable.getGL(); - gl.setSwapInterval(gl.getSwapInterval()<=0?1:0); - final GLAnimatorControl a = drawable.getAnimator(); - if( null != a ) { - a.resetFPSCounter(); - } - return true; - } - }); - } } ); - button.addMouseListener(dragZoomRotateListener); - buttons.add(button); - - button = new Button(renderModes, font, "< Tilt >", buttonXSize, buttonYSize); - button.move(xStartLeft,yStartTop - diffY*buttons.size(), 0f); - button.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); - if( shapeEvent.objPos[0] < shapeEvent.shape.getBounds().getCenter()[0] ) { - rotateButtons(new float[] { 0f, -5f, 0f}); // left-half pressed - } else { - rotateButtons(new float[] { 0f, 5f, 0f}); // right-half pressed - } - } - @Override - public void mouseWheelMoved(final MouseEvent e) { - rotateButtons(new float[] { 0f, e.getRotation()[1], 0f}); - } } ); - buttons.add(button); - - if( pass2Mode ) { // second column to the left - button = new Button(renderModes, font, "< Samples >", buttonXSize, buttonYSize); - button.move(xStartLeft,yStartTop - diffY*buttons.size(), 0f); - button.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); - int sampleCount = scene.getSampleCount(); - if( shapeEvent.objPos[0] < shapeEvent.shape.getBounds().getCenter()[0] ) { - // left-half pressed - sampleCount--; - } else { - // right-half pressed - sampleCount++; - } - sampleCount = scene.setSampleCount(sampleCount); // validated / clipped - } } ); - button.addMouseListener(dragZoomRotateListener); - buttons.add(button); - - button = new Button(renderModes, font, "< Quality >", buttonXSize, buttonYSize); - button.move(xStartLeft,yStartTop - diffY*buttons.size(), 0f); - button.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); - int quality = shapeEvent.shape.getQuality(); - - if( shapeEvent.objPos[0] < shapeEvent.shape.getBounds().getCenter()[0] ) { - // left-half pressed - if( quality > 0 ) { - quality--; - } - } else { - // right-half pressed - if( quality < Region.MAX_QUALITY ) { - quality++; - } - } - scene.setAllShapesQuality(quality); - } } ); - button.addMouseListener(dragZoomRotateListener); - buttons.add(button); - } - - button = new Button(renderModes, font, "Quit", buttonXSize, buttonYSize); - button.setName(BUTTON_QUIT); - button.move(xStartLeft,yStartTop - diffY*buttons.size(), 0f); - button.setColor(0.7f, 0.0f, 0.0f, 1.0f); - button.setLabelColor(1.2f, 1.2f, 1.2f); - button.setPressedColorMod(1.1f, 0.0f, 0.0f, 1.0f); - button.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - new InterruptSource.Thread() { - @Override - public void run() { - if( null != cDrawable ) { - final GLAnimatorControl actrl = cDrawable.getAnimator(); - if( null != actrl ) { - actrl.stop(); - } - cDrawable.destroy(); - } - } }.start(); - } } ); - button.addMouseListener(dragZoomRotateListener); - buttons.add(button); - - // second column to the left - { - final int j = 1; // column - int k = 0; // row - button = new Button(renderModes, font, "Y Flip", buttonXSize, buttonYSize); - button.move(xStartLeft - diffX*j,yStartTop - diffY*k, 0f); - button.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - rotateButtons(new float[] { 0f, 180f, 0f}); - } } ); - button.addMouseListener(dragZoomRotateListener); - buttons.add(button); - - k++; - button = new Button(renderModes, font, "X Flip", buttonXSize, buttonYSize); - button.move(xStartLeft - diffX*j,yStartTop - diffY*k, 0f); - button.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - rotateButtons(new float[] { 180f, 0f, 0f}); - } } ); - button.addMouseListener(dragZoomRotateListener); - buttons.add(button); - k++; - - button = new Button(renderModes, font, "< Space >", buttonXSize, buttonYSize); - button.move(xStartLeft - diffX*j,yStartTop - diffY*k, 0f); - button.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); - final float dx, dy; - if( shapeEvent.objPos[0] < shapeEvent.shape.getBounds().getCenter()[0] ) { - dx=-0.01f; dy=-0.005f; - } else { - dx=0.01f; dy=0.005f; - } - setButtonsSpacing(dx, dy); - } - @Override - public void mouseWheelMoved(final MouseEvent e) { - setButtonsSpacing(e.getRotation()[0]/100f, e.getRotation()[1]/200f); - } } ); - buttons.add(button); - k++; - - button = new Button(renderModes, font, "< Corner >", buttonXSize, buttonYSize); - button.move(xStartLeft - diffX*j,yStartTop - diffY*k, 0f); - button.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); - final float dc; - if( shapeEvent.objPos[0] < shapeEvent.shape.getBounds().getCenter()[0] ) { - dc=-0.1f; - } else { - dc=0.1f; - } - setButtonsCorner(dc); - } - @Override - public void mouseWheelMoved(final MouseEvent e) { - setButtonsCorner(e.getRotation()[1]/20f); - } } ); - buttons.add(button); - k++; - - button = new Button(renderModes, font, "Reset", buttonXSize, buttonYSize); - button.move(xStartLeft - diffX*j,yStartTop - diffY*k, 0f); - button.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - resetButtons(); - } } ); - button.addMouseListener(dragZoomRotateListener); - buttons.add(button); - k++; - - button = new Button(renderModes, font, "Snapshot", buttonXSize, buttonYSize); - button.move(xStartLeft - diffX*j,yStartTop - diffY*k, 0f); - button.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - cDrawable.invoke(false, new GLRunnable() { - @Override - public boolean run(final GLAutoDrawable drawable) { - printScreen(drawable.getGL()); - return true; - } - }); - } } ); - button.addMouseListener(dragZoomRotateListener); - buttons.add(button); - k++; - } - - buttonsLeftCount = buttons.size(); - - final int texUnitMediaPlayer, texUnitImageButton, texUnitGLELButton; - { - // works - but not required .. - texUnitMediaPlayer=1; - texUnitImageButton=2; - texUnitGLELButton=3; - } - - if( true ) { - final GLMediaPlayer mPlayer = GLMediaPlayerFactory.createDefault(); - mPlayer.setTextureUnit(texUnitMediaPlayer); - final MediaButton mPlayerButton = new MediaButton(renderModes, button2XSize, - button2YSize, mPlayer); - mPlayerButton.setName(BUTTON_MOVIE); - mPlayerButton.setVerbose(false); - mPlayerButton.addDefaultEventListener(); - mPlayerButton.move(xStartRight, yStartTop - diffY*1, 0f); - mPlayerButton.setToggleable(true); - mPlayerButton.setToggle(true); // toggle == false -> mute audio - mPlayerButton.setToggleOffColorMod(0f, 1f, 0f, 1.0f); - mPlayerButton.addMouseListener(dragZoomRotateListener); - mPlayerButton.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - mPlayer.setAudioVolume( mPlayerButton.isToggleOn() ? 1f : 0f ); - } } ); - buttons.add(mPlayerButton); - mPlayer.playStream(filmURL, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.TEXTURE_COUNT_DEFAULT); - } - if( true ) { - final ImageSequence imgSeq = new ImageSequence(texUnitImageButton, true); - final ImageButton imgButton = new ImageButton(renderModes, button2XSize, - button2YSize, imgSeq); - try { - imgSeq.addFrame(gl, GPUUISceneGLListener0A.class, "button-released-145x53.png", TextureIO.PNG); - imgSeq.addFrame(gl, GPUUISceneGLListener0A.class, "button-pressed-145x53.png", TextureIO.PNG); - } catch (final IOException e2) { - e2.printStackTrace(); - } - imgSeq.setManualStepping(true); - imgButton.move(xStartRight, yStartTop - diffY*2.5f, 0f); - imgButton.addMouseListener(dragZoomRotateListener); - imgButton.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mousePressed(final MouseEvent e) { - imgButton.setCurrentIdx(1); - System.err.println("XXX: "+imgButton); - } - @Override - public void mouseReleased(final MouseEvent e) { - imgButton.setCurrentIdx(0); - } } ); - buttons.add(imgButton); - } - if( true ) { - // Issues w/ OSX and NewtCanvasAWT when rendering / animating - // Probably related to CALayer - FBO - FBO* (of this button) - final GearsES2 gears = new GearsES2(0); - gears.setVerbose(false); - gears.setClearColor(new float[] { 0.9f, 0.9f, 0.9f, 1f } ); - final boolean[] animate = { true }; - new Thread(new Runnable() { - @Override - public void run() { - System.err.println("Gears Anim: Waiting"); - try { - gears.waitForInit(true); - } catch (final InterruptedException e) { } - System.err.println("Gears Anim: Started"); - while( gears.isInit() ) { - if( animate[0] ) { - final float ry = ( gears.getRotY() + 1 ) % 360; - gears.setRotY(ry); - } - try { - Thread.sleep(15); - } catch (final InterruptedException e) { } - } - System.err.println("Gears Anim: End"); - } - }).start(); - final GLButton b = new GLButton(renderModes, button2XSize, - button2YSize, texUnitGLELButton, - gears, false /* useAlpha */); - b.setName(BUTTON_GLEL); - b.setToggleable(true); - b.setToggle(false); // toggle == true -> animation - b.setAnimate(false); - b.move(xStartRight, yStartTop - diffY*4f, 0f); - b.addMouseListener(dragZoomRotateListener); - b.addMouseListener(new Shape.MouseGestureAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - b.setAnimate( b.isToggleOn() ); - animate[0] = b.getAnimate(); - } } ); - buttons.add(b); - } - } - - private void initTexts() { - strings = new String[4]; - int i = 0; - - strings[i++] = "- Mouse Scroll Over Object\n"+ - " - General\n"+ - " - X-Rotation\n"+ - " - Shift: Y-Rotation\n"+ - " - Tilt, Space and Corner\n"+ - " - Their respective action via wheel\n"+ - " (shift = other value)\n"+ - "\n"+ - "- Mouse Drag On Object\n"+ - " - Click on Object and drag mouse\n"+ - " - Current postion in status line at bottom\n"+ - " - Resize when click on 1/4 bottom-left or bottom-right corner.\n"+ - "\n"+ - "- Tilt Button Rotate Whole Button Group"; - - strings[i++] = "abcdefghijklmn\nopqrstuvwxyz\n"+ - "ABCDEFGHIJKL\n"+ - "MNOPQRSTUVWXYZ\n"+ - "0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]"; - - strings[i++] = "The quick brown fox jumps over the lazy dog"; - - strings[i++] = longText; - - labels = new Label[i]; - - currentText = strings.length - 1; - } - - - private static final boolean enableOthers = true; - - - private void setupUI(final GLAutoDrawable drawable, final AABBox sceneBox) { - final float[/*2*/] sceneSize = { 0f, 0f }; - scene.surfaceToPlaneSize(new int[] { 0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight()}, sceneSize); - - final float modelSizeFixed = fontSizeFixedNorm * sceneSize[1]; - jogampLabel = new Label(renderModes, font, modelSizeFixed, jogamp); - jogampLabel.addMouseListener(dragZoomRotateListener); - scene.addShape(jogampLabel); - jogampLabel.setEnabled(enableOthers); - - final float pixelSize10Pt = FontScale.toPixels(fontSizePt, dpiV); - final float modelSize10Pt = pixelSize10Pt / drawable.getSurfaceHeight() * sceneSize[1]; - System.err.println("10Pt PixelSize: Display "+dpiV+" dpi, fontSize "+fontSizePt+" ppi -> "+pixelSize10Pt+" pixe-size, "+modelSize10Pt+" model-size"); - truePtSizeLabel = new Label(renderModes, font, modelSize10Pt, truePtSize); - scene.addShape(truePtSizeLabel); - truePtSizeLabel.setEnabled(enableOthers); - truePtSizeLabel.move(0, - 1.5f * jogampLabel.getLineHeight(), 0f); - truePtSizeLabel.setColor(0.1f, 0.1f, 0.1f, 1.0f); - - /** - * - * [Label] Display 112.88889 dpi, fontSize 12.0 ppi -> pixelSize 18.814816 - * [FPS] Display 112.88889 dpi, fontSize 12.0 ppi -> pixelSize 15.679012 - */ - final float pixelSizeFPS = fontSizeFpsNorm * drawable.getSurfaceHeight(); - final float modelSizeFPS = pixelSizeFPS / drawable.getSurfaceHeight() * sceneSize[1]; - fpsLabel = new Label(renderModes, fontFPS, modelSizeFPS, "Nothing there yet"); - fpsLabel.addMouseListener(dragZoomRotateListener); - scene.addShape(fpsLabel); - fpsLabel.setEnabled(enableOthers); - fpsLabel.setColor(0.1f, 0.1f, 0.1f, 1.0f); - fpsLabel.move(0f, modelSizeFPS * (fontFPS.getMetrics().getLineGap() - fontFPS.getMetrics().getDescent()), 0f); - - final float sx = sceneBox.getWidth(); - final float sy = sceneBox.getHeight(); - final float sxy = sx > sy ? sx : sy; - initButtons(drawable.getGL().getGL2ES2(), sxy); - scene.addShapes(buttons); - } - - @Override - public void init(final GLAutoDrawable drawable) { - final Object upObj = drawable.getUpstreamWidget(); - if( upObj instanceof Window ) { - final Window upWin = (Window)upObj; - final MonitorDevice monitor = upWin.getMainMonitor(); - final float[] monitorDPI = MonitorDevice.perMMToPerInch( monitor.getPixelsPerMM(new float[2]) ); - final float[] sDPI = MonitorDevice.perMMToPerInch( upWin.getPixelsPerMM(new float[2]) ); - dpiV = sDPI[1]; - System.err.println("Monitor detected: "+monitor); - System.err.println("Monitor dpi: "+monitorDPI[0]+" x "+monitorDPI[1]); - System.err.println("Surface scale: native "+Arrays.toString(upWin.getMaximumSurfaceScale(new float[2]))+", current "+Arrays.toString(upWin.getCurrentSurfaceScale(new float[2]))); - System.err.println("Surface dpi "+sDPI[0]+" x "+sDPI[1]); - } else { - System.err.println("Using default DPI of "+dpiV); - } - if( 0 == renderModes && !FloatUtil.isZero(noAADPIThreshold, FloatUtil.EPSILON)) { - final boolean noAA = dpiV >= noAADPIThreshold; - final String noAAs = noAA ? " >= " : " < "; - System.err.println("AUTO RenderMode: dpi "+dpiV+noAAs+noAADPIThreshold+" -> noAA "+noAA); - renderModes = noAA ? 0 : Region.VBAA_RENDERING_BIT; - } - if(drawable instanceof GLWindow) { - System.err.println("GPUUISceneGLListener0A: init (1)"); - final GLWindow glw = (GLWindow) drawable; - scene.attachInputListenerTo(glw); - } else { - System.err.println("GPUUISceneGLListener0A: init (0)"); - } - cDrawable = 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(); - } - System.err.println(JoglVersion.getGLInfo(gl, null, false /* withCapsAndExts */).toString()); - System.err.println("VSync Swap Interval: "+gl.getSwapInterval()); - System.err.println("Chosen: "+drawable.getChosenGLCapabilities()); - MSAATool.dump(drawable); - - gl.setSwapInterval(1); - gl.glEnable(GL.GL_DEPTH_TEST); - gl.glEnable(GL.GL_BLEND); - - initTexts(); - - scene.init(drawable); - - final GLAnimatorControl a = drawable.getAnimator(); - if( null != a ) { - a.resetFPSCounter(); - } - } - - @Override - public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { - System.err.println("GPUUISceneGLListener0A: reshape"); - - // - // Layout all shapes: Relational move regarding object coordinates - // - System.err.println("Reshape: Scene Plane.0 "+scene.getBounds()); - final float lastWidth = scene.getBounds().getWidth(); - final float lastHeight = scene.getBounds().getHeight(); - System.err.println("Reshape: Scene Plane.0 "+lastWidth+" x "+lastHeight); - - scene.reshape(drawable, x, y, width, height); - final AABBox sceneBox = scene.getBounds(); - System.err.println("Reshape: Scene Plane.1 "+sceneBox); - - if( scene.getShapes().isEmpty() ) { - setupUI(drawable, sceneBox); - } - - final float dw = sceneBox.getWidth() - lastWidth; - final float dh = sceneBox.getHeight() - lastHeight; - - final float dz = 0f; - final float dyTop = dh * relTop; - final float dxLeft = dw * relLeft; - final float dxRight = dw; - - System.err.println("XXX: dw "+dw+", dh "+dh+", dxLeft "+dxLeft+", dxRight "+dxRight+", dyTop "+dyTop); - - for(int i=0; i 0 ) { - caps.setSampleBuffers(true); - caps.setNumSamples(sceneMSAASamples); - } - System.out.println("Requested: " + caps); - - final int renderModes; - if( graphVBAAMode ) { - renderModes = Region.VBAA_RENDERING_BIT; - } else if( graphMSAAMode ) { - renderModes = Region.MSAA_RENDERING_BIT; - } else { - renderModes = 0; - } - - final GLWindow window = GLWindow.create(screen, caps); - if( 0 == sceneMSAASamples ) { - window.setCapabilitiesChooser(new NonFSAAGLCapsChooser(true)); - } - window.setSize(width, height); - window.setTitle("GraphUI Newt Demo: graph["+Region.getRenderModeString(renderModes)+"], msaa "+sceneMSAASamples); - window.setSurfaceScale(reqSurfacePixelScale); - // final float[] valReqSurfacePixelScale = window.getRequestedSurfaceScale(new float[2]); - - final GPUUISceneGLListener0A scene = 0 < graphAutoMode ? new GPUUISceneGLListener0A(fontfilename, filmURL, graphAutoMode, DEBUG, TRACE) : - new GPUUISceneGLListener0A(fontfilename, filmURL, renderModes, DEBUG, TRACE); - window.addGLEventListener(scene); - - final Animator animator = new Animator(); - animator.setUpdateFPSFrames(5*60, null); - animator.add(window); - - window.addWindowListener(new WindowAdapter() { - @Override - public void windowDestroyed(final WindowEvent e) { - animator.stop(); - } - }); - - window.setVisible(true); - animator.start(); - - // sleep(3000); - // final UIShape movie = scene.getWidget(GPUUISceneGLListener0A.BUTTON_MOVIE); - } - -} diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java new file mode 100644 index 000000000..6cd5a9b76 --- /dev/null +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java @@ -0,0 +1,1110 @@ +/** + * 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.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +import com.jogamp.common.net.Uri; +import com.jogamp.common.util.IOUtil; +import com.jogamp.common.util.InterruptSource; +import com.jogamp.common.util.VersionUtil; +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.FontScale; +import com.jogamp.graph.ui.gl.Scene; +import com.jogamp.graph.ui.gl.Scene.PMVMatrixSetup; +import com.jogamp.graph.ui.gl.Shape; +import com.jogamp.graph.ui.gl.shapes.Button; +import com.jogamp.graph.ui.gl.shapes.GLButton; +import com.jogamp.graph.ui.gl.shapes.ImageButton; +import com.jogamp.graph.ui.gl.shapes.Label; +import com.jogamp.graph.ui.gl.shapes.MediaButton; +import com.jogamp.graph.ui.gl.shapes.RoundButton; +import com.jogamp.nativewindow.ScalableSurface; +import com.jogamp.newt.Display; +import com.jogamp.newt.MonitorDevice; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Screen; +import com.jogamp.newt.Window; +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.GLAnimatorControl; +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.JoglVersion; +import com.jogamp.opengl.demos.es2.GearsES2; +import com.jogamp.opengl.demos.graph.FontSetDemos; +import com.jogamp.opengl.demos.graph.MSAATool; +import com.jogamp.opengl.demos.util.MiscUtils; +import com.jogamp.opengl.fixedfunc.GLMatrixFunc; +import com.jogamp.opengl.math.FloatUtil; +import com.jogamp.opengl.math.VectorUtil; +import com.jogamp.opengl.math.geom.AABBox; +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; +import com.jogamp.opengl.util.caps.NonFSAAGLCapsChooser; +import com.jogamp.opengl.util.texture.ImageSequence; +import com.jogamp.opengl.util.texture.TextureIO; + +/** + * Complex interactive GraphUI Scene demo with different Button and Label Shapes layout on the screen. + *

+ * This demo uses sets up an own {@link Scene.PMVMatrixSetup}, {@link MyPMVMatrixSetup}, + * with a plane origin bottom-left and keeping the perspective non-normalized object screen dimension of < 1. + *

+ *

+ * Unlike {@link UISceneDemo00}, the {@link Scene}'s {@link GLEventListener} method are called directly + * from this {@link GLEventListener} implementation, i.e. the {@link Scene} is not attached + * to {@link GLAutoDrawable#addGLEventListener(GLEventListener)} itself. + *

+ */ +public class UISceneDemo20 implements GLEventListener { + static final boolean DEBUG = false; + static final boolean TRACE = false; + + public static void main(final String[] args) { + int sceneMSAASamples = 0; + boolean graphVBAAMode = true; + boolean graphMSAAMode = false; + float graphAutoMode = 0; // GPUUISceneGLListener0A.DefaultNoAADPIThreshold; + + final float[] reqSurfacePixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; + + String fontfilename = null; + String filmURL = null; + + int width = 1280, height = 720; + + boolean forceES2 = false; + boolean forceES3 = false; + boolean forceGL3 = false; + boolean forceGLDef = false; + + if( 0 != args.length ) { + for(int i=0; i 0 ) { + caps.setSampleBuffers(true); + caps.setNumSamples(sceneMSAASamples); + } + System.out.println("Requested: " + caps); + + final int renderModes; + if( graphVBAAMode ) { + renderModes = Region.VBAA_RENDERING_BIT; + } else if( graphMSAAMode ) { + renderModes = Region.MSAA_RENDERING_BIT; + } else { + renderModes = 0; + } + + final GLWindow window = GLWindow.create(screen, caps); + if( 0 == sceneMSAASamples ) { + window.setCapabilitiesChooser(new NonFSAAGLCapsChooser(true)); + } + window.setSize(width, height); + window.setTitle("GraphUI Newt Demo: graph["+Region.getRenderModeString(renderModes)+"], msaa "+sceneMSAASamples); + window.setSurfaceScale(reqSurfacePixelScale); + // final float[] valReqSurfacePixelScale = window.getRequestedSurfaceScale(new float[2]); + + final UISceneDemo20 scene = 0 < graphAutoMode ? new UISceneDemo20(fontfilename, filmURL, graphAutoMode, DEBUG, TRACE) : + new UISceneDemo20(fontfilename, filmURL, renderModes, DEBUG, TRACE); + window.addGLEventListener(scene); + + final Animator animator = new Animator(); + animator.setUpdateFPSFrames(5*60, null); + animator.add(window); + + window.addWindowListener(new WindowAdapter() { + @Override + public void windowDestroyed(final WindowEvent e) { + animator.stop(); + } + }); + + window.setVisible(true); + animator.start(); + } + + static private final String defaultMediaURL = "http://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4"; + + private boolean debug = false; + private boolean trace = false; + + private final float noAADPIThreshold; + private final Scene scene; + + /** -1 == AUTO, TBD @ init(..) */ + private int renderModes; + + private final Font font; + private final Font fontFPS; + private final Uri filmURL; + + private final float relTop = 80f/100f; + private final float relMiddle = 22f/100f; + private final float relLeft = 11f/100f; + + /** Relative Button Size to Window Height, normalized to 1. */ + private static final float buttonXSizeNorm = 0.084f; + private static final float fontSizePt = 10f; + /** Relative Font Size to Window Height for Main Text, normalized to 1. */ + private static final float fontSizeFixedNorm = 0.04f; + /** Relative Font Size to Window Height for FPS Status Line, normalized to 1. */ + private static final float fontSizeFpsNorm = 0.03f; // 1/18f; + private float dpiV = 96; + + /** + * Default DPI threshold value to disable {@link Region#VBAA_RENDERING_BIT VBAA}: {@value} dpi + * @see #GPUUISceneGLListener0A(float) + * @see #GPUUISceneGLListener0A(float, boolean, boolean) + */ + public static final float DefaultNoAADPIThreshold = 200f; + + private int currentText = 0; + + private String actionText = null; + private Label[] labels = null; + private String[] strings = null; + private final List buttons = new ArrayList(); + private int buttonsLeftCount = 0; + private Label truePtSizeLabel = null; + private Label jogampLabel = null; + private Label fpsLabel = null; + + private GLAutoDrawable cDrawable; + + private final GLReadBufferUtil screenshot; + + private final String jogamp = "JogAmp - Jogl Graph Module Demo"; + private final String truePtSize = fontSizePt+" pt font size label - true scale!"; + + private final String longText = "JOGL: Java™ Binding for the OpenGL® API.\n\n"+ + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec \n"+ + "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel\n"+ + "quam iaculis urna cursus ornare. Nullam ut felis a ante ultrices\n"+ + "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia\n"+ + "Morbi quis bibendum nibh. Donec lectus orci, sagittis in consequat\n"+ + "Donec ut dolor et nulla tristique varius. In nulla magna, fermentum\n"+ + "in lorem. Maecenas in ipsum ac justo scelerisque sollicitudin.\n"+ + "\n"+ + "Lyford’s in Texas & L’Anse-aux-Griffons in Québec;\n"+ + "Kwikpak on the Yukon delta, Kvæven in Norway, Kyulu in Kenya, not Rwanda.…\n"+ + "Ytterbium in the periodic table. Are Toussaint L’Ouverture, Wölfflin, Wolfe,\n"+ + "\n"+ + "The quick brown fox jumps over the lazy dog\n"; + + /** + * @param renderModes + */ + public UISceneDemo20(final int renderModes) { + this(null, null, renderModes, false, false); + } + + /** + * @param filmURL TODO + * @param renderModes + * @param debug + * @param trace + */ + public UISceneDemo20(final String fontfilename, final String filmURL, final int renderModes, final boolean debug, final boolean trace) { + this(fontfilename, filmURL, 0f, renderModes, debug, trace); + } + + /** + * @param filmURL TODO + * @param noAADPIThreshold see {@link #DefaultNoAADPIThreshold} + * @param debug + * @param trace + */ + public UISceneDemo20(final String fontfilename, final String filmURL, final float noAADPIThreshold, final boolean debug, final boolean trace) { + this(fontfilename, filmURL, noAADPIThreshold, 0, debug, trace); + } + + private UISceneDemo20(final String fontfilename, final String filmURL, final float noAADPIThreshold, final int renderModes, final boolean debug, final boolean trace) { + this.noAADPIThreshold = noAADPIThreshold; + this.debug = debug; + this.trace = trace; + + this.renderModes = renderModes; + + try { + if( null == fontfilename ) { + font = FontFactory.get(IOUtil.getResource("fonts/freefont/FreeSerif.ttf", + FontSetDemos.class.getClassLoader(), FontSetDemos.class).getInputStream(), true); + } else { + font = FontFactory.get( new File( fontfilename ) ); + } + System.err.println("Font "+font.getFullFamilyName()); + + fontFPS = FontFactory.get(IOUtil.getResource("fonts/freefont/FreeMonoBold.ttf", + FontSetDemos.class.getClassLoader(), FontSetDemos.class).getInputStream(), true); + System.err.println("Font FPS "+fontFPS.getFullFamilyName()); + + } catch (final IOException ioe) { + throw new RuntimeException(ioe); + } + try { + this.filmURL = Uri.cast( null != filmURL ? filmURL : defaultMediaURL ); + } catch (final URISyntaxException e1) { + throw new RuntimeException(e1); + } + scene = new Scene(); + scene.setPMVMatrixSetup(new MyPMVMatrixSetup()); + scene.getRenderState().setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED); + // scene.setSampleCount(3); // easy on embedded devices w/ just 3 samples (default is 4)? + + screenshot = new GLReadBufferUtil(false, false); + } + + private void rotateButtons(float[] angdeg) { + angdeg = VectorUtil.scaleVec3(angdeg, angdeg, FloatUtil.PI / 180.0f); + for(int i=0; i0); + button.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + cDrawable.invoke(false, new GLRunnable() { + @Override + public boolean run(final GLAutoDrawable drawable) { + final GL gl = drawable.getGL(); + gl.setSwapInterval(gl.getSwapInterval()<=0?1:0); + final GLAnimatorControl a = drawable.getAnimator(); + if( null != a ) { + a.resetFPSCounter(); + } + return true; + } + }); + } } ); + button.addMouseListener(dragZoomRotateListener); + buttons.add(button); + + button = new Button(renderModes, font, "< Tilt >", buttonXSize, buttonYSize); + button.move(xStartLeft,yStartTop - diffY*buttons.size(), 0f); + button.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); + if( shapeEvent.objPos[0] < shapeEvent.shape.getBounds().getCenter()[0] ) { + rotateButtons(new float[] { 0f, -5f, 0f}); // left-half pressed + } else { + rotateButtons(new float[] { 0f, 5f, 0f}); // right-half pressed + } + } + @Override + public void mouseWheelMoved(final MouseEvent e) { + rotateButtons(new float[] { 0f, e.getRotation()[1], 0f}); + } } ); + buttons.add(button); + + if( pass2Mode ) { // second column to the left + button = new Button(renderModes, font, "< Samples >", buttonXSize, buttonYSize); + button.move(xStartLeft,yStartTop - diffY*buttons.size(), 0f); + button.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); + int sampleCount = scene.getSampleCount(); + if( shapeEvent.objPos[0] < shapeEvent.shape.getBounds().getCenter()[0] ) { + // left-half pressed + sampleCount--; + } else { + // right-half pressed + sampleCount++; + } + sampleCount = scene.setSampleCount(sampleCount); // validated / clipped + } } ); + button.addMouseListener(dragZoomRotateListener); + buttons.add(button); + + button = new Button(renderModes, font, "< Quality >", buttonXSize, buttonYSize); + button.move(xStartLeft,yStartTop - diffY*buttons.size(), 0f); + button.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); + int quality = shapeEvent.shape.getQuality(); + + if( shapeEvent.objPos[0] < shapeEvent.shape.getBounds().getCenter()[0] ) { + // left-half pressed + if( quality > 0 ) { + quality--; + } + } else { + // right-half pressed + if( quality < Region.MAX_QUALITY ) { + quality++; + } + } + scene.setAllShapesQuality(quality); + } } ); + button.addMouseListener(dragZoomRotateListener); + buttons.add(button); + } + + button = new Button(renderModes, font, "Quit", buttonXSize, buttonYSize); + button.setName(BUTTON_QUIT); + button.move(xStartLeft,yStartTop - diffY*buttons.size(), 0f); + button.setColor(0.7f, 0.0f, 0.0f, 1.0f); + button.setLabelColor(1.2f, 1.2f, 1.2f); + button.setPressedColorMod(1.1f, 0.0f, 0.0f, 1.0f); + button.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + new InterruptSource.Thread() { + @Override + public void run() { + if( null != cDrawable ) { + final GLAnimatorControl actrl = cDrawable.getAnimator(); + if( null != actrl ) { + actrl.stop(); + } + cDrawable.destroy(); + } + } }.start(); + } } ); + button.addMouseListener(dragZoomRotateListener); + buttons.add(button); + + // second column to the left + { + final int j = 1; // column + int k = 0; // row + button = new Button(renderModes, font, "Y Flip", buttonXSize, buttonYSize); + button.move(xStartLeft - diffX*j,yStartTop - diffY*k, 0f); + button.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + rotateButtons(new float[] { 0f, 180f, 0f}); + } } ); + button.addMouseListener(dragZoomRotateListener); + buttons.add(button); + + k++; + button = new Button(renderModes, font, "X Flip", buttonXSize, buttonYSize); + button.move(xStartLeft - diffX*j,yStartTop - diffY*k, 0f); + button.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + rotateButtons(new float[] { 180f, 0f, 0f}); + } } ); + button.addMouseListener(dragZoomRotateListener); + buttons.add(button); + k++; + + button = new Button(renderModes, font, "< Space >", buttonXSize, buttonYSize); + button.move(xStartLeft - diffX*j,yStartTop - diffY*k, 0f); + button.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); + final float dx, dy; + if( shapeEvent.objPos[0] < shapeEvent.shape.getBounds().getCenter()[0] ) { + dx=-0.01f; dy=-0.005f; + } else { + dx=0.01f; dy=0.005f; + } + setButtonsSpacing(dx, dy); + } + @Override + public void mouseWheelMoved(final MouseEvent e) { + setButtonsSpacing(e.getRotation()[0]/100f, e.getRotation()[1]/200f); + } } ); + buttons.add(button); + k++; + + button = new Button(renderModes, font, "< Corner >", buttonXSize, buttonYSize); + button.move(xStartLeft - diffX*j,yStartTop - diffY*k, 0f); + button.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment(); + final float dc; + if( shapeEvent.objPos[0] < shapeEvent.shape.getBounds().getCenter()[0] ) { + dc=-0.1f; + } else { + dc=0.1f; + } + setButtonsCorner(dc); + } + @Override + public void mouseWheelMoved(final MouseEvent e) { + setButtonsCorner(e.getRotation()[1]/20f); + } } ); + buttons.add(button); + k++; + + button = new Button(renderModes, font, "Reset", buttonXSize, buttonYSize); + button.move(xStartLeft - diffX*j,yStartTop - diffY*k, 0f); + button.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + resetButtons(); + } } ); + button.addMouseListener(dragZoomRotateListener); + buttons.add(button); + k++; + + button = new Button(renderModes, font, "Snapshot", buttonXSize, buttonYSize); + button.move(xStartLeft - diffX*j,yStartTop - diffY*k, 0f); + button.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + cDrawable.invoke(false, new GLRunnable() { + @Override + public boolean run(final GLAutoDrawable drawable) { + printScreen(drawable.getGL()); + return true; + } + }); + } } ); + button.addMouseListener(dragZoomRotateListener); + buttons.add(button); + k++; + } + + buttonsLeftCount = buttons.size(); + + final int texUnitMediaPlayer, texUnitImageButton, texUnitGLELButton; + { + // works - but not required .. + texUnitMediaPlayer=1; + texUnitImageButton=2; + texUnitGLELButton=3; + } + + if( true ) { + final GLMediaPlayer mPlayer = GLMediaPlayerFactory.createDefault(); + mPlayer.setTextureUnit(texUnitMediaPlayer); + final MediaButton mPlayerButton = new MediaButton(renderModes, button2XSize, + button2YSize, mPlayer); + mPlayerButton.setName(BUTTON_MOVIE); + mPlayerButton.setVerbose(false); + mPlayerButton.addDefaultEventListener(); + mPlayerButton.move(xStartRight, yStartTop - diffY*1, 0f); + mPlayerButton.setToggleable(true); + mPlayerButton.setToggle(true); // toggle == false -> mute audio + mPlayerButton.setToggleOffColorMod(0f, 1f, 0f, 1.0f); + mPlayerButton.addMouseListener(dragZoomRotateListener); + mPlayerButton.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + mPlayer.setAudioVolume( mPlayerButton.isToggleOn() ? 1f : 0f ); + } } ); + buttons.add(mPlayerButton); + mPlayer.playStream(filmURL, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.TEXTURE_COUNT_DEFAULT); + } + if( true ) { + final ImageSequence imgSeq = new ImageSequence(texUnitImageButton, true); + final ImageButton imgButton = new ImageButton(renderModes, button2XSize, + button2YSize, imgSeq); + try { + imgSeq.addFrame(gl, UISceneDemo20.class, "button-released-145x53.png", TextureIO.PNG); + imgSeq.addFrame(gl, UISceneDemo20.class, "button-pressed-145x53.png", TextureIO.PNG); + } catch (final IOException e2) { + e2.printStackTrace(); + } + imgSeq.setManualStepping(true); + imgButton.move(xStartRight, yStartTop - diffY*2.5f, 0f); + imgButton.addMouseListener(dragZoomRotateListener); + imgButton.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mousePressed(final MouseEvent e) { + imgButton.setCurrentIdx(1); + System.err.println("XXX: "+imgButton); + } + @Override + public void mouseReleased(final MouseEvent e) { + imgButton.setCurrentIdx(0); + } } ); + buttons.add(imgButton); + } + if( true ) { + // Issues w/ OSX and NewtCanvasAWT when rendering / animating + // Probably related to CALayer - FBO - FBO* (of this button) + final GearsES2 gears = new GearsES2(0); + gears.setVerbose(false); + gears.setClearColor(new float[] { 0.9f, 0.9f, 0.9f, 1f } ); + final boolean[] animate = { true }; + new Thread(new Runnable() { + @Override + public void run() { + System.err.println("Gears Anim: Waiting"); + try { + gears.waitForInit(true); + } catch (final InterruptedException e) { } + System.err.println("Gears Anim: Started"); + while( gears.isInit() ) { + if( animate[0] ) { + final float ry = ( gears.getRotY() + 1 ) % 360; + gears.setRotY(ry); + } + try { + Thread.sleep(15); + } catch (final InterruptedException e) { } + } + System.err.println("Gears Anim: End"); + } + }).start(); + final GLButton b = new GLButton(renderModes, button2XSize, + button2YSize, texUnitGLELButton, + gears, false /* useAlpha */); + b.setName(BUTTON_GLEL); + b.setToggleable(true); + b.setToggle(false); // toggle == true -> animation + b.setAnimate(false); + b.move(xStartRight, yStartTop - diffY*4f, 0f); + b.addMouseListener(dragZoomRotateListener); + b.addMouseListener(new Shape.MouseGestureAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + b.setAnimate( b.isToggleOn() ); + animate[0] = b.getAnimate(); + } } ); + buttons.add(b); + } + } + + private void initTexts() { + strings = new String[4]; + int i = 0; + + strings[i++] = "- Mouse Scroll Over Object\n"+ + " - General\n"+ + " - X-Rotation\n"+ + " - Shift: Y-Rotation\n"+ + " - Tilt, Space and Corner\n"+ + " - Their respective action via wheel\n"+ + " (shift = other value)\n"+ + "\n"+ + "- Mouse Drag On Object\n"+ + " - Click on Object and drag mouse\n"+ + " - Current postion in status line at bottom\n"+ + " - Resize when click on 1/4 bottom-left or bottom-right corner.\n"+ + "\n"+ + "- Tilt Button Rotate Whole Button Group"; + + strings[i++] = "abcdefghijklmn\nopqrstuvwxyz\n"+ + "ABCDEFGHIJKL\n"+ + "MNOPQRSTUVWXYZ\n"+ + "0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]"; + + strings[i++] = "The quick brown fox jumps over the lazy dog"; + + strings[i++] = longText; + + labels = new Label[i]; + + currentText = strings.length - 1; + } + + + private static final boolean enableOthers = true; + + + private void setupUI(final GLAutoDrawable drawable, final AABBox sceneBox) { + final float[/*2*/] sceneSize = { 0f, 0f }; + scene.surfaceToPlaneSize(new int[] { 0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight()}, sceneSize); + + final float modelSizeFixed = fontSizeFixedNorm * sceneSize[1]; + jogampLabel = new Label(renderModes, font, modelSizeFixed, jogamp); + jogampLabel.addMouseListener(dragZoomRotateListener); + scene.addShape(jogampLabel); + jogampLabel.setEnabled(enableOthers); + + final float pixelSize10Pt = FontScale.toPixels(fontSizePt, dpiV); + final float modelSize10Pt = pixelSize10Pt / drawable.getSurfaceHeight() * sceneSize[1]; + System.err.println("10Pt PixelSize: Display "+dpiV+" dpi, fontSize "+fontSizePt+" ppi -> "+pixelSize10Pt+" pixe-size, "+modelSize10Pt+" model-size"); + truePtSizeLabel = new Label(renderModes, font, modelSize10Pt, truePtSize); + scene.addShape(truePtSizeLabel); + truePtSizeLabel.setEnabled(enableOthers); + truePtSizeLabel.move(0, - 1.5f * jogampLabel.getLineHeight(), 0f); + truePtSizeLabel.setColor(0.1f, 0.1f, 0.1f, 1.0f); + + /** + * + * [Label] Display 112.88889 dpi, fontSize 12.0 ppi -> pixelSize 18.814816 + * [FPS] Display 112.88889 dpi, fontSize 12.0 ppi -> pixelSize 15.679012 + */ + final float pixelSizeFPS = fontSizeFpsNorm * drawable.getSurfaceHeight(); + final float modelSizeFPS = pixelSizeFPS / drawable.getSurfaceHeight() * sceneSize[1]; + fpsLabel = new Label(renderModes, fontFPS, modelSizeFPS, "Nothing there yet"); + fpsLabel.addMouseListener(dragZoomRotateListener); + scene.addShape(fpsLabel); + fpsLabel.setEnabled(enableOthers); + fpsLabel.setColor(0.1f, 0.1f, 0.1f, 1.0f); + fpsLabel.move(0f, modelSizeFPS * (fontFPS.getMetrics().getLineGap() - fontFPS.getMetrics().getDescent()), 0f); + + final float sx = sceneBox.getWidth(); + final float sy = sceneBox.getHeight(); + final float sxy = sx > sy ? sx : sy; + initButtons(drawable.getGL().getGL2ES2(), sxy); + scene.addShapes(buttons); + } + + @Override + public void init(final GLAutoDrawable drawable) { + final Object upObj = drawable.getUpstreamWidget(); + if( upObj instanceof Window ) { + final Window upWin = (Window)upObj; + final MonitorDevice monitor = upWin.getMainMonitor(); + final float[] monitorDPI = MonitorDevice.perMMToPerInch( monitor.getPixelsPerMM(new float[2]) ); + final float[] sDPI = MonitorDevice.perMMToPerInch( upWin.getPixelsPerMM(new float[2]) ); + dpiV = sDPI[1]; + System.err.println("Monitor detected: "+monitor); + System.err.println("Monitor dpi: "+monitorDPI[0]+" x "+monitorDPI[1]); + System.err.println("Surface scale: native "+Arrays.toString(upWin.getMaximumSurfaceScale(new float[2]))+", current "+Arrays.toString(upWin.getCurrentSurfaceScale(new float[2]))); + System.err.println("Surface dpi "+sDPI[0]+" x "+sDPI[1]); + } else { + System.err.println("Using default DPI of "+dpiV); + } + if( 0 == renderModes && !FloatUtil.isZero(noAADPIThreshold, FloatUtil.EPSILON)) { + final boolean noAA = dpiV >= noAADPIThreshold; + final String noAAs = noAA ? " >= " : " < "; + System.err.println("AUTO RenderMode: dpi "+dpiV+noAAs+noAADPIThreshold+" -> noAA "+noAA); + renderModes = noAA ? 0 : Region.VBAA_RENDERING_BIT; + } + if(drawable instanceof GLWindow) { + System.err.println("GPUUISceneGLListener0A: init (1)"); + final GLWindow glw = (GLWindow) drawable; + scene.attachInputListenerTo(glw); + } else { + System.err.println("GPUUISceneGLListener0A: init (0)"); + } + cDrawable = 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(); + } + System.err.println(JoglVersion.getGLInfo(gl, null, false /* withCapsAndExts */).toString()); + System.err.println("VSync Swap Interval: "+gl.getSwapInterval()); + System.err.println("Chosen: "+drawable.getChosenGLCapabilities()); + MSAATool.dump(drawable); + + gl.setSwapInterval(1); + gl.glEnable(GL.GL_DEPTH_TEST); + gl.glEnable(GL.GL_BLEND); + + initTexts(); + + scene.init(drawable); + + final GLAnimatorControl a = drawable.getAnimator(); + if( null != a ) { + a.resetFPSCounter(); + } + } + + @Override + public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { + System.err.println("GPUUISceneGLListener0A: reshape"); + + // + // Layout all shapes: Relational move regarding object coordinates + // + System.err.println("Reshape: Scene Plane.0 "+scene.getBounds()); + final float lastWidth = scene.getBounds().getWidth(); + final float lastHeight = scene.getBounds().getHeight(); + System.err.println("Reshape: Scene Plane.0 "+lastWidth+" x "+lastHeight); + + scene.reshape(drawable, x, y, width, height); + final AABBox sceneBox = scene.getBounds(); + System.err.println("Reshape: Scene Plane.1 "+sceneBox); + + if( scene.getShapes().isEmpty() ) { + setupUI(drawable, sceneBox); + } + + final float dw = sceneBox.getWidth() - lastWidth; + final float dh = sceneBox.getHeight() - lastHeight; + + final float dz = 0f; + final float dyTop = dh * relTop; + final float dxLeft = dw * relLeft; + final float dxRight = dw; + + System.err.println("XXX: dw "+dw+", dh "+dh+", dxLeft "+dxLeft+", dxRight "+dxRight+", dyTop "+dyTop); + + for(int i=0; i