28package com.jogamp.opengl.demos.graph.ui;
31import java.io.IOException;
32import java.net.URISyntaxException;
33import java.util.ArrayList;
34import java.util.Arrays;
36import java.util.Locale;
38import com.jogamp.common.av.AudioSink;
39import com.jogamp.common.net.Uri;
40import com.jogamp.common.util.IOUtil;
41import com.jogamp.common.util.VersionUtil;
42import com.jogamp.graph.curve.Region;
43import com.jogamp.graph.curve.opengl.RegionRenderer;
44import com.jogamp.graph.curve.opengl.RenderState;
45import com.jogamp.graph.font.Font;
46import com.jogamp.graph.font.FontFactory;
47import com.jogamp.graph.font.FontScale;
48import com.jogamp.graph.ui.GraphShape;
49import com.jogamp.graph.ui.Group;
50import com.jogamp.graph.ui.Scene;
51import com.jogamp.graph.ui.Shape;
52import com.jogamp.graph.ui.layout.Alignment;
53import com.jogamp.graph.ui.layout.Gap;
54import com.jogamp.graph.ui.layout.GridLayout;
55import com.jogamp.graph.ui.shapes.Button;
56import com.jogamp.graph.ui.shapes.GLButton;
57import com.jogamp.graph.ui.shapes.ImageButton;
58import com.jogamp.graph.ui.shapes.Label;
59import com.jogamp.graph.ui.shapes.MediaButton;
60import com.jogamp.math.FloatUtil;
61import com.jogamp.math.Vec2f;
62import com.jogamp.math.Vec3f;
63import com.jogamp.math.geom.AABBox;
64import com.jogamp.math.util.PMVMatrix4f;
65import com.jogamp.graph.ui.shapes.BaseButton;
66import com.jogamp.nativewindow.ScalableSurface;
67import com.jogamp.newt.Display;
68import com.jogamp.newt.MonitorDevice;
69import com.jogamp.newt.NewtFactory;
70import com.jogamp.newt.Screen;
71import com.jogamp.newt.Window;
72import com.jogamp.newt.event.MouseEvent;
73import com.jogamp.newt.event.WindowAdapter;
74import com.jogamp.newt.event.WindowEvent;
75import com.jogamp.newt.opengl.GLWindow;
76import com.jogamp.openal.sound3d.AudioSystem3D;
77import com.jogamp.openal.util.ALAudioSink;
78import com.jogamp.openal.util.SimpleSineSynth;
79import com.jogamp.opengl.GL;
80import com.jogamp.opengl.GL2ES2;
81import com.jogamp.opengl.GLAnimatorControl;
82import com.jogamp.opengl.GLAutoDrawable;
83import com.jogamp.opengl.GLCapabilities;
84import com.jogamp.opengl.GLEventListener;
85import com.jogamp.opengl.GLPipelineFactory;
86import com.jogamp.opengl.GLRunnable;
87import com.jogamp.opengl.JoglVersion;
88import com.jogamp.opengl.demos.es2.GearsES2;
89import com.jogamp.opengl.demos.graph.FontSetDemos;
90import com.jogamp.opengl.demos.graph.MSAATool;
91import com.jogamp.opengl.demos.util.CommandlineOptions;
92import com.jogamp.opengl.demos.util.MiscUtils;
93import com.jogamp.opengl.util.Animator;
94import com.jogamp.opengl.util.av.GLMediaPlayer;
95import com.jogamp.opengl.util.av.GLMediaPlayer.EventMask;
96import com.jogamp.opengl.util.av.GLMediaPlayer.GLMediaEventListener;
97import com.jogamp.opengl.util.av.GLMediaPlayerFactory;
98import com.jogamp.opengl.util.caps.NonFSAAGLCapsChooser;
99import com.jogamp.opengl.util.texture.ImageSequence;
100import com.jogamp.opengl.util.texture.TextureIO;
102import jogamp.graph.ui.TreeTool;
117 static final boolean DEBUG =
false;
118 static final boolean TRACE =
false;
122 public static void main(
final String[] args) {
125 String fontfilename =
null;
126 String filmURL =
null;
128 if( 0 != args.length ) {
129 final int[] idx = { 0 };
130 for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
131 if( options.
parse(args, idx) ) {
133 }
else if(args[idx[0]].equals(
"-font")) {
135 fontfilename = args[idx[0]];
136 }
else if(args[idx[0]].equals(
"-pixelScale")) {
138 final float pS =
MiscUtils.
atof(args[idx[0]], reqSurfacePixelScale[0]);
139 reqSurfacePixelScale[0] = pS;
140 reqSurfacePixelScale[1] = pS;
141 }
else if(args[idx[0]].equals(
"-film") || args[idx[0]].equals(
"-file")) {
143 filmURL = args[idx[0]];
147 System.err.println(options);
151 System.err.println(VersionUtil.getPlatformInfo());
155 System.out.println(
"Requested: " + caps);
175 animator.
add(window);
189 static private final String defaultMediaURL =
"https://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4";
191 private boolean debug =
false;
192 private boolean trace =
false;
194 private final Scene scene;
196 private final Font font;
197 private final Font fontButtons;
198 private final Font fontSymbols;
199 private final Font fontFPS;
200 private final Uri filmURL;
202 private final float relTop = 90f/100f;
203 private final float relMiddle = 22f/100f;
206 private static final float buttonXSizeNorm = 0.09f;
207 private static final float fontSizePt = 10f;
209 private static final float fontSizeFixedNorm = 0.04f;
210 private float dpiV = 96;
212 private int currentText = 0;
214 private String actionText =
null;
215 private Label[] labels =
null;
216 private String[] strings =
null;
219 private Label truePtSizeLabel =
null;
220 private Label jogampLabel =
null;
221 private Label fpsLabel =
null;
225 private final String jogamp =
"JogAmp - Jogl Graph Module Demo";
226 private final String truePtSize = fontSizePt+
" pt font size label - true scale!";
228 private final String longText =
"JOGL: Java™ Binding for the OpenGL® API.\n\n"+
229 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec \n"+
230 "Ut purus odio, rhoncus sit amet commodo eget, ullamcorper vel\n"+
231 "quam iaculis urna cursus ornare. Nullam ut felis a ante ultrices\n"+
232 "In hac habitasse platea dictumst. Vivamus et mi a quam lacinia\n"+
233 "Morbi quis bibendum nibh. Donec lectus orci, sagittis in consequat\n"+
234 "Donec ut dolor et nulla tristique varius. In nulla magna, fermentum\n"+
235 "in lorem. Maecenas in ipsum ac justo scelerisque sollicitudin.\n"+
237 "Lyford’s in Texas & L’Anse-aux-Griffons in Québec;\n"+
238 "Kwikpak on the Yukon delta, Kvæven in Norway, Kyulu in Kenya, not Rwanda.…\n"+
239 "Ytterbium in the periodic table. Are Toussaint L’Ouverture, Wölfflin, Wolfe,\n"+
241 "The quick brown fox jumps over the lazy dog\n";
256 public UISceneDemo20(
final String fontfilename,
final String filmURL,
final int renderModes,
final boolean debug,
final boolean trace) {
257 this(fontfilename, filmURL, options.
noAADPIThreshold, renderModes, debug, trace);
266 public UISceneDemo20(
final String fontfilename,
final String filmURL,
final float noAADPIThreshold,
final boolean debug,
final boolean trace) {
267 this(fontfilename, filmURL, noAADPIThreshold, 0, debug, trace);
270 private UISceneDemo20(
final String fontfilename,
final String filmURL,
final float noAADPIThreshold,
final int renderModes,
final boolean debug,
final boolean trace) {
271 options.noAADPIThreshold = noAADPIThreshold;
275 UISceneDemo20.options.renderModes = renderModes;
278 if(
null == fontfilename ) {
279 font =
FontFactory.
get(IOUtil.getResource(
"fonts/freefont/FreeSerif.ttf",
286 fontButtons = FontFactory.get(FontFactory.UBUNTU).getDefault();
287 fontSymbols = FontFactory.get(FontFactory.SYMBOLS).getDefault();
288 fontFPS = FontFactory.get(IOUtil.getResource(
"fonts/freefont/FreeMono.ttf",
289 FontSetDemos.class.getClassLoader(), FontSetDemos.class).getInputStream(),
true);
292 }
catch (
final IOException ioe) {
293 throw new RuntimeException(ioe);
296 this.filmURL = Uri.cast(
null != filmURL ? filmURL : defaultMediaURL );
297 }
catch (
final URISyntaxException e1) {
298 throw new RuntimeException(e1);
308 private void rotateButtons(
final Vec3f angdeg) {
309 angdeg.scale(FloatUtil.PI / 180.0f);
310 final List<Shape> sl =
new ArrayList<Shape>();
313 for(
final Shape s : sl) {
314 s.setRotation( s.getRotation().rotateByEuler( angdeg ) );
318 private void setButtonsSpacing(
final float dx,
final float dy) {
319 final List<Shape> sl =
new ArrayList<Shape>();
322 for(
final Shape s : sl) {
323 if( s instanceof Button ) {
324 final Button lb = (Button) s;
325 final float sx = lb.getSpacing().x()+dx, sy = lb.getSpacing().y()+dy;
326 System.err.println(
"Spacing: X "+sx+
", Y "+sy);
327 lb.setSpacing(sx, sy);
332 private void setButtonsCorner(
final float dc) {
333 final List<Shape> sl =
new ArrayList<Shape>();
336 for(
final Shape s : sl) {
337 if( s instanceof BaseButton ) {
338 final BaseButton rb = (BaseButton)s;
339 final float c = rb.getCorner()+dc;
340 System.err.println(
"Corner: "+c);
346 private void resetButtons() {
347 final List<Shape> sl =
new ArrayList<Shape>();
350 for(
final Shape s : sl) {
351 if( s instanceof BaseButton ) {
352 final BaseButton b = (BaseButton)s;
353 b.setRotation( b.getRotation().setIdentity() );
354 b.setCorner(BaseButton.ROUND_CORNER);
355 if( b instanceof Button ) {
356 ((Button)b).setSpacing(Button.DEFAULT_SPACING_X, Button.DEFAULT_SPACING_Y);
373 private void initSound(
final Shape shape,
374 final com.jogamp.openal.sound3d.Context context,
375 final com.jogamp.openal.sound3d.Source aSource)
377 final com.jogamp.openal.sound3d.Listener audioListener = AudioSystem3D.getListener();
378 context.makeCurrent(
true);
381 f3x2 = audioListener.getOrientation();
382 System.err.printf(
"Listener init orientation: at[%.3f %.3f %.3f], up[%.3f %.3f %.3f]%n",
383 f3x2[0], f3x2[1], f3x2[2], f3x2[3], f3x2[4], f3x2[5]);
384 f3x2 =
new float[]{ 0f, 0f, -1f, 0f, 1f, 0f };
385 audioListener.setOrientation(f3x2);
386 f3x2 = audioListener.getOrientation();
387 System.err.printf(
"Listener set orientation: at[%.3f %.3f %.3f], up[%.3f %.3f %.3f]%n",
388 f3x2[0], f3x2[1], f3x2[2], f3x2[3], f3x2[4], f3x2[5]);
390 com.jogamp.openal.sound3d.Vec3f ap = audioListener.
getPosition();
391 System.err.printf(
"Listener init pos: %.3f %.3f %.3f%n", ap.v1, ap.v2, ap.v3);
392 audioListener.setPosition(0, 0, -0.25f);
393 ap = audioListener.getPosition();
394 System.err.printf(
"Listener set pos: %.3f %.3f %.3f%n", ap.v1, ap.v2, ap.v3);
396 System.err.printf(
"Source init rel: %b%n", aSource.isSourceRelative());
397 aSource.setSourceRelative(
false);
398 System.err.printf(
"Source set rel: %b%n", aSource.isSourceRelative());
400 ap = aSource.getDirection();
401 System.err.printf(
"Source init dir: %.3f %.3f %.3f%n", ap.v1, ap.v2, ap.v3);
403 final float rollOff0 = aSource.getRolloffFactor();
404 System.err.printf(
"Source init rollOff: %.3f%n", rollOff0);
406 final float refDist0 = aSource.getReferenceDistance();
407 aSource.setReferenceDistance(0.75f);
408 final float refDist1 = aSource.getReferenceDistance();
409 System.err.printf(
"Source ref-dist: %.3f -> %.3f%n", refDist0, refDist1);
411 ap = aSource.getPosition();
412 System.err.printf(
"Source init pos: %.3f %.3f %.3f%n", ap.v1, ap.v2, ap.v3);
413 AudioSystem3D.checkError(context.getDevice(),
"setup",
true,
false);
415 setSoundPosition(shape, context, aSource);
417 context.release(
true);
421 private void setSoundPosition(
final Shape shape,
422 final com.jogamp.openal.sound3d.Context context,
423 final com.jogamp.openal.sound3d.Source aSource) {
426 final PMVMatrix4f pmv =
new PMVMatrix4f();
427 worldBounds = scene.
getBounds(pmv, shape);
429 context.makeCurrent(
true);
431 aSource.setPosition(worldBounds.getCenter().x(), worldBounds.getCenter().y(), worldBounds.getCenter().z());
432 System.err.println(
"Source pos: "+worldBounds.getCenter());
434 context.release(
true);
438 private static void setSineSoundLabel(
final Button shape,
final float freq,
final float amp) {
440 if( shape.isToggleOn() ) {
441 s = String.format(
"scroll %.0f Hz\nctrl-scroll %.2f amp\nmove spatial", freq, amp);
442 shape.setSpacing(0.05f, 0.20f);
444 s = String.format(
"click to enable\nf %.0f Hz, a %.2f", freq, amp);
445 shape.setSpacing(Button.DEFAULT_SPACING_X, Button.DEFAULT_SPACING_Y);
451 private void initButtons(
final GL2ES2 gl) {
452 final boolean pass2Mode = Region.isTwoPass( options.
renderModes ) ;
456 final float buttonLWidth = buttonXSizeNorm;
457 final float buttonLHeight = buttonLWidth / 2.5f;
458 buttonsLeft.
setLayout(
new GridLayout(buttonLWidth, buttonLHeight, Alignment.Fill,
new Gap(buttonLHeight*0.50f, buttonLWidth*0.10f), 7));
460 final float buttonRWidth = 2f*buttonLWidth;
461 final float buttonRHeight = 2f*buttonLHeight;
463 buttonsRight.
setLayout(
new GridLayout(1, buttonRWidth, buttonRHeight, Alignment.Fill,
new Gap(buttonLHeight*0.50f, buttonLWidth*0.10f)));
465 System.err.println(
"Button Size: "+buttonLWidth+
" x "+buttonLHeight);
466 final Vec2f fixedSymSize =
new Vec2f(0.0f, 1.0f);
467 final Vec2f symSpacing =
new Vec2f(0f, 0.2f);
470 button =
new Button(options.
renderModes, fontSymbols, fontSymbols.
getUTF16String(
"fast_forward"), buttonLWidth, buttonLHeight);
471 ((Button)button).setSpacing(symSpacing, fixedSymSize);
473 button.addMouseListener(
new Shape.MouseGestureAdapter() {
475 public void mouseClicked(
final MouseEvent e) {
476 if(
null != labels[currentText] ) {
479 currentText = (currentText+1)%labels.length;
480 if(
null != labels[currentText] ) {
484 button.addMouseListener(dragZoomRotateListener);
487 button =
new Button(options.
renderModes, fontButtons,
"Show fps",
"Hide fps", buttonLWidth, buttonLHeight, Button.DEFAULT_LABEL_ZOFFSET);
489 button.setToggleable(
true);
491 button.addMouseListener(
new Shape.MouseGestureAdapter() {
493 public void mouseClicked(final MouseEvent e) {
494 final GLAnimatorControl a = cDrawable.getAnimator();
498 fpsLabel.setVisible(!fpsLabel.isVisible());
500 button.addMouseListener(dragZoomRotateListener);
503 button =
new Button(options.
renderModes, fontButtons,
" V-Sync ", buttonLWidth, buttonLHeight);
505 button.setToggleable(
true);
506 button.setToggle(gl.getSwapInterval()>0);
507 button.addMouseListener(
new Shape.MouseGestureAdapter() {
509 public void mouseClicked(final MouseEvent e) {
510 cDrawable.invoke(false, new GLRunnable() {
512 public boolean run(final GLAutoDrawable drawable) {
513 final GL gl = drawable.getGL();
514 gl.setSwapInterval(gl.getSwapInterval()<=0?1:0);
515 final GLAnimatorControl a = drawable.getAnimator();
523 button.addMouseListener(dragZoomRotateListener);
526 button =
new Button(options.
renderModes, fontButtons,
" < Tilt > ", buttonLWidth, buttonLHeight);
527 button.addMouseListener(
new Shape.MouseGestureAdapter() {
529 public void mouseClicked(final MouseEvent e) {
530 final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment();
531 if( shapeEvent.objPos.x() < shapeEvent.shape.getBounds().getCenter().x() ) {
532 rotateButtons(new Vec3f( 0f, -5f, 0f ) );
534 rotateButtons(new Vec3f( 0f, 5f, 0f ) );
538 public void mouseWheelMoved(
final MouseEvent e) {
539 rotateButtons(
new Vec3f( 0f, e.getRotation()[1], 0f ) );
544 button =
new Button(options.
renderModes, fontButtons,
"< Samples >", buttonLWidth, buttonLHeight);
545 button.addMouseListener(
new Shape.MouseGestureAdapter() {
547 public void mouseClicked(final MouseEvent e) {
548 final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment();
549 int sampleCount = scene.getSampleCount();
550 if( shapeEvent.objPos.x() < shapeEvent.shape.getBounds().getCenter().x() ) {
557 sampleCount = scene.setSampleCount(sampleCount);
559 button.addMouseListener(dragZoomRotateListener);
562 button =
new Button(options.
renderModes, fontButtons,
"< Quality >", buttonLWidth, buttonLHeight);
563 button.addMouseListener(
new Shape.MouseGestureAdapter() {
565 public void mouseClicked(final MouseEvent e) {
566 final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment();
567 if( shapeEvent.shape instanceof GraphShape ) {
568 int quality = scene.getAAQuality();
569 if( shapeEvent.objPos.x() < shapeEvent.shape.getBounds().getCenter().x() ) {
576 scene.setAAQuality(quality);
579 button.addMouseListener(dragZoomRotateListener);
583 button =
new Button(options.
renderModes, fontSymbols, fontSymbols.
getUTF16String(
"power_settings_new"), buttonLWidth, buttonLHeight);
584 ((Button)button).setSpacing(symSpacing, fixedSymSize);
585 button.setID(BUTTON_QUIT);
586 button.setColor(0.7f, 0.3f, 0.3f, 1.0f);
587 ((Button)button).setLabelColor(1.2f, 1.2f, 1.2f, 1.0f);
588 button.setPressedColorMod(1.1f, 0.0f, 0.0f, 1.0f);
589 button.addMouseListener(
new Shape.MouseGestureAdapter() {
591 public void mouseClicked(
final MouseEvent e) {
592 MiscUtils.destroyWindow(cDrawable);
594 button.addMouseListener(dragZoomRotateListener);
600 ((Button)button).setSpacing(symSpacing, fixedSymSize);
601 button.addMouseListener(
new Shape.MouseGestureAdapter() {
603 public void mouseClicked(
final MouseEvent e) {
604 rotateButtons(
new Vec3f ( 0f, 180f, 0f ));
606 button.addMouseListener(dragZoomRotateListener);
609 button =
new Button(options.
renderModes, fontButtons,
" X Flip ", buttonLWidth, buttonLHeight);
610 button.addMouseListener(
new Shape.MouseGestureAdapter() {
612 public void mouseClicked(final MouseEvent e) {
613 rotateButtons(new Vec3f ( 180f, 0f, 0f ));
615 button.addMouseListener(dragZoomRotateListener);
618 button =
new Button(options.
renderModes, fontButtons,
"< Space >", buttonLWidth, buttonLHeight);
619 button.addMouseListener(
new Shape.MouseGestureAdapter() {
621 public void mouseClicked(final MouseEvent e) {
622 final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment();
624 if( shapeEvent.objPos.x() < shapeEvent.shape.getBounds().getCenter().x() ) {
625 dx=-0.01f; dy=-0.005f;
629 setButtonsSpacing(dx, dy);
632 public void mouseWheelMoved(
final MouseEvent e) {
633 setButtonsSpacing(e.getRotation()[0]/100f, e.getRotation()[1]/200f);
637 button =
new Button(options.
renderModes, fontButtons,
"< Corner >", buttonLWidth, buttonLHeight);
638 button.addMouseListener(
new Shape.MouseGestureAdapter() {
640 public void mouseClicked(final MouseEvent e) {
641 final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment();
643 if( shapeEvent.objPos.x() < shapeEvent.shape.getBounds().getCenter().x() ) {
648 setButtonsCorner(dc);
651 public void mouseWheelMoved(
final MouseEvent e) {
652 setButtonsCorner(e.getRotation()[1]/20f);
657 ((Button)button).setSpacing(symSpacing, fixedSymSize);
658 button.addMouseListener(
new Shape.MouseGestureAdapter() {
660 public void mouseClicked(
final MouseEvent e) {
663 button.addMouseListener(dragZoomRotateListener);
666 button =
new Button(options.
renderModes, fontSymbols, fontSymbols.
getUTF16String(
"camera"), buttonLWidth, buttonLHeight);
667 ((Button)button).setSpacing(symSpacing, fixedSymSize);
668 button.addMouseListener(
new Shape.MouseGestureAdapter() {
670 public void mouseClicked(
final MouseEvent e) {
671 scene.screenshot(
false, scene.
nextScreenshotFile(
null, UISceneDemo20.class.getSimpleName(), options.
renderModes, gl.getContext().getGLDrawable().getChosenGLCapabilities(),
null));
673 button.addMouseListener(dragZoomRotateListener);
680 final int texUnitMediaPlayer, texUnitImageButton, texUnitGLELButton;
683 texUnitMediaPlayer=1;
684 texUnitImageButton=2;
689 final GLMediaPlayer mPlayer = GLMediaPlayerFactory.createDefault();
690 mPlayer.setTextureUnit(texUnitMediaPlayer);
691 mPlayer.setAudioChannelLimit(1);
692 button =
new MediaButton(options.
renderModes, buttonRWidth, buttonRHeight, mPlayer);
693 button.setID(BUTTON_MOVIE);
694 ((MediaButton)button).setVerbose(
false).addDefaultEventListener().setFixedARatioResize(
true);
695 button.setToggleable(
true);
696 button.setToggle(
true);
697 button.setToggleOffColorMod(0f, 1f, 0f, 1.0f);
698 button.addMouseListener(dragZoomRotateListener);
700 button.onToggle( (
final Shape s) -> {
701 mPlayer.setAudioVolume( s.isToggleOn() ? 1f : 0f );
705 final ALAudioSink[] alAudioSink = {
null };
707 mPlayer.addEventListener(
new GLMediaEventListener() {
709 public void attributesChanged(
final GLMediaPlayer mp,
final EventMask eventMask,
final long when) {
710 System.err.println(
"MediaButton AttributesChanges: "+eventMask+
", when "+when);
711 System.err.println(
"MediaButton State: "+mp);
712 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) {
713 final AudioSink audioSink = mp.getAudioSink();
714 if( audioSink instanceof ALAudioSink ) {
715 alAudioSink[0] = (ALAudioSink)audioSink;
717 alAudioSink[0] =
null;
720 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) {
721 alAudioSink[0] =
null;
726 button.onMove((
final Shape shape,
final Vec3f origin,
final Vec3f dest,
final MouseEvent e) -> {
727 final ALAudioSink aSink = alAudioSink[0];
728 if(
null != aSink && aSink.getContext().isValid() ) {
729 setSoundPosition(shape, aSink.getContext(), aSink.getSource());
732 button.onDraw( (
final Shape shape,
final GL2ES2 gl_,
final RegionRenderer renderer_) -> {
733 final ALAudioSink aSink = alAudioSink[0];
734 if(
null != aSink && aSink.getContext().isValid() ) {
735 initSound(shape, aSink.getContext(), aSink.getSource());
736 System.err.println(
"Media Audio: "+aSink);
744 mPlayer.playStream(filmURL, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_NONE, GLMediaPlayer.TEXTURE_COUNT_DEFAULT);
747 final SimpleSineSynth sineSound =
new SimpleSineSynth();
752 sineSound.setFreq(200f);
753 sineSound.setAmplitude(0.1f);
754 final Button sineButton =
new Button(options.
renderModes, fontButtons,
"lala", buttonRWidth, buttonRHeight);
756 button.setToggleable(
true);
757 button.setToggle(
false);
758 setSineSoundLabel(sineButton, sineSound.getFreq(), sineSound.getAmplitude());
760 final ALAudioSink aSink = sineSound.getSink();
761 final com.jogamp.openal.sound3d.Source aSource = aSink.getSource();
763 button.addMouseListener(
new Shape.MouseGestureAdapter() {
765 public void mouseReleased(final MouseEvent e) {
770 public void mouseDragged(
final MouseEvent e) {
771 final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment();
772 if( e.getPointerCount() == 1 ) {
773 final AABBox worldBounds;
775 final PMVMatrix4f pmv =
new PMVMatrix4f();
776 worldBounds = scene.
getBounds(pmv, shapeEvent.shape);
778 actionText = String.format((Locale)
null,
"Pos %s", worldBounds.getCenter());
782 public void mouseClicked(
final MouseEvent e) {
783 final Shape.EventInfo info = (Shape.EventInfo)e.getAttachment();
784 if( info.shape.isToggleOn() ) {
789 setSineSoundLabel(sineButton, sineSound.getFreq(), sineSound.getAmplitude());
792 public void mouseWheelMoved(
final MouseEvent e) {
793 if( e.isControlDown() ) {
794 final float a1 = sineSound.getAmplitude() + + e.getRotation()[1] / 20f;
795 sineSound.setAmplitude(a1);
797 final float f1 = sineSound.getFreq() + e.getRotation()[1] * 10f;
798 sineSound.setFreq(f1);
800 setSineSoundLabel(sineButton, sineSound.getFreq(), sineSound.getAmplitude());
801 System.err.println(
"Sine "+sineSound);
804 button.onDraw( (
final Shape shape,
final GL2ES2 gl_,
final RegionRenderer renderer_) -> {
805 if(
null != aSink && aSink.getContext().isValid() ) {
806 initSound(shape, aSink.getContext(), aSource);
807 System.err.println(
"Sine Audio: "+aSink);
813 button.onMove( (
final Shape shape,
final Vec3f origin,
final Vec3f dest,
final MouseEvent e) -> {
814 setSoundPosition(shape, aSink.getContext(), aSource);
819 final ImageSequence imgSeq =
new ImageSequence(texUnitImageButton,
true);
820 button =
new ImageButton(options.
renderModes, buttonRWidth, buttonRHeight, imgSeq);
822 imgSeq.addFrame(gl, UISceneDemo20.class,
"button-released-145x53.png", TextureIO.PNG);
823 imgSeq.addFrame(gl, UISceneDemo20.class,
"button-pressed-145x53.png", TextureIO.PNG);
824 }
catch (
final IOException e2) {
825 e2.printStackTrace();
827 imgSeq.setManualStepping(
true);
828 button.addMouseListener(dragZoomRotateListener);
829 button.addMouseListener(
new Shape.MouseGestureAdapter() {
831 public void mousePressed(final MouseEvent e) {
832 final Shape.EventInfo info = (Shape.EventInfo)e.getAttachment();
833 final ImageButton s = (ImageButton)info.shape;
835 System.err.println(
"XXX: "+s);
838 public void mouseReleased(
final MouseEvent e) {
839 final Shape.EventInfo info = (Shape.EventInfo)e.getAttachment();
840 final ImageButton s = (ImageButton)info.shape;
848 final GearsES2 gears =
new GearsES2(0);
849 gears.setVerbose(
false);
850 gears.setClearColor(
new float[] { 0.9f, 0.9f, 0.9f, 1f } );
851 final boolean[] animate = {
true };
852 new Thread(
new Runnable() {
855 System.err.println(
"Gears Anim: Waiting");
857 gears.waitForInit(
true);
858 }
catch (
final InterruptedException e) { }
859 System.err.println(
"Gears Anim: Started");
860 while( gears.isInit() ) {
862 final float ry = ( gears.getRotY() + 1 ) % 360;
867 }
catch (
final InterruptedException e) { }
869 System.err.println(
"Gears Anim: End");
872 button =
new GLButton(options.
renderModes, buttonRWidth, buttonRHeight,
873 texUnitGLELButton, gears,
false );
874 button.setID(BUTTON_GLEL);
875 button.setToggleable(
true);
876 button.setToggle(
false);
877 ((GLButton)button).setAnimate(
false);
878 button.addMouseListener(dragZoomRotateListener);
879 button.addMouseListener(
new Shape.MouseGestureAdapter() {
881 public void mouseClicked(
final MouseEvent e) {
882 final Shape.EventInfo info = (Shape.EventInfo)e.getAttachment();
883 final GLButton s = (GLButton)info.shape;
884 s.setAnimate( s.isToggleOn() );
885 animate[0] = s.getAnimate();
891 private void initTexts() {
892 strings =
new String[4];
895 strings[i++] =
"- Mouse Scroll Over Object\n"+
898 " - Shift: Y-Rotation\n"+
899 " - Tilt, Space and Corner\n"+
900 " - Their respective action via wheel\n"+
901 " (shift = other value)\n"+
903 "- Mouse Drag On Object\n"+
904 " - Click on Object and drag mouse\n"+
905 " - Current postion in status line at bottom\n"+
906 " - Resize when click on 1/4 bottom-left or bottom-right corner.\n"+
908 "- Tilt Button Rotate Whole Button Group";
910 strings[i++] =
"abcdefghijklmn\nopqrstuvwxyz\n"+
913 "0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]";
915 strings[i++] =
"The quick brown fox jumps over the lazy dog";
917 strings[i++] = longText;
919 labels =
new Label[i];
921 currentText = strings.length - 1;
925 private static final boolean enableOthers =
true;
928 private void initLabels(
final GL2ES2 gl) {
929 jogampLabel =
new Label(options.
renderModes, font, fontSizeFixedNorm, jogamp);
934 truePtSizeLabel =
new Label(options.
renderModes, font, truePtSize);
936 truePtSizeLabel.
setColor(0.1f, 0.1f, 0.1f, 1.0f);
944 fpsLabel =
new Label(options.
renderModes, fontFPS,
"Nothing there yet");
947 fpsLabel.
setColor(0.1f, 0.1f, 0.1f, 1.0f);
954 if( upObj instanceof
Window ) {
960 System.err.println(
"Monitor detected: "+monitor);
961 System.err.println(
"Monitor dpi: "+monitorDPI[0]+
" x "+monitorDPI[1]);
963 System.err.println(
"Surface dpi "+sDPI[0]+
" x "+sDPI[1]);
965 System.err.println(
"Using default DPI of "+dpiV);
969 System.err.println(
"AUTO RenderMode: dpi "+dpiV+
", threshold "+options.
noAADPIThreshold+
974 System.err.println(
"UISceneDemo20: init (1)");
978 System.err.println(
"UISceneDemo20: init (0)");
980 cDrawable = drawable;
989 System.err.println(
"VSync Swap Interval: "+gl.getSwapInterval());
990 System.err.println(
"Chosen: "+drawable.getChosenGLCapabilities());
993 gl.setSwapInterval(1);
1003 scene.
init(drawable);
1013 System.err.println(
"UISceneDemo20: reshape: "+x+
"/"+y+
" "+width+
"x"+height);
1014 System.err.println(
"UISceneDemo20: drawable: "+drawable);
1019 System.err.println(
"Reshape: Scene Plane.0 "+scene.
getBounds());
1022 System.err.println(
"Reshape: Scene Plane.0 "+lastSceneWidth+
" x "+lastSceneHeight);
1024 scene.
reshape(drawable, x, y, width, height);
1027 System.err.println(
"Reshape: Scene Plane.1 "+sceneBox);
1028 System.err.println(
"Reshape: Scene zEpsilon "+zEpsilon);
1030 final float sceneWidth = sceneBox.
getWidth();
1031 final float sceneHeight = sceneBox.
getHeight();
1032 final float button_sxy = sceneWidth > sceneHeight ? sceneWidth : sceneHeight;
1034 TreeTool.forAll(buttonsLeft, (
final Shape s) -> {
if( s instanceof
Button) { ((
Button)s).setLabelZOffset(zEpsilon); }
return false; } );
1035 TreeTool.forAll(buttonsRight, (
final Shape s) -> {
if( s instanceof
Button) { ((
Button)s).setLabelZOffset(zEpsilon); }
return false; } );
1039 buttonsLeft.
setScale(button_sxy, button_sxy, 1f);
1040 buttonsRight.
setScale(button_sxy, button_sxy, 1f);
1042 final float dz = 0f;
1043 final float dxLeft = sceneBox.
getMinX();
1044 final float dyBottom = sceneBox.
getMinY();
1045 final float dyTop = dyBottom + sceneHeight * relTop;
1047 System.err.println(
"XXX: dw "+sceneWidth+
", dh "+sceneHeight+
", dyTop "+dyTop);
1048 System.err.println(
"BL "+buttonsLeft);
1049 System.err.println(
"BL "+buttonsLeft.
getLayout());
1050 System.err.println(
"BR "+buttonsRight);
1051 System.err.println(
"BR "+buttonsRight.
getLayout());
1055 jogampLabel.
setScale(sceneHeight, sceneHeight, 1f);
1057 final float dxMiddleAbs = dxLeft + sceneWidth * relMiddle;
1062 final float scale = pixelSize10Pt / height * sceneHeight;
1063 System.err.println(
"10Pt PixelSize: Display "+dpiV+
" dpi, fontSize "+fontSizePt+
" pt, "+
FontScale.
ptToMM(fontSizePt)+
" mm -> "+pixelSize10Pt+
" pixels, "+scale+
" scene-size");
1064 truePtSizeLabel.
setScale(scale, scale, 1f);
1069 final float scale = sceneWidth / ( 1.4f * fbox.
getWidth() );
1070 fpsLabel.
setScale(scale, scale, 1f);
1073 System.err.println(
"StatusLabel Scale: " + scale +
" = " + sceneWidth +
" / " + fbox.
getWidth() +
", " + fbox);
1074 System.err.println(
"StatusLabel: " + fpsLabel);
1076 if(
null != labels[currentText] ) {
1077 labels[currentText].
setScale(sceneHeight, sceneHeight, 1f);
1078 labels[currentText].
moveTo(dxMiddleAbs,
1082 System.err.println(
"Label["+currentText+
"] MOVE: "+labels[currentText]);
1083 System.err.println(
"Label["+currentText+
"] MOVE: "+labels[currentText].getPosition());
1089 System.err.println(
"UISceneDemo20: dispose");
1101 if(
null == labels[currentText]) {
1103 final float sceneHeight = sbox.
getHeight();
1106 labels[currentText] =
new Label(options.
renderModes, font, fontSizeFixedNorm, strings[currentText]);
1107 labels[currentText].
setScale(sceneHeight, sceneHeight, 1f);
1108 labels[currentText].
setColor(0.1f, 0.1f, 0.1f, 1.0f);
1109 labels[currentText].
setVisible(enableOthers);
1112 labels[currentText].
move(dxMiddle,
1117 scene.
addShape(labels[currentText]);
1118 System.err.println(
"Label["+currentText+
"] CTOR: "+labels[currentText]);
1119 System.err.println(
"Label["+currentText+
"] CTOR: "+labels[currentText].getPosition());
1123 if(
null == actionText ) {
1130 if( fpsLabel.
setText(text) ) {
1143 public void mouseReleased(
final MouseEvent e) {
1148 public void mouseDragged(
final MouseEvent e) {
1149 final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment();
1150 if( e.getPointerCount() == 1 ) {
1151 final AABBox worldBounds;
1154 worldBounds = scene.
getBounds(pmv, shapeEvent.shape);
1156 actionText = String.format((Locale)
null,
"Pos %s", worldBounds.
getCenter());
1161 public void mouseWheelMoved(
final MouseEvent e) {
1162 final Shape.EventInfo shapeEvent = (Shape.EventInfo) e.getAttachment();
1163 final Vec3f rot =
new Vec3f(e.getRotation()).
scale( FloatUtil.PI / 180.0f );
1165 final float tmp = rot.x(); rot.setX( rot.y() ); rot.setY( tmp );
1166 shapeEvent.shape.setRotation( shapeEvent.shape.getRotation().rotateByEuler( rot.scale( 2f ) ) );
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
static String getRenderModeString(final int renderModes)
Returns a unique technical description string for renderModes as follows:
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
final void setHintBits(final int mask)
The optional property jogamp.graph.font.ctor allows user to specify the FontConstructor implementatio...
static final FontSet get(final int font)
Simple static font scale methods for unit conversions.
static float ptToMM(final float points)
Converts the the given points size to mm, dividing by 72 * 25.4 points per inch.
static float toPixels(final float points, final float res_dpi)
Converts typical font size in points and screen resolution in dpi (pixels-per-inch) to font size in p...
Group of Shapes, optionally utilizing a Group.Layout.
void addShape(final Shape s)
Adds a Shape.
void removeAllShapes(final GL2ES2 gl, final RegionRenderer renderer)
Removes all contained shapes with Shape#destroy(GL2ES2, RegionRenderer).
List< Shape > getShapes()
Returns added Shapes.
Layout getLayout()
Return current Group.Layout.
Group setLayout(final Layout l)
Set Group.Layout.
void addShape(final Shape s)
Adds a Shape.
void addDisposeAction(final GLRunnable action)
Add a user one-time GLRunnable disposal action to an internal list, all invoked at {@Link dispose(GLA...
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
RegionRenderer getRenderer()
Returns the associated RegionRenderer.
Shape getShapeByID(final int id)
int setAAQuality(final int v)
Sets RegionRenderer#setAAQuality(int).
void dispose(final GLAutoDrawable drawable)
Disposes all added Shapes.
final void setPMVMatrixSetup(final PMVMatrixSetup setup)
Set a custom PMVMatrixSetup.
static float getZEpsilon(final int zBits, final PMVMatrixSetup setup)
Default Z precision on 16-bit depth buffer using -1 z-position and DEFAULT_ZNEAR.
AABBox getBounds(final PMVMatrix4f pmv, final Shape shape)
Returns AABBox dimension of given Shape from this container's perspective, i.e.
synchronized void attachInputListenerTo(final GLWindow window)
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height)
Reshape scene using setupMatrix(PMVMatrix4f, int, int, int, int) using PMVMatrixSetup.
String getStatusText(final GLAutoDrawable glad, final int renderModes, final float dpi)
Return a formatted status string containing avg fps and avg frame duration.
File nextScreenshotFile(final String dir, final String prefix, final int renderModes, final GLCapabilitiesImmutable caps, final String contentDetail)
Return the unique next technical screenshot PNG File instance as follows:
Convenient adapter combining dummy implementation for MouseListener and GestureListener.
Generic Shape, potentially using a Graph via GraphShape or other means of representing content.
Shape setColor(final float r, final float g, final float b, final float a)
Set base color.
final Shape move(final float dtx, final float dty, final float dtz)
Move about scaled distance.
final Shape setScale(final Vec3f s)
Set scale factor to given scale.
final Shape setFixedARatioResize(final boolean v)
Sets whether aspect-ratio shall be kept at resize, if isResizable().
final Shape moveTo(final float tx, final float ty, final float tz)
Move to scaled position.
final float getScaledWidth()
Returns the scaled width of the bounding AABBox for this shape.
final float getScaledHeight()
Returns the scaled height of the bounding AABBox for this shape.
final Vec3f getPosition()
Returns position Vec3f reference, i.e.
final boolean isVisible()
Returns true if this shape is set visible by the user, otherwise false.
final Shape validate(final GL2ES2 gl)
Validates the shape's underlying GLRegion.
final Shape addMouseListener(final MouseGestureListener l)
final Shape setVisible(final boolean v)
Enable (default) or disable this shape's visibility.
A GraphUI text label GraphShape.
boolean setText(final CharSequence text)
Set the text to be rendered.
float getScaledLineHeight()
Returns Font#getLineHeight() * getFontScale() * getScaleY().
Axis Aligned Bounding Box.
final AABBox scale(final float s)
Scale this AABBox by a constant around fixed center.
final Vec3f getCenter()
Returns computed center of this AABBox of getLow() and getHigh().
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
Visual output device, i.e.
static float[] mmToInch(final float[] ppmm)
Converts [1/mm] to [1/inch] in place.
final float[] getPixelsPerMM(final float[] ppmmStore)
Returns the pixels per millimeter value according to the current mode's surface resolution.
static Display createDisplay(final String name)
Create a Display entity.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
Pointer event of type PointerType.
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void setTitle(final String title)
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
CapabilitiesChooser setCapabilitiesChooser(final CapabilitiesChooser chooser)
Set the CapabilitiesChooser to help determine the native visual type.
final boolean setSurfaceScale(final float[] pixelScale)
Request a pixel scale in x- and y-direction for the associated NativeSurface, where size_in_pixel_uni...
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
abstract GL setGL(GL gl)
Sets the GL pipeline object for this GLContext.
Factory for pipelining GL instances.
static final GL create(final String pipelineClazzBaseName, final Class<?> reqInterface, final GL downstream, final Object[] additionalArgs)
Creates a pipelined GL instance using the given downstream downstream and optional arguments addition...
static StringBuilder getGLInfo(final GL gl, final StringBuilder sb)
Complex interactive GraphUI Scene demo with different Button and Label Shapes layout on the screen.
static final int BUTTON_GLEL
UISceneDemo20(final String fontfilename, final String filmURL, final int renderModes, final boolean debug, final boolean trace)
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
static final int BUTTON_MOVIE
static void main(final String[] args)
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
static final int BUTTON_NEXTTEXT
Shape getShapeByID(final int name)
void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height)
Called by the drawable during the first repaint after the component has been resized.
UISceneDemo20(final String fontfilename, final String filmURL, final float noAADPIThreshold, final boolean debug, final boolean trace)
static final int BUTTON_QUIT
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
static final int BUTTON_VSYNC
UISceneDemo20(final int renderModes)
static final int BUTTON_FPS
GLCapabilities getGLCaps()
int fixDefaultAARenderModeWithDPIThreshold(final float dpiV)
Fix default AA rendering bit, forced if having default_aa_setting is true.
int graphAASamples
Sample count for Graph Region AA render-modes: Region#VBAA_RENDERING_BIT or Region#MSAA_RENDERING_BIT...
int graphAAQuality
Pass2 AA-quality rendering for Graph Region AA render-modes: VBAA_RENDERING_BIT.
void parse(final String[] args)
static float atof(final String str, final float def)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized Thread setExclusiveContext(final Thread t)
Dedicate all GLAutoDrawable's context to the given exclusive context thread.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
Custom GLCapabilitiesChooser, filtering out all full screen anti-aliasing (FSAA, multisample) capabil...
float getDescent()
Distance from baseline of lowest descender, a negative value.
float getLineGap()
Typographic line gap, a positive value.
Interface wrapper for font implementation.
String getFullFamilyName()
Shall return the family and subfamily name, separated a dash.
AABBox getGlyphBounds(final CharSequence string)
Try using getGlyphBounds(CharSequence, AffineTransform, AffineTransform) to reuse AffineTransform ins...
static String getUTF16String(final char codepoint)
Returns UTF-16 representation of the specified (unicode) codepoint symbol like Character#toChars(int)...
Adding mutable surface pixel scale property to implementing class, usually to a NativeSurface impleme...
float[] getMaximumSurfaceScale(final float[] result)
Returns the maximum pixel scale of the associated NativeSurface.
static final float AUTOMAX_PIXELSCALE
Setting surface-pixel-scale of {@value}, results in maximum platform dependent pixel-scale,...
float[] getCurrentSurfaceScale(final float[] result)
Returns the current pixel scale of the associated NativeSurface.
Specifying NEWT's Window functionality:
float[] getPixelsPerMM(final float[] ppmmStore)
Returns the pixels per millimeter of this window's NativeSurface according to the main monitor's curr...
MonitorDevice getMainMonitor()
Returns the MonitorDevice with the highest viewport coverage of this window.
void resetFPSCounter()
Reset all performance counter (startTime, currentTime, frame number)
An animator control interface, which implementation may drive a com.jogamp.opengl....
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
boolean invoke(boolean wait, GLRunnable glRunnable)
Enqueues a one-shot GLRunnable, which will be executed within the next display() call after all regis...
GLAnimatorControl getAnimator()
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
Object getUpstreamWidget()
Method may return the upstream UI toolkit object holding this GLAutoDrawable instance,...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
GLContext getContext()
Returns the GLContext associated which this GL object.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
static final int GL_COLOR_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" with expression '0x...
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...
static final int GL_DEPTH_TEST
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_TEST" with expression '0x0B71',...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
static final int GL_BLEND
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_BLEND" with expression '0x0BE2',...
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" with expression '0x...