28package com.jogamp.opengl.demos.graph.ui;
30import java.io.IOException;
32import com.jogamp.common.os.Clock;
33import com.jogamp.graph.curve.Region;
34import com.jogamp.graph.font.Font;
35import com.jogamp.graph.font.FontFactory;
36import com.jogamp.graph.font.FontSet;
37import com.jogamp.graph.ui.Scene;
38import com.jogamp.graph.ui.Shape;
39import com.jogamp.graph.ui.shapes.GLButton;
40import com.jogamp.math.Recti;
41import com.jogamp.math.geom.AABBox;
42import com.jogamp.math.util.PMVMatrix4f;
43import com.jogamp.newt.event.MouseEvent;
44import com.jogamp.newt.event.WindowAdapter;
45import com.jogamp.newt.event.WindowEvent;
46import com.jogamp.newt.opengl.GLWindow;
47import com.jogamp.opengl.GL;
48import com.jogamp.opengl.GLCapabilities;
49import com.jogamp.opengl.demos.es2.GearsES2;
50import com.jogamp.opengl.demos.util.CommandlineOptions;
51import com.jogamp.opengl.util.Animator;
67 public static void main(
final String[] args)
throws IOException {
69 System.err.println(options);
71 System.out.println(
"Requested: " + reqCaps);
81 System.err.println(
"Shape "+shape);
102 public void windowDestroyNotify(
final WindowEvent e) {
110 animator.
add(window);
120 System.err.println(
"SceneBox "+sceneBox);
121 System.err.println(
"Shape "+shape);
122 try { Thread.sleep(1000); }
catch (
final InterruptedException e1) { }
127 final float min_obj = sceneBox.
getMinX();
134 final float dist_px = scene.
getWidth() - shapeSizePx[0];
135 final float dist_m = dist_px/pixPerMM/1e3f;
136 final float velocity = 50/1e3f;
137 final float velocity_px = velocity * 1e3f * pixPerMM;
138 final float velocity_obj = velocity_px / pixPerShapeUnit[0];
139 final float exp_dur_s = dist_m / velocity;
141 System.err.println();
142 System.err.printf(
"Shape: %d x %d [pixel], %.4f px/shape_unit%n", shapeSizePx[0], shapeSizePx[1], pixPerShapeUnit[0]);
143 System.err.printf(
"Shape: %s%n", shape);
144 System.err.println();
145 System.err.printf(
"Distance: %.0f pixel @ %.3f px/mm, %.3f mm%n", dist_px, pixPerMM, dist_m*1e3f);
146 System.err.printf(
"Velocity: %.3f mm/s, %.3f px/s, %.6f obj/s, expected travel-duration %.3f s%n",
147 velocity*1e3f, velocity_px, velocity_obj, exp_dur_s);
149 final long t0_us = Clock.currentNanos() / 1000;
151 shape.
moveTo(min_obj, 0f, 0f);
153 final long t2_us = Clock.currentNanos() / 1000;
154 final float dt_s = ( t2_us - t1_us ) / 1e6f;
157 final float dx = velocity_obj * dt_s;
162 window.
invoke(
true, (drawable) -> {
163 shape.
move(dx, 0f, 0f);
167 final float has_dur_s = ( ( Clock.currentNanos() / 1000 ) - t0_us ) / 1e6f;
168 System.err.printf(
"Actual travel-duration %.3f s, delay %.3f s%n", has_dur_s, has_dur_s-exp_dur_s);
169 try { Thread.sleep(1000); }
catch (
final InterruptedException e1) { }
175 static class MyPMVMatrixSetup
extends Scene.DefaultPMVMatrixSetup {
178 super.set(pmv, viewport);
182 setPlaneBox(planeBox0, pmv, viewport);
183 final float sx = planeBox0.
getWidth();
185 final float sxy = sx > sy ? sx : sy;
186 pmv.scaleP(sxy / 100f, sxy / 100f, 1f);
190 static Shape makeShape(
final Font font,
final int renderModes) {
192 final float sh = sw / 2.5f;
194 final GearsES2 gears =
new GearsES2(0);
195 gears.setVerbose(
false);
196 gears.setClearColor(
new float[] { 0.9f, 0.9f, 0.9f, 1f } );
197 final boolean[] animate = {
true };
198 new Thread(
new Runnable() {
201 System.err.println(
"Gears Anim: Waiting");
203 gears.waitForInit(
true);
204 }
catch (
final InterruptedException e) { }
205 System.err.println(
"Gears Anim: Started");
206 while( gears.isInit() ) {
208 final float ry = ( gears.getRotY() + 1 ) % 360;
213 }
catch (
final InterruptedException e) { }
215 System.err.println(
"Gears Anim: End");
218 final int texUnit = 1;
219 final GLButton b =
new GLButton(renderModes, sw,
220 sh, texUnit, gears,
false );
221 b.setToggleable(
true);
224 b.addMouseListener(
new Shape.MouseGestureAdapter() {
226 public void mouseClicked(final MouseEvent e) {
227 b.setAnimate( b.isToggleOn() );
228 animate[0] = b.getAnimate();
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}.
void addShape(final Shape s)
Adds a Shape.
final void setClearParams(final float[] clearColor, final int clearMask)
Sets the clear parameter for glClearColor(..) and glClear(..) to be issued at display(GLAutoDrawable)...
int setAAQuality(final int v)
Sets RegionRenderer#setAAQuality(int).
void waitUntilDisplayed()
Blocks until first display(GLAutoDrawable) has completed after construction or dispose(GLAutoDrawable...
final void setPMVMatrixSetup(final PMVMatrixSetup setup)
Set a custom PMVMatrixSetup.
int getWidth()
Returns the getViewport()'s width, set after initial reshape(GLAutoDrawable, int, int,...
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)
Generic Shape, potentially using a Graph via GraphShape or other means of representing content.
final Shape move(final float dtx, final float dty, final float dtz)
Move about scaled distance.
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 Vec3f getPosition()
Returns position Vec3f reference, i.e.
final float[] getPixelPerShapeUnit(final int[] shapeSizePx, final float[] pixPerShape)
Retrieve pixel per scaled shape-coordinate unit, i.e.
final AABBox getBounds()
Returns the unscaled bounding AABBox for this shape, borrowing internal instance.
final int[] getSurfaceSize(final PMVMatrix4f pmv, final Recti viewport, final int[] surfaceSize)
Retrieve surface (view) size in pixels of this shape.
Rectangle with x, y, width and height integer components.
Axis Aligned Bounding Box.
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final boolean isNativeValid()
final void setTitle(final String title)
final float[] getPixelsPerMM(final float[] ppmmStore)
Returns the pixels per millimeter of this window's NativeSurface according to the main monitor's curr...
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
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.
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
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, Scene attached to GLWindow showing simple linear Shape movement.
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...
int graphAAQuality
Pass2 AA-quality rendering for Graph Region AA render-modes: VBAA_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.
boolean invoke(boolean wait, GLRunnable glRunnable)
Enqueues a one-shot GLRunnable, which will be executed within the next display() call after all regis...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
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...