29package com.jogamp.opengl.demos;
31import java.io.IOException;
32import java.lang.reflect.Constructor;
34import com.jogamp.newt.Display;
35import com.jogamp.newt.Display.PointerIcon;
36import com.jogamp.newt.NewtFactory;
37import com.jogamp.newt.Screen;
38import com.jogamp.newt.event.WindowEvent;
39import com.jogamp.newt.event.TraceMouseAdapter;
40import com.jogamp.newt.event.WindowAdapter;
41import com.jogamp.newt.opengl.GLWindow;
42import com.jogamp.newt.opengl.util.NEWTDemoListener;
43import com.jogamp.opengl.util.Animator;
44import com.jogamp.opengl.util.AnimatorBase;
45import com.jogamp.common.util.ReflectionUtil;
46import com.jogamp.nativewindow.ScalableSurface;
47import com.jogamp.nativewindow.util.Dimension;
48import com.jogamp.nativewindow.util.Point;
49import com.jogamp.nativewindow.util.PointImmutable;
50import com.jogamp.nativewindow.util.DimensionImmutable;
51import com.jogamp.opengl.GL;
52import com.jogamp.opengl.GLAnimatorControl;
53import com.jogamp.opengl.GLAutoDrawable;
54import com.jogamp.opengl.GLCapabilities;
55import com.jogamp.opengl.GLEventListener;
56import com.jogamp.opengl.GLPipelineFactory;
57import com.jogamp.opengl.GLProfile;
58import com.jogamp.opengl.demos.es2.RedSquareES2;
59import com.jogamp.opengl.demos.util.MiscUtils;
70 static int screenIdx = 0;
75 static String demoName =
"com.jogamp.opengl.demos.es2.GearsES2";
76 static long duration = 500;
77 static boolean opaque =
true;
78 static int forceAlpha = -1;
79 static boolean undecorated =
false;
80 static boolean alwaysOnTop =
false;
81 static boolean alwaysOnBottom =
false;
82 static boolean resizable =
true;
83 static boolean sticky =
false;
84 static boolean max_vert=
false;
85 static boolean max_horz=
false;
86 static boolean fullscreen =
false;
87 static int swapInterval = 1;
88 static boolean waitForKey =
false;
89 static boolean mouseVisible =
true;
90 static boolean mouseConfined =
false;
91 static boolean useMultiplePointerIcon =
true;
92 static boolean showFPS =
true;
93 static boolean forceES2 =
false;
94 static boolean forceES3 =
false;
95 static boolean forceGL3 =
false;
96 static boolean forceGL2 =
false;
97 static boolean useDoubleBuffer =
true;
98 static boolean forceDebug =
false;
99 static boolean forceTrace =
false;
100 static boolean traceMouse =
false;
101 static boolean exclusiveContext =
false;
102 static boolean useAnimator =
true;
104 public void runTest() throws InterruptedException {
108 }
else if(forceES3) {
110 }
else if(forceES2) {
112 }
else if(forceGL2) {
119 if(-1 < forceAlpha) {
124 System.err.println(
"requested: vsync "+swapInterval+
", "+caps);
149 final Class<?> demoClazz = ReflectionUtil.getClass(demoName,
true,
Launcher0.class.getClassLoader());
152 System.err.println(
"Loading "+demoName+
"("+swapInterval+
")");
153 final Constructor<?> ctr = ReflectionUtil.getConstructor(demoClazz,
int.
class);
154 _demo = (
GLEventListener) ReflectionUtil.createInstance(ctr, swapInterval);
155 }
catch(
final Exception e ) {
156 System.err.println(e.getMessage()+
" using.0: <"+demoName+
">");
158 if(
null == _demo ) {
160 System.err.println(
"Loading "+demoName+
"()");
163 }
catch(
final Exception e ) {
164 System.err.println(e.getMessage()+
" using.1: <"+demoName+
">");
166 if(
null == _demo ) {
167 System.err.println(
"Loading RedSquareES2()");
172 System.out.println(
"Choosen demo "+demo.getClass().getName());
173 if( forceDebug || forceTrace ) {
181 }
catch (
final Exception e) {e.printStackTrace();}
188 }
catch (
final Exception e) {e.printStackTrace();}
196 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {}
220 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
221 final int width,
final int height) { }
257 animator.
add(glWindow);
275 System.err.println(
"HiDPI PixelScale: "+reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]+
" (req) -> "+
276 valReqSurfacePixelScale[0]+
"x"+valReqSurfacePixelScale[1]+
" (val) -> "+
277 hasSurfacePixelScale1[0]+
"x"+hasSurfacePixelScale1[1]+
" (has)");
280 if(
null != rwsize ) {
286 final long t0 = System.currentTimeMillis();
288 while(!newtDemoListener.
shouldQuit() && t1-t0<duration) {
295 t1 = System.currentTimeMillis();
304 public static void main(
final String args[])
throws IOException {
305 int x=0, y=0, w=640, h=480, rw=-1, rh=-1;
306 boolean usePos =
false;
308 for(
int i=0; i<args.length; i++) {
309 if(args[i].equals(
"-demo") && i+1<args.length) {
310 demoName = args[++i];
311 }
else if(args[i].equals(
"-time")) {
314 }
else if(args[i].equals(
"-translucent")) {
316 }
else if(args[i].equals(
"-forceAlpha")) {
319 }
else if(args[i].equals(
"-undecorated")) {
321 }
else if(args[i].equals(
"-atop")) {
323 }
else if(args[i].equals(
"-abottom")) {
324 alwaysOnBottom =
true;
325 }
else if(args[i].equals(
"-noresize")) {
327 }
else if(args[i].equals(
"-sticky")) {
329 }
else if(args[i].equals(
"-maxv")) {
331 }
else if(args[i].equals(
"-maxh")) {
333 }
else if(args[i].equals(
"-fullscreen")) {
335 }
else if(args[i].equals(
"-vsync")) {
338 }
else if(args[i].equals(
"-single")) {
339 useDoubleBuffer =
false;
340 }
else if(args[i].equals(
"-exclctx")) {
341 exclusiveContext =
true;
342 }
else if(args[i].equals(
"-noanim")) {
344 }
else if(args[i].equals(
"-es2")) {
346 }
else if(args[i].equals(
"-es3")) {
348 }
else if(args[i].equals(
"-gl3")) {
350 }
else if(args[i].equals(
"-gl2")) {
352 }
else if(args[i].equals(
"-debug")) {
354 }
else if(args[i].equals(
"-trace")) {
356 }
else if(args[i].equals(
"-wait")) {
358 }
else if(args[i].equals(
"-mouseInvisible")) {
359 mouseVisible =
false;
360 }
else if(args[i].equals(
"-mouseConfine")) {
361 mouseConfined =
true;
362 }
else if(args[i].equals(
"-noPointerIcons")) {
363 useMultiplePointerIcon =
false;
364 }
else if(args[i].equals(
"-showFPS")) {
366 }
else if(args[i].equals(
"-width")) {
369 }
else if(args[i].equals(
"-height")) {
372 }
else if(args[i].equals(
"-x")) {
376 }
else if(args[i].equals(
"-y")) {
380 }
else if(args[i].equals(
"-pixelScale")) {
382 final float pS =
MiscUtils.
atof(args[i], reqSurfacePixelScale[0]);
383 reqSurfacePixelScale[0] = pS;
384 reqSurfacePixelScale[1] = pS;
385 }
else if(args[i].equals(
"-rwidth")) {
388 }
else if(args[i].equals(
"-rheight")) {
391 }
else if(args[i].equals(
"-screen")) {
394 }
else if(args[i].equals(
"-traceMouse")) {
399 if( 0 < rw && 0 < rh ) {
404 wpos =
new Point(x, y);
406 System.err.println(
"demo "+demoName);
407 System.err.println(
"position "+wpos);
408 System.err.println(
"size "+wsize);
409 System.err.println(
"resize "+rwsize);
410 System.err.println(
"screen "+screenIdx);
411 System.err.println(
"translucent "+(!opaque));
412 System.err.println(
"forceAlpha "+forceAlpha);
413 System.err.println(
"undecorated "+undecorated);
414 System.err.println(
"atop "+alwaysOnTop);
415 System.err.println(
"abottom "+alwaysOnBottom);
416 System.err.println(
"resizable "+resizable);
417 System.err.println(
"sticky "+sticky);
418 System.err.println(
"max_vert "+max_vert);
419 System.err.println(
"max_horz "+max_horz);
420 System.err.println(
"fullscreen "+fullscreen);
421 System.err.println(
"mouseVisible "+mouseVisible);
422 System.err.println(
"mouseConfined "+mouseConfined);
423 System.err.println(
"pointerIcons "+useMultiplePointerIcon);
424 System.err.println(
"forceES2 "+forceES2);
425 System.err.println(
"forceES3 "+forceES3);
426 System.err.println(
"forceGL3 "+forceGL3);
427 System.err.println(
"forceGL2 "+forceGL2);
428 System.err.println(
"forceDebug "+forceDebug);
429 System.err.println(
"forceTrace "+forceTrace);
430 System.err.println(
"useDoubleBuffer "+useDoubleBuffer);
431 System.err.println(
"swapInterval "+swapInterval);
432 System.err.println(
"exclusiveContext "+exclusiveContext);
433 System.err.println(
"useAnimator "+useAnimator);
434 System.err.println(
"traceMouse "+traceMouse);
442 System.err.println(
"Start-Demo");
444 System.err.println(
"End-Demo");
445 }
catch (
final InterruptedException e) {
451 System.err.println(
"End-Pre-Shutdown");
453 System.err.println(
"End-Post-Shutdown");
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
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.
abstract Display getDisplay()
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final String getStateMaskString()
Returns a string representation of the current state mask.
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final void setPointerVisible(final boolean mouseVisible)
Makes the pointer visible or invisible.
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
final void setAlwaysOnTop(final boolean value)
final float[] getRequestedSurfaceScale(final float[] result)
Returns the requested pixel scale of the associated NativeSurface.
final void setMaximized(final boolean horz, final boolean vert)
final int getX()
Returns the current x position of this window, relative to it's parent.
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
final int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
final float[] getCurrentSurfaceScale(final float[] result)
Returns the current pixel scale of the associated NativeSurface.
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 String getSupportedStateMaskString()
Returns a string representation of the supported state mask.
final boolean setFullscreen(final boolean fullscreen)
Enable or disable fullscreen mode for this window.
final void setAlwaysOnBottom(final boolean value)
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final Rectangle getBounds()
Returns a newly created Rectangle containing window origin, getX() & getY(), and size,...
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
final void setSticky(final boolean value)
final CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
final void setResizable(final boolean value)
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
final void setUndecorated(final boolean value)
final boolean setSurfaceScale(final float[] pixelScale)
Request a pixel scale in x- and y-direction for the associated NativeSurface, where size_in_pixel_uni...
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
final void confinePointer(final boolean grab)
Confine the pointer to this window, ie.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
NEWT GLWindow Demo functionality.
static PointerIcon[] createPointerIcons(final Display disp)
void quitAdapterEnable(final boolean v)
Specifies a set of OpenGL capabilities.
void setDoubleBuffered(final boolean enable)
Enables or disables double buffering.
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...
Specifies the the OpenGL profile.
static final String GLES3
The embedded OpenGL profile ES 3.x, with x >= 0.
static final String GL3
The desktop OpenGL core profile 3.x, with x >= 1.
static void shutdown()
Manual shutdown method, may be called after your last JOGL use within the running JVM.
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
static void main(final String args[])
static void waitForKey(final String preMessage)
static int atoi(final String str, final int def)
static float atof(final String str, final float def)
static long atol(final String str, final long 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.
Adding mutable surface pixel scale property to implementing class, usually to a NativeSurface impleme...
static final float AUTOMAX_PIXELSCALE
Setting surface-pixel-scale of {@value}, results in maximum platform dependent pixel-scale,...
Immutable Dimension Interface, consisting of it's read only components:
Immutable Point interface.
Native PointerIcon handle.
CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
void setUpdateFPSFrames(int frames, PrintStream out)
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) ...
GLAnimatorControl getAnimator()
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GLContext getContext()
Returns the GLContext associated which this GL object.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.