28package com.jogamp.opengl.demos.graph.ui;
30import java.io.IOException;
32import com.jogamp.common.os.Clock;
33import com.jogamp.common.util.IOUtil;
34import com.jogamp.graph.curve.Region;
35import com.jogamp.graph.font.Font;
36import com.jogamp.graph.font.FontFactory;
37import com.jogamp.graph.ui.Scene;
38import com.jogamp.graph.ui.shapes.Label;
39import com.jogamp.math.geom.AABBox;
40import com.jogamp.math.util.PMVMatrix4f;
41import com.jogamp.newt.MonitorDevice;
42import com.jogamp.newt.event.WindowAdapter;
43import com.jogamp.newt.event.WindowEvent;
44import com.jogamp.newt.opengl.GLWindow;
45import com.jogamp.opengl.GL;
46import com.jogamp.opengl.GLCapabilities;
47import com.jogamp.opengl.GLProfile;
48import com.jogamp.opengl.demos.graph.FontSetDemos;
49import com.jogamp.opengl.demos.util.CommandlineOptions;
50import com.jogamp.opengl.demos.util.MiscUtils;
51import com.jogamp.opengl.util.Animator;
66 static float req_total_dur_s = 6f;
68 public static void main(
final String[] args)
throws IOException {
71 if( 0 != args.length ) {
72 final int[] idx = { 0 };
73 for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
74 if( options.
parse(args, idx) ) {
76 }
else if(args[idx[0]].equals(
"-aspeed")) {
79 options.keepRunning =
true;
83 System.err.println(options);
85 System.out.println(
"Requested: " + reqCaps);
96 destText.
setColor(0.1f, 0.1f, 0.1f, 1);
98 movingGlyph.
setColor(0.1f, 0.1f, 0.1f, 1);
120 public void windowDestroyNotify(
final WindowEvent e) {
127 animator.
add(window);
138 System.err.println(
"SceneBox "+sceneBox);
144 final Label statusLabel;
146 final AABBox fbox = fontStatus.
getGlyphBounds(
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
149 System.err.println(
"StatusLabel Scale: " + statusLabelScale +
" = " + sceneBox.
getWidth() +
" / " + fbox.
getWidth() +
", " + fbox);
151 statusLabel =
new Label(options.
renderModes, fontStatus,
"Nothing there yet");
152 statusLabel.
setScale(statusLabelScale, statusLabelScale, 1f);
153 statusLabel.
setColor(0.1f, 0.1f, 0.1f, 1.0f);
158 final String originalText =
"GraphUI & JOGL, Resolution Agnostic Curve Rendering @ GPU via OpenGL® on Java™";
164 float req_dur_s = 0f;
165 float req_velocity = 0f;
166 final float init_velocity = 2000/1e3f;
168 final float pixPerMM, dpiV;
179 System.err.println(
"FontScale: "+fontScale+
" = "+sceneBox.
getWidth()+
" / "+fbox.
getWidth());
180 destText.
setScale(fontScale, fontScale, 1f);
181 movingGlyph.
setScale(fontScale, fontScale, 1f);
185 final long t0_us = Clock.currentNanos() / 1000;
186 float exp_total_dur_s = 0f;
187 float total_dist_m = 0f;
188 for(
int idx = 0; idx < originalText.length() && window.
isNativeValid(); ++idx ) {
189 boolean skipChar =
false;
190 final String[] movingChar = {
null };
192 movingChar[0] = originalText.substring(idx, idx+1);
193 if( Character.isWhitespace(movingChar[0].charAt(0)) ) {
200 }
while( skipChar && idx < originalText.length() );
201 if( movingChar[0].isEmpty() ) {
206 movingGlyph.
setText(hasGLP, movingChar[0]);
209 movingGlyph.
moveTo(start_pos, 0f, 0f);
212 final int[] destTextSizePx = destText.
getSurfaceSize(scene, pmv,
new int[2]);
213 final int[] movingGlyphSizePx = movingGlyph.
getSurfaceSize(scene, pmv,
new int[2]);
214 final float[] movingGlyphPixPerShapeUnit = movingGlyph.
getPixelPerShapeUnit(movingGlyphSizePx,
new float[2]);
216 final float dist_px = scene.
getWidth() - movingGlyphSizePx[0];
217 final float dist_m = dist_px/pixPerMM/1e3f;
218 final float exp_dur_s = dist_m / init_velocity;
219 total_dist_m += dist_m;
221 exp_total_dur_s = ( exp_dur_s * originalText.length() ) / 2f;
222 req_dur_s = ( req_total_dur_s * 2f ) / originalText.length();
223 req_velocity = dist_m / req_dur_s;
227 final float velocity_px = req_velocity * 1e3f * pixPerMM;
228 final float velocity_obj = velocity_px / movingGlyphPixPerShapeUnit[0];
231 System.err.println();
232 System.err.printf(
"DestText: %d x %d [pixel], %s%n", destTextSizePx[0], destTextSizePx[1], destText.
getText());
233 System.err.printf(
"MovingGl: %d x %d [pixel], %.4f px/su, %s%n", movingGlyphSizePx[0], movingGlyphSizePx[1], movingGlyphPixPerShapeUnit[0], movingGlyph.
getText());
235 System.err.println();
236 System.err.printf(
"Distance: %.0f pixel @ %.3f px/mm, %.3f mm%n", dist_px, pixPerMM, dist_m*1e3f);
237 System.err.printf(
"Velocity: init %.3f mm/s, req %.3f mm/s, %.3f px/s, %.6f obj/s, duration exp %.3f s, req %.3f s%n",
238 init_velocity*1e3f, req_velocity*1e3f, velocity_px, velocity_obj, exp_dur_s, req_dur_s);
243 final long t1_us = Clock.currentNanos() / 1000;
244 final long[] t2_us = { t1_us };
248 final long[] t3_us = { 0 };
249 window.
invoke(
true, (drawable) -> {
250 t3_us[0] = Clock.currentNanos() / 1000;
251 final float dt_s = ( t3_us[0] - t2_us[0] ) / 1e6f;
252 final float dx = -1f * velocity_obj * dt_s;
253 movingGlyph.
move(dx, 0f, 0f);
254 final String text = String.format(
"%s, anim-duration %.1f s",
262 final float has_dur_s = ( ( Clock.currentNanos() / 1000 ) - t1_us ) / 1e6f;
263 System.err.printf(
"Actual char travel-duration %.3f s, %.3f mm/s, delay exp %.3f s, req %.3f%n",
264 has_dur_s, (dist_m/has_dur_s)*1e3f, has_dur_s-exp_dur_s, has_dur_s-req_dur_s);
269 final float has_dur_s = ( ( Clock.currentNanos() / 1000 ) - t0_us ) / 1e6f;
270 System.err.printf(
"Text travel-duration %.3f s, dist %.3f mm, %.3f mm/s, %d chars, %.3f s/char; Exp %.3f s, delay %.3f s, Req %.3f s, delay %.3f s%n",
271 has_dur_s, total_dist_m*1e3f, (total_dist_m/has_dur_s)*1e3f, originalText.length(), has_dur_s / originalText.length(),
272 exp_total_dur_s, has_dur_s - exp_total_dur_s,
273 req_total_dur_s, has_dur_s - req_total_dur_s);
274 try { Thread.sleep(1000); }
catch (
final InterruptedException e1) { }
276 if( autoSpeed > 0 ) {
277 if( req_total_dur_s > 3f ) {
278 req_total_dur_s -= 3f;
280 req_total_dur_s += 3f;
283 }
else if( autoSpeed < 0 ) {
284 if( req_total_dur_s < 10f ) {
285 req_total_dur_s += 3f;
287 req_total_dur_s -= 3f;
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)
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...
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)
String getStatusText(final GLAutoDrawable glad, final int renderModes, final float dpi)
Return a formatted status string containing avg fps and avg frame duration.
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 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 Shape validate(final GL2ES2 gl)
Validates the shape's underlying GLRegion.
final int[] getSurfaceSize(final PMVMatrix4f pmv, final Recti viewport, final int[] surfaceSize)
Retrieve surface (view) size in pixels of this shape.
A GraphUI text label GraphShape.
boolean setText(final CharSequence text)
Set the text to be rendered.
CharSequence getText()
Returns the label text.
Axis Aligned Bounding Box.
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
Visual output device, i.e.
static float[] perMMToPerInch(final float[] ppmm)
Converts [1/mm] to [1/inch] in place.
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.
Specifies the the OpenGL profile.
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)
static void waitForKey(final String preMessage)
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.
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...
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.
GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
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...