28package com.jogamp.opengl.demos.graph.ui;
31import java.io.IOException;
32import java.net.URISyntaxException;
34import com.jogamp.common.net.Uri;
35import com.jogamp.common.util.InterruptSource;
36import com.jogamp.graph.curve.Region;
37import com.jogamp.graph.font.Font;
38import com.jogamp.graph.font.FontFactory;
39import com.jogamp.graph.font.FontSet;
40import com.jogamp.graph.ui.Scene;
41import com.jogamp.graph.ui.Shape;
42import com.jogamp.graph.ui.shapes.Button;
43import com.jogamp.graph.ui.shapes.CrossHair;
44import com.jogamp.graph.ui.shapes.GLButton;
45import com.jogamp.graph.ui.shapes.MediaButton;
46import com.jogamp.math.Recti;
47import com.jogamp.math.Vec3f;
48import com.jogamp.math.geom.AABBox;
49import com.jogamp.math.util.PMVMatrix4f;
50import com.jogamp.newt.Window;
51import com.jogamp.newt.event.KeyAdapter;
52import com.jogamp.newt.event.KeyEvent;
53import com.jogamp.newt.event.MouseEvent;
54import com.jogamp.newt.event.WindowAdapter;
55import com.jogamp.newt.event.WindowEvent;
56import com.jogamp.newt.opengl.GLWindow;
57import com.jogamp.opengl.GL;
58import com.jogamp.opengl.GLCapabilities;
59import com.jogamp.opengl.GLEventListener;
60import com.jogamp.opengl.demos.es2.GearsES2;
61import com.jogamp.opengl.demos.util.CommandlineOptions;
62import com.jogamp.opengl.util.Animator;
63import com.jogamp.opengl.util.av.GLMediaPlayer;
64import com.jogamp.opengl.util.av.GLMediaPlayerFactory;
73 static final boolean DEBUG =
false;
74 static final boolean TRACE =
false;
78 static private final String defaultMediaPath =
"http://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4";
79 static private String filmPath = defaultMediaPath;
81 public static void main(
final String[] args)
throws IOException {
84 if( 0 != args.length ) {
85 final int[] idx = { 0 };
86 for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
87 if( options.
parse(args, idx) ) {
89 }
else if(args[idx[0]].equals(
"-font")) {
92 }
else if(args[idx[0]].equals(
"-film")) {
94 filmPath = args[idx[0]];
98 System.err.println(options);
101 System.out.println(
"Requested: " + reqCaps);
114 System.err.println(
"m0 "+shape);
123 System.err.println(
"Shape moved: "+origin+
" -> "+p);
127 public void mouseMoved(final MouseEvent e) {
128 final Recti viewport = scene.getViewport(new Recti());
130 final int glWinX = e.getX();
131 final int glWinY = viewport.height() - e.getY() - 1;
132 testProject(scene, shape, glWinX, glWinY);
135 public void mouseDragged(
final MouseEvent e) {
138 final int glWinX = e.
getX();
139 final int glWinY = viewport.height() - e.
getY() - 1;
140 testProject(scene, shape, glWinX, glWinY);
143 scene.addShape(shape);
146 window.setTitle(
UISceneDemo10.class.getSimpleName()+
": "+window.getSurfaceWidth()+
" x "+window.getSurfaceHeight());
148 window.addGLEventListener(scene);
149 scene.attachInputListenerTo(window);
153 animator.
add(window);
157 public void keyPressed(
final KeyEvent arg0) {
160 new InterruptSource.Thread( () -> { window.destroy(); } ).start();
164 window.addWindowListener(
new WindowAdapter() {
166 public void windowResized(
final WindowEvent e) {
167 window.setTitle(UISceneDemo10.class.getSimpleName()+
": "+window.getSurfaceWidth()+
" x "+window.getSurfaceHeight());
170 public void windowDestroyed(
final WindowEvent e) {
181 scene.waitUntilDisplayed();
183 System.err.println(
"m1.1 Scene "+scene.getBounds());
184 System.err.println(
"m1.1 "+shape);
185 try { Thread.sleep(1000); }
catch (
final InterruptedException e1) { }
187 System.err.println(
"You may test moving the Shape by dragging the shape with 1-pointer.");
188 System.err.println(
"You may test resizing the Shape by dragging the shape on 1/5th of the bottom-left or bottom-right corner with 1-pointer.");
189 System.err.println(
"Press F4 or 'window close' to exit ..");
192 static void testProject(
final Scene scene,
final Shape shape,
final int glWinX,
final int glWinY) {
193 final PMVMatrix4f pmv =
new PMVMatrix4f();
194 final Vec3f objPos = shape.winToShapeCoord(scene.getPMVMatrixSetup(), scene.getViewport(), glWinX, glWinY, pmv,
new Vec3f());
195 System.err.printf(
"MM1: winToObjCoord: obj %s%n", objPos);
196 final int[] glWinPos = shape.shapeToWinCoord(scene.getPMVMatrixSetup(), scene.getViewport(), objPos, pmv,
new int[2]);
197 final int windx = glWinPos[0]-glWinX;
198 final int windy = glWinPos[1]-glWinY;
199 System.err.printf(
"MM2: objToWinCoord: winCoords %d / %d, diff %d x %d%n", glWinPos[0], glWinPos[1], windx, windy);
202 @SuppressWarnings(
"unused")
203 static Shape makeShape(final Window window, final Font font, final
int renderModes) {
204 final float sw = 0.25f;
205 final float sh = sw / 2.5f;
210 filmUri = Uri.cast( filmPath );
211 }
catch (
final URISyntaxException e1) {
212 throw new RuntimeException(e1);
214 final GLMediaPlayer mPlayer = GLMediaPlayerFactory.createDefault();
216 final MediaButton b =
new MediaButton(renderModes, sw, sh, mPlayer);
218 b.addDefaultEventListener();
219 b.setToggleable(
true);
221 b.setToggleOffColorMod(0f, 1f, 0f, 1.0f);
222 b.addMouseListener(
new Shape.MouseGestureAdapter() {
224 public void mouseClicked(final MouseEvent e) {
225 mPlayer.setAudioVolume( b.isToggleOn() ? 1f : 0f );
227 mPlayer.playStream(filmUri, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_NONE, GLMediaPlayer.TEXTURE_COUNT_DEFAULT);
230 final GLEventListener glel;
232 final GearsES2 gears =
new GearsES2(0);
233 gears.setVerbose(
false);
234 gears.setClearColor(
new float[] { 0.9f, 0.9f, 0.9f, 1f } );
235 window.addKeyListener(gears.getKeyListener());
238 final int texUnit = 1;
239 final GLButton b =
new GLButton(renderModes, sw,
240 sh, texUnit, glel,
false );
241 b.setToggleable(
true);
244 b.addMouseListener(
new Shape.MouseGestureAdapter() {
246 public void mouseClicked(final MouseEvent e) {
247 b.setAnimate( b.isToggleOn() );
251 return new Button(renderModes, font,
"+", sw, sh).setPerp();
253 final CrossHair b =
new CrossHair(renderModes, sw, sw, 1f/100f);
257 static class MyPMVMatrixSetup
extends Scene.DefaultPMVMatrixSetup {
259 public void set(
final PMVMatrix4f pmv,
final Recti viewport) {
260 super.set(pmv, viewport);
263 final AABBox planeBox0 =
new AABBox();
264 setPlaneBox(planeBox0, pmv, viewport);
265 final float sx = planeBox0.getWidth();
266 final float sy = planeBox0.getHeight();
267 final float sxy = sx > sy ? sx : sy;
268 pmv.scaleP(sxy, sxy, 1f);
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
The optional property jogamp.graph.font.ctor allows user to specify the FontConstructor implementatio...
static final FontSet get(final int font)
static final int UBUNTU
Ubuntu is the default font family, {@value}.
final void setClearParams(final float[] clearColor, final int clearMask)
Sets the clear parameter for glClearColor(..) and glClear(..) to be issued at display(GLAutoDrawable)...
final void setPMVMatrixSetup(final PMVMatrixSetup setup)
Set a custom PMVMatrixSetup.
final Recti getViewport(final Recti target)
Copies the current int[4] viewport in given target and returns it for chaining.
Convenient adapter combining dummy implementation for MouseListener and GestureListener.
Generic Shape, potentially using a Graph via GraphShape or other means of representing content.
final Vec3f getPosition()
Returns position Vec3f reference, i.e.
final AABBox getBounds()
Returns the unscaled bounding AABBox for this shape, borrowing internal instance.
final Shape addMouseListener(final MouseGestureListener l)
final Shape setVisible(final boolean v)
Enable (default) or disable this shape's visibility.
final void onMove(final MoveListener l)
Set user callback to be notified when shape is move(Vec3f)'ed.
Rectangle with x, y, width and height integer components.
3D Vector based upon three float components.
static final short VK_F4
Constant for the F4 function key.
static final short VK_ESCAPE
Constant for the ESCAPE function key.
final short getKeySymbol()
Returns the virtual key symbol reflecting the current keyboard layout.
static final short VK_Q
See VK_A.
Pointer event of type PointerType.
final int getY()
See details for multiple-pointer events.
final int getX()
See details for multiple-pointer events.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
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.
final GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
Res independent Shape, in Scene attached to GLWindow w/ listener attached.
static void main(final String[] args)
GLCapabilities getGLCaps()
int graphAASamples
Sample count for Graph Region AA render-modes: Region#VBAA_RENDERING_BIT or Region#MSAA_RENDERING_BIT...
void parse(final String[] args)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
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.
static final int FAMILY_LIGHT
Font family LIGHT, {@value}.
Font get(int family, int stylebits)
static final int STYLE_SERIF
SERIF style/family bit flag.
Interface wrapper for font implementation.
String getFullFamilyName()
Shall return the family and subfamily name, separated a dash.
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" wit...