JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
UITypeDemo01.java
Go to the documentation of this file.
1/**
2 * Copyright 2010-2024 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.opengl.demos.graph.ui;
29
30import java.io.File;
31import java.io.IOException;
32
33import com.jogamp.common.util.InterruptSource;
34import com.jogamp.graph.curve.Region;
35import com.jogamp.graph.curve.opengl.GLRegion;
36import com.jogamp.graph.curve.opengl.RegionRenderer;
37import com.jogamp.graph.curve.opengl.TextRegionUtil;
38import com.jogamp.graph.font.Font;
39import com.jogamp.graph.font.Font.Glyph;
40import com.jogamp.graph.font.FontFactory;
41import com.jogamp.graph.font.FontSet;
42import com.jogamp.graph.ui.GraphShape;
43import com.jogamp.graph.ui.Shape;
44import com.jogamp.graph.ui.shapes.CrossHair;
45import com.jogamp.graph.ui.shapes.Rectangle;
46import com.jogamp.math.FloatUtil;
47import com.jogamp.math.Recti;
48import com.jogamp.math.Vec3f;
49import com.jogamp.math.Vec4f;
50import com.jogamp.math.geom.AABBox;
51import com.jogamp.math.geom.plane.AffineTransform;
52import com.jogamp.math.util.PMVMatrix4f;
53import com.jogamp.newt.Window;
54import com.jogamp.newt.event.KeyAdapter;
55import com.jogamp.newt.event.KeyEvent;
56import com.jogamp.newt.event.KeyListener;
57import com.jogamp.newt.event.MouseEvent;
58import com.jogamp.newt.event.MouseListener;
59import com.jogamp.newt.event.WindowAdapter;
60import com.jogamp.newt.event.WindowEvent;
61import com.jogamp.newt.opengl.GLWindow;
62import com.jogamp.opengl.FPSCounter;
63import com.jogamp.opengl.GL;
64import com.jogamp.opengl.GL2ES2;
65import com.jogamp.opengl.GLAnimatorControl;
66import com.jogamp.opengl.GLAutoDrawable;
67import com.jogamp.opengl.GLCapabilities;
68import com.jogamp.opengl.GLEventListener;
69import com.jogamp.opengl.GLException;
70import com.jogamp.opengl.GLPipelineFactory;
71import com.jogamp.opengl.GLProfile;
72import com.jogamp.opengl.GLRunnable;
73import com.jogamp.opengl.demos.graph.MSAATool;
74import com.jogamp.opengl.demos.graph.ui.testshapes.Glyph03FreeMonoRegular_M;
75import com.jogamp.opengl.demos.util.CommandlineOptions;
76import com.jogamp.opengl.demos.util.MiscUtils;
77import com.jogamp.opengl.util.Animator;
78import com.jogamp.opengl.util.GLReadBufferUtil;
79
80/**
81 * Basic UIShape and Type Rendering demo.
82 *
83 * Action Keys:
84 * - 1/2: zoom in/out
85 * - 4/5: increase/decrease shape/text spacing
86 * - 6/7: increase/decrease corner size
87 * - 0/9: rotate
88 * - v: toggle v-sync
89 * - s: screenshot
90 */
91public class UITypeDemo01 implements GLEventListener {
92 static final boolean DEBUG = false;
93 static final boolean TRACE = false;
94
95 static CommandlineOptions options = new CommandlineOptions(1280, 720, Region.VBAA_RENDERING_BIT);
96
97 public static void main(final String[] args) throws IOException {
98 String text = "Hello Origin.";
99 Font font = null;
100 int glyph_id = Glyph.ID_UNKNOWN;
101 final int[] idx = { 0 };
102 for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
103 if( options.parse(args, idx) ) {
104 continue;
105 } else if(args[idx[0]].equals("-font")) {
106 idx[0]++;
107 font = FontFactory.get(new File(args[idx[0]]));
108 } else if(args[idx[0]].equals("-text")) {
109 idx[0]++;
110 text = args[idx[0]];
111 } else if(args[idx[0]].equals("-glyph")) {
112 idx[0]++;
113 glyph_id = MiscUtils.atoi(args[idx[0]], 0);
114 }
115 }
116 System.err.println(options);
117 if( null == font ) {
119 }
120 System.err.println("Font: "+font.getFullFamilyName());
121 System.err.println("Text: "+text);
122
123 final GLProfile glp = GLProfile.getGL2ES2();
124 final GLCapabilities caps = new GLCapabilities(glp);
125 caps.setAlphaBits(4);
126 System.out.println("Requested: " + caps);
127
128 final GLWindow window = GLWindow.create(caps);
129 // window.setPosition(10, 10);
130 window.setSize(options.surface_width, options.surface_height);
131 window.setTitle(UITypeDemo01.class.getSimpleName()+": "+window.getSurfaceWidth()+" x "+window.getSurfaceHeight());
132 final UITypeDemo01 uiGLListener = new UITypeDemo01(font, glyph_id, text, options.renderModes, DEBUG, TRACE);
133 uiGLListener.attachInputListenerTo(window);
134 window.addGLEventListener(uiGLListener);
135 window.setVisible(true);
136
137 final Animator animator = new Animator(0 /* w/o AWT */);
138 // animator.setUpdateFPSFrames(60, System.err);
139 animator.add(window);
140
141 window.addKeyListener(new KeyAdapter() {
142 @Override
143 public void keyPressed(final KeyEvent arg0) {
144 final short keySym = arg0.getKeySymbol();
145 if( keySym == KeyEvent.VK_F4 || keySym == KeyEvent.VK_ESCAPE || keySym == KeyEvent.VK_Q ) {
146 new InterruptSource.Thread( () -> { window.destroy(); } ).start();
147 }
148 }
149 });
150 window.addWindowListener(new WindowAdapter() {
151 @Override
152 public void windowDestroyed(final WindowEvent e) {
153 animator.stop();
154 }
155 });
156
157 animator.start();
158 }
159
160 private final Vec4f fg_color = new Vec4f( 0, 0, 0, 1 );
161 private final Font font;
162 private final String text;
163 private final int glyph_id;
164 private final GLReadBufferUtil screenshot;
165 private final int renderModes;
166 private final RegionRenderer rRenderer;
167 private final boolean debug;
168 private final boolean trace;
169
170 private final CrossHair crossHair;
171 private final GraphShape testObj;
172
173 private KeyAction keyAction;
174 private MouseAction mouseAction;
175
176 private volatile GLAutoDrawable autoDrawable = null;
177
178 private final float[] position = new float[] {0,0,0};
179
180 private static final float xTran = 0f;
181 private static final float yTran = 0f;
182 private static final float zTran = -1/5f;
183 private static final float zNear = 0.1f;
184 private static final float zFar = 7000.0f;
185
186 boolean ignoreInput = false;
187
188 protected final AffineTransform tempT1 = new AffineTransform();
189 protected final AffineTransform tempT2 = new AffineTransform();
190
191 @SuppressWarnings("unused")
192 public UITypeDemo01(final Font font, final int glyph_id, final String text, final int renderModes, final boolean debug, final boolean trace) {
193 this.font = font;
194 this.text = text;
195 this.glyph_id = glyph_id;
196 this.renderModes = renderModes;
198 this.rRenderer.setAAQuality(options.graphAAQuality);
199 this.rRenderer.setSampleCount(options.graphAASamples);
200 this.debug = debug;
201 this.trace = trace;
202 this.screenshot = new GLReadBufferUtil(false, false);
203
204 crossHair = new CrossHair(renderModes, 1/20f, 1/20f, 1/1000f);
205 crossHair.setColor(0f,0f,1f,1f);
206 crossHair.setVisible(true);
207
208 if (false ) {
209 final Rectangle o = new Rectangle(renderModes, 1/10f, 1/20f, 1/1000f);
210 o.move(o.getWidth(), -o.getHeight(), 0f);
211 testObj = o;
212 } else {
213 final float scale = 0.15312886f;
214 final float size_xz = 0.541f;
215 final GraphShape o = new Glyph03FreeMonoRegular_M(renderModes);
216 o.scale(scale, scale, 1f);
217 // o.translate(size_xz, -size_xz, 0f);
218 testObj = o;
219 }
220 testObj.setColor(0f, 0f, 0f, 1f);
221 testObj.setVisible(true);
222 }
223
224 public final RegionRenderer getRegionRenderer() { return rRenderer; }
225 public final float[] getPosition() { return position; }
226
227 @Override
228 public void init(final GLAutoDrawable drawable) {
229 autoDrawable = drawable;
230 GL2ES2 gl = drawable.getGL().getGL2ES2();
231 if(debug) {
232 gl = gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Debug", null, gl, null) ).getGL2ES2();
233 }
234 if(trace) {
235 gl = gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Trace", null, gl, new Object[] { System.err } ) ).getGL2ES2();
236 }
237 gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
239
240 gl.setSwapInterval(1);
242 // gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
243 MSAATool.dump(drawable);
244 }
245
246 @Override
247 public void reshape(final GLAutoDrawable drawable, final int xstart, final int ystart, final int width, final int height) {
248 final GL2ES2 gl = drawable.getGL().getGL2ES2();
249
250 gl.glViewport(xstart, ystart, width, height);
251 rRenderer.reshapePerspective(FloatUtil.QUARTER_PI, width, height, zNear, zFar);
252 // rRenderer.reshapeOrtho(width, height, zNear, zFar);
253
254 lastWidth = width;
255 lastHeight = height;
256 if( drawable instanceof Window ) {
257 ((Window)drawable).setTitle(UITypeDemo01.class.getSimpleName()+": "+drawable.getSurfaceWidth()+" x "+drawable.getSurfaceHeight());
258 }
259 }
260 float lastWidth = 0f, lastHeight = 0f;
261
262 private void drawShape(final GL2ES2 gl, final PMVMatrix4f pmv, final RegionRenderer renderer, final Shape shape) {
263 pmv.pushMv();
264 shape.applyMatToMv(pmv);
265 shape.draw(gl, renderer);
266 pmv.popMv();
267 }
268
269 @Override
270 public void display(final GLAutoDrawable drawable) {
271 final GL2ES2 gl = drawable.getGL().getGL2ES2();
272
273 gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
275
276 final RegionRenderer renderer = getRegionRenderer();
277 final PMVMatrix4f pmv = renderer.getMatrix();
278 pmv.loadMvIdentity();
279 pmv.translateMv(xTran, yTran, zTran);
280 renderer.enable(gl, true);
281 {
282 pmv.pushMv();
283 pmv.scaleMv(0.8f, 0.8f, 1f);
284 drawShape(gl, pmv, renderer, testObj);
285 pmv.popMv();
286 }
287 drawShape(gl, pmv, renderer, crossHair);
288 {
289 final float full_width_o;
290 final float full_height_o;
291 {
292 final float orthoDist = -zTran; // assume orthogonal plane at -zTran
293 float glWinX = 0;
294 float glWinY = 0;
295 final float winZ = FloatUtil.getOrthoWinZ(orthoDist, zNear, zFar);
296 final Vec3f objCoord0 = new Vec3f();
297 final Vec3f objCoord1 = new Vec3f();
298 if( pmv.mapWinToObj(glWinX, glWinY, winZ, renderer.getViewport(), objCoord0) ) {
299 if( once ) {
300 System.err.printf("winToObjCoord: win [%f, %f, %f] -> obj [%s]%n", glWinX, glWinY, winZ, objCoord0);
301 }
302 }
303 glWinX = drawable.getSurfaceWidth();
304 glWinY = drawable.getSurfaceHeight();
305 if( pmv.mapWinToObj(glWinX, glWinY, winZ, renderer.getViewport(), objCoord1) ) {
306 if( once ) {
307 System.err.printf("winToObjCoord: win [%f, %f, %f] -> obj [%s]%n", glWinX, glWinY, winZ, objCoord1);
308 }
309 }
310 full_width_o = objCoord1.x() - objCoord0.x();
311 full_height_o = objCoord1.y() - objCoord0.y();
312 }
313 pmv.pushMv();
314
315 final Font.Glyph glyph;
316 if( Glyph.ID_UNKNOWN < glyph_id ) {
317 glyph = font.getGlyph(glyph_id);
318 if( once ) {
319 System.err.println("glyph_id "+glyph_id+": "+glyph);
320 }
321 } else {
322 glyph = null;
323 }
324 if( null != glyph && glyph.getID() != Glyph.ID_UNKNOWN ) {
325 final AABBox txt_box_em = glyph.getBounds();
326 final float full_width_s = full_width_o / txt_box_em.getWidth();
327 final float full_height_s = full_height_o / txt_box_em.getHeight();
328 final float txt_scale = full_width_s < full_height_s ? full_width_s/2f : full_height_s/2f;
329 pmv.scaleMv(txt_scale, txt_scale, 1f);
330 pmv.translateMv(-txt_box_em.getWidth(), 0f, 0f);
331 if( null != glyph.getShape() ) {
332 final GLRegion region = GLRegion.create(gl.getGLProfile(), renderModes, null, glyph.getShape());
333 region.addOutlineShape(glyph.getShape(), null, fg_color);
334 region.draw(gl, renderer);
335 region.destroy(gl);
336 }
337 if( once ) {
338 final AABBox txt_box_em2 = font.getGlyphShapeBounds(null, text);
339 System.err.println("XXX: full_width: "+full_width_o+" / "+txt_box_em.getWidth()+" -> "+full_width_s);
340 System.err.println("XXX: full_height: "+full_height_o+" / "+txt_box_em.getHeight()+" -> "+full_height_s);
341 System.err.println("XXX: txt_scale: "+txt_scale);
342 System.err.println("XXX: txt_box_em "+txt_box_em);
343 System.err.println("XXX: txt_box_e2 "+txt_box_em2);
344 }
345 } else if( Glyph.ID_UNKNOWN == glyph_id ) {
346 final AABBox txt_box_em = font.getGlyphBounds(text, tempT1, tempT2);
347 final float full_width_s = full_width_o / txt_box_em.getWidth();
348 final float full_height_s = full_height_o / txt_box_em.getHeight();
349 final float txt_scale = full_width_s < full_height_s ? full_width_s/2f : full_height_s/2f;
350 pmv.scaleMv(txt_scale, txt_scale, 1f);
351 pmv.translateMv(-txt_box_em.getWidth(), 0f, 0f);
352 final AABBox txt_box_r = TextRegionUtil.drawString3D(gl, renderModes, renderer, font, text, fg_color, tempT1, tempT2);
353 if( once ) {
354 final AABBox txt_box_em2 = font.getGlyphShapeBounds(null, text);
355 System.err.println("XXX: full_width: "+full_width_o+" / "+txt_box_em.getWidth()+" -> "+full_width_s);
356 System.err.println("XXX: full_height: "+full_height_o+" / "+txt_box_em.getHeight()+" -> "+full_height_s);
357 System.err.println("XXX: txt_scale: "+txt_scale);
358 System.err.println("XXX: txt_box_em "+txt_box_em);
359 System.err.println("XXX: txt_box_e2 "+txt_box_em2);
360 System.err.println("XXX: txt_box_rg "+txt_box_r);
361 }
362 }
363 pmv.popMv();
364 if( once ) {
365 try {
366 printScreen(drawable);
367 } catch (GLException | IOException e) {
368 e.printStackTrace();
369 }
370 }
371 once = false;
372 }
373 renderer.enable(gl, false);
374 }
375 private boolean once = true;
376
377 @Override
378 public void dispose(final GLAutoDrawable drawable) {
379 final GL2ES2 gl = drawable.getGL().getGL2ES2();
380 crossHair.destroy(gl, getRegionRenderer());
381 testObj.destroy(gl, getRegionRenderer());
382
383 autoDrawable = null;
384 screenshot.dispose(gl);
385 rRenderer.destroy(gl);
386 }
387
388 /** Attach the input listener to the window */
389 public void attachInputListenerTo(final GLWindow window) {
390 if ( null == keyAction ) {
391 keyAction = new KeyAction();
392 window.addKeyListener(keyAction);
393 }
394 if ( null == mouseAction ) {
395 mouseAction = new MouseAction();
396 window.addMouseListener(mouseAction);
397 }
398 }
399
400 public void detachFrom(final GLWindow window) {
401 if ( null == keyAction ) {
402 return;
403 }
404 if ( null == mouseAction ) {
405 return;
406 }
407 window.removeGLEventListener(this);
408 window.removeKeyListener(keyAction);
409 window.removeMouseListener(mouseAction);
410 }
411
412 public void printScreen(final GLAutoDrawable drawable) throws GLException, IOException {
413 final String dir = "./";
414 final String tech="demo-"+Region.getRenderModeString(renderModes);
415 final String objName = "snap"+screenshot_num;
416 {
417 final String sw = String.format("-%03dx%03d-Z%04d-T%04d-%s", drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), (int)Math.abs(zTran), 0, objName);
418
419 final String filename = dir + tech + sw +".png";
420 if(screenshot.readPixels(drawable.getGL(), false)) {
421 screenshot.write(new File(filename));
422 }
423 }
424 screenshot_num++;
425 }
426 int screenshot_num = 0;
427
428 public void setIgnoreInput(final boolean v) {
429 ignoreInput = v;
430 }
431 public boolean getIgnoreInput() {
432 return ignoreInput;
433 }
434
435 public class MouseAction implements MouseListener{
436
437 @Override
438 public void mouseClicked(final MouseEvent e) {
439
440 }
441
442 @Override
443 public void mouseEntered(final MouseEvent e) {
444 }
445
446 @Override
447 public void mouseExited(final MouseEvent e) {
448 }
449
450 @Override
451 public void mousePressed(final MouseEvent e) {
452 autoDrawable.invoke(false, new GLRunnable() { // avoid data-race
453 @Override
454 public boolean run(final GLAutoDrawable drawable) {
455 System.err.println("\n\nMouse: "+e);
456
457 final RegionRenderer renderer = getRegionRenderer();
458 final PMVMatrix4f pmv = renderer.getMatrix();
459 pmv.loadMvIdentity();
460 pmv.translateMv(xTran, yTran, zTran);
461
462 // flip to GL window coordinates, origin bottom-left
463 final Recti viewport = renderer.getViewport(new Recti());
464 final int glWinX = e.getX();
465 final int glWinY = viewport.height() - e.getY() - 1;
466
467 {
468 pmv.pushMv();
469 crossHair.applyMatToMv(pmv);
470
471 final Vec3f objPosC = crossHair.getBounds().getCenter();
472 System.err.println("\n\nCrossHair: "+crossHair);
473 final int[] objWinPos = crossHair.shapeToWinCoord(pmv, viewport, objPosC, new int[2]);
474 System.err.println("CrossHair: Obj: Obj "+objPosC+" -> Win "+objWinPos[0]+"/"+objWinPos[1]);
475
476 final Vec3f objPos2 = crossHair.winToShapeCoord(pmv, viewport, objWinPos[0], objWinPos[1], new Vec3f());
477 System.err.println("CrossHair: Obj: Win "+objWinPos[0]+"/"+objWinPos[1]+" -> Obj "+objPos2);
478
479 final Vec3f winObjPos = crossHair.winToShapeCoord(pmv, viewport, glWinX, glWinY, new Vec3f());
480 if( null != winObjPos ) {
481 // final float[] translate = crossHair.getTranslate();
482 // final float[] objPosT = new float[] { objPosC[0]+translate[0], objPosC[1]+translate[1], objPosC[2]+translate[2] };
483 final Vec3f diff = winObjPos.minus(objPosC);
484 // final float dz = winObjPos[2] - objPosT[2];
485 if( !FloatUtil.isZero(diff.x()) || !FloatUtil.isZero(diff.y()) ) {
486 System.err.println("CrossHair: Move.1: Win "+glWinX+"/"+glWinY+" -> Obj "+winObjPos+" -> diff "+diff);
487 crossHair.move(diff.x(), diff.y(), 0f);
488 } else {
489 System.err.println("CrossHair: Move.0: Win "+glWinX+"/"+glWinY+" -> Obj "+winObjPos+" -> diff "+diff);
490 }
491 }
492
493 final int[] surfaceSize = crossHair.getSurfaceSize(pmv, viewport, new int[2]);
494 System.err.println("CrossHair: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]);
495
496 pmv.popMv();
497 }
498 return true;
499 } } );
500
501 }
502
503 @Override
504 public void mouseReleased(final MouseEvent e) {
505 }
506
507 @Override
508 public void mouseMoved(final MouseEvent e) {
509 // TODO Auto-generated method stub
510
511 }
512
513 @Override
514 public void mouseDragged(final MouseEvent e) {
515 // TODO Auto-generated method stub
516
517 }
518
519 @Override
520 public void mouseWheelMoved(final MouseEvent e) {
521 // TODO Auto-generated method stub
522
523 }
524
525 }
526
527 public class KeyAction implements KeyListener {
528 @Override
529 public void keyPressed(final KeyEvent arg0) {
530 if(ignoreInput) {
531 return;
532 }
533
534 if(arg0.getKeyCode() == KeyEvent.VK_1){
535 crossHair.move(0f, 0f, -zTran/10f);
536 }
537 else if(arg0.getKeyCode() == KeyEvent.VK_2){
538 crossHair.move(0f, 0f, zTran/10f);
539 }
540 else if(arg0.getKeyCode() == KeyEvent.VK_UP){
541 crossHair.move(0f, crossHair.getHeight()/10f, 0f);
542 }
543 else if(arg0.getKeyCode() == KeyEvent.VK_DOWN){
544 crossHair.move(0f, -crossHair.getHeight()/10f, 0f);
545 }
546 else if(arg0.getKeyCode() == KeyEvent.VK_LEFT){
547 crossHair.move(-crossHair.getWidth()/10f, 0f, 0f);
548 }
549 else if(arg0.getKeyCode() == KeyEvent.VK_RIGHT){
550 crossHair.move(crossHair.getWidth()/10f, 0f, 0f);
551 }
552 else if(arg0.getKeyCode() == KeyEvent.VK_0){
553 // rotate(1);
554 }
555 else if(arg0.getKeyCode() == KeyEvent.VK_9){
556 // rotate(-1);
557 }
558 else if(arg0.getKeyCode() == KeyEvent.VK_V) {
559 if(null != autoDrawable) {
560 autoDrawable.invoke(false, new GLRunnable() {
561 @Override
562 public boolean run(final GLAutoDrawable drawable) {
563 final GL gl = drawable.getGL();
564 final int _i = gl.getSwapInterval();
565 final int i;
566 switch(_i) {
567 case 0: i = 1; break;
568 case 1: i = -1; break;
569 case -1: i = 0; break;
570 default: i = 1; break;
571 }
572 gl.setSwapInterval(i);
573
574 final GLAnimatorControl a = drawable.getAnimator();
575 if( null != a ) {
576 a.resetFPSCounter();
577 }
578 if(drawable instanceof FPSCounter) {
579 ((FPSCounter)drawable).resetFPSCounter();
580 }
581 System.err.println("Swap Interval: "+_i+" -> "+i+" -> "+gl.getSwapInterval());
582 return true;
583 }
584 });
585 }
586 }
587 else if(arg0.getKeyCode() == KeyEvent.VK_S){
588 if(null != autoDrawable) {
589 autoDrawable.invoke(false, new GLRunnable() {
590 @Override
591 public boolean run(final GLAutoDrawable drawable) {
592 try {
593 printScreen(drawable);
594 } catch (final GLException e) {
595 e.printStackTrace();
596 } catch (final IOException e) {
597 e.printStackTrace();
598 }
599 return true;
600 }
601 });
602 }
603 }
604 }
605 @Override
606 public void keyReleased(final KeyEvent arg0) {}
607 }
608}
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
Definition: Region.java:62
final void addOutlineShape(final OutlineShape shape, final AffineTransform t, final Vec4f rgbaColor)
Add the given OutlineShape to this region with the given optional AffineTransform.
Definition: Region.java:616
static String getRenderModeString(final int renderModes)
Returns a unique technical description string for renderModes as follows:
Definition: Region.java:251
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:115
A GLRegion is the OGL binding of one or more OutlineShapes Defined by its vertices and generated tria...
Definition: GLRegion.java:70
final void destroy(final GL2ES2 gl)
Delete and clear the associated OGL objects.
Definition: GLRegion.java:460
final void draw(final GL2ES2 gl, final RegionRenderer renderer)
Renders the associated OGL objects specifying current width/hight of window for optional multi pass r...
Definition: GLRegion.java:518
static GLRegion create(final GLProfile glp, int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit, final int initialVerticesCount, final int initialIndicesCount)
Create a GLRegion using the passed render mode.
Definition: GLRegion.java:109
final void enable(final GL2ES2 gl, final boolean enable)
Enabling or disabling the RenderState's current shader program.
final PMVMatrix4f getMatrix()
Borrow the current PMVMatrix4f.
final int setSampleCount(final int v)
Sets pass2 AA sample count clipped to the range [Region#MIN_AA_SAMPLE_COUNT..Region#MAX_AA_SAMPLE_COU...
static final GLCallback defaultBlendDisable
Default GL#GL_BLEND disable GLCallback, simply turning-off the GL#GL_BLEND state and turning-on depth...
final int setAAQuality(final int v)
Sets pass2 AA-quality rendering value clipped to the range [Region#MIN_AA_QUALITY....
static final GLCallback defaultBlendEnable
Default GL#GL_BLEND enable GLCallback, turning-off depth writing via GL#glDepthMask(boolean) if Rende...
final void init(final GL2ES2 gl)
Initialize shader and bindings for GPU based rendering bound to the given GL object's GLContext if no...
static RegionRenderer create()
Create a hardware accelerated RegionRenderer including its RenderState composition.
final void reshapePerspective(final float angle_rad, final int width, final int height, final float near, final float far)
Perspective projection, method also calls reshapeNotify(int, int, int, int).
final Recti getViewport(final Recti target)
Copies the current Rect4i viewport in given target and returns it for chaining.
final void destroy(final GL2ES2 gl)
Deletes all ShaderPrograms and nullifies its references including RenderState#destroy(GL2ES2).
Text Type Rendering Utility Class adding the Font.Glyphs OutlineShape to a GLRegion.
AABBox drawString3D(final GL2ES2 gl, final RegionRenderer renderer, final Font font, final CharSequence str, final Vec4f rgbaColor)
Render the string in 3D space w.r.t.
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}.
Graph based GLRegion Shape.
Definition: GraphShape.java:55
Generic Shape, potentially using a Graph via GraphShape or other means of representing content.
Definition: Shape.java:87
Shape setColor(final float r, final float g, final float b, final float a)
Set base color.
Definition: Shape.java:1389
final Shape move(final float dtx, final float dty, final float dtz)
Move about scaled distance.
Definition: Shape.java:557
void draw(final GL2ES2 gl, final RegionRenderer renderer)
Renders the shape.
Definition: Shape.java:798
final Vec3f winToShapeCoord(final PMVMatrix4f pmv, final Recti viewport, final int glWinX, final int glWinY, final Vec3f objPos)
Map given gl-window-coordinates to object coordinates relative to this shape and its z-coordinate.
Definition: Shape.java:1305
final AABBox getBounds()
Returns the unscaled bounding AABBox for this shape, borrowing internal instance.
Definition: Shape.java:732
final int[] getSurfaceSize(final PMVMatrix4f pmv, final Recti viewport, final int[] surfaceSize)
Retrieve surface (view) size in pixels of this shape.
Definition: Shape.java:1100
final void destroy(final GL2ES2 gl, final RegionRenderer renderer)
Destroys all data.
Definition: Shape.java:457
final int[] shapeToWinCoord(final PMVMatrix4f pmv, final Recti viewport, final Vec3f objPos, final int[] glWinPos)
Map given object coordinate relative to this shape to window coordinates.
Definition: Shape.java:1236
final void applyMatToMv(final PMVMatrix4f pmv)
Applies the internal Matrix4f to the given modelview matrix, i.e.
Definition: Shape.java:908
final Shape scale(final Vec3f s)
Multiply current scale factor by given scale.
Definition: Shape.java:661
final Shape setVisible(final boolean v)
Enable (default) or disable this shape's visibility.
Definition: Shape.java:363
A GraphUI Crosshair GraphShape.
Definition: CrossHair.java:41
A GraphUI rectangle GraphShape.
Definition: Rectangle.java:47
Basic Float math utility functions.
Definition: FloatUtil.java:83
static float getOrthoWinZ(final float orthoZ, final float zNear, final float zFar)
Returns orthogonal distance (1f/zNear-1f/orthoZ) / (1f/zNear-1f/zFar);.
static final float QUARTER_PI
The value PI/4, i.e.
static boolean isZero(final float a, final float epsilon)
Returns true if value is zero, i.e.
Rectangle with x, y, width and height integer components.
Definition: Recti.java:34
3D Vector based upon three float components.
Definition: Vec3f.java:37
Vec3f minus(final Vec3f arg)
Returns this - arg; creates new vector.
Definition: Vec3f.java:255
4D Vector based upon four float components.
Definition: Vec4f.java:37
Axis Aligned Bounding Box.
Definition: AABBox.java:54
final float getWidth()
Definition: AABBox.java:879
final float getHeight()
Definition: AABBox.java:883
final Vec3f getCenter()
Returns computed center of this AABBox of getLow() and getHigh().
Definition: AABBox.java:737
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
final PMVMatrix4f translateMv(final float x, final float y, final float z)
Translate the modelview matrix.
final PMVMatrix4f scaleMv(final float x, final float y, final float z)
Scale the modelview matrix.
final PMVMatrix4f loadMvIdentity()
Load the modelview matrix with the values of the given Matrix4f.
final PMVMatrix4f popMv()
Pop the modelview matrix from its stack.
final boolean mapWinToObj(final float winx, final float winy, final float winz, final Recti viewport, final Vec3f objPos)
Map window coordinates to object coordinates.
final PMVMatrix4f pushMv()
Push the modelview matrix to its stack, while preserving its values.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
static final short VK_RIGHT
Constant for the cursor- or numerical-pad right arrow key.
Definition: KeyEvent.java:817
static final short VK_F4
Constant for the F4 function key.
Definition: KeyEvent.java:686
static final short VK_2
See VK_0.
Definition: KeyEvent.java:557
static final short VK_ESCAPE
Constant for the ESCAPE function key.
Definition: KeyEvent.java:485
static final short VK_UP
Constant for the cursor- or numerical-pad up arrow key.
Definition: KeyEvent.java:814
static final short VK_LEFT
Constant for the cursor- or numerical-pad left arrow key.
Definition: KeyEvent.java:811
final short getKeySymbol()
Returns the virtual key symbol reflecting the current keyboard layout.
Definition: KeyEvent.java:176
static final short VK_DOWN
Constant for the cursor- or numerical pad down arrow key.
Definition: KeyEvent.java:820
static final short VK_9
See VK_0.
Definition: KeyEvent.java:571
static final short VK_0
VK_0 thru VK_9 are the same as UTF16/ASCII '0' thru '9' [0x30 - 0x39].
Definition: KeyEvent.java:553
static final short VK_S
See VK_A.
Definition: KeyEvent.java:631
static final short VK_Q
See VK_A.
Definition: KeyEvent.java:627
static final short VK_V
See VK_A.
Definition: KeyEvent.java:637
static final short VK_1
See VK_0.
Definition: KeyEvent.java:555
final short getKeyCode()
Returns the virtual key code using a fixed mapping to the US keyboard layout.
Definition: KeyEvent.java:195
Pointer event of type PointerType.
Definition: MouseEvent.java:74
final int getY()
See details for multiple-pointer events.
final int getX()
See details for multiple-pointer events.
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Definition: GLWindow.java:466
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
Definition: GLWindow.java:927
final void setTitle(final String title)
Definition: GLWindow.java:297
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
Definition: GLWindow.java:902
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
Definition: GLWindow.java:461
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
Definition: GLWindow.java:882
final void removeKeyListener(final KeyListener l)
Definition: GLWindow.java:912
final void removeMouseListener(final MouseListener l)
Removes the given MouseListener from the list.
Definition: GLWindow.java:937
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
abstract GL setGL(GL gl)
Sets the GL pipeline object for this GLContext.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
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.
Definition: GLProfile.java:77
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
static void dump(final GLAutoDrawable drawable)
Definition: MSAATool.java:51
void keyPressed(final KeyEvent arg0)
A key has been pressed, excluding auto-repeat modifier keys.
void keyReleased(final KeyEvent arg0)
A key has been released, excluding auto-repeat modifier keys.
void mouseExited(final MouseEvent e)
Only generated for PointerType#Mouse.
void mouseWheelMoved(final MouseEvent e)
Traditional event name originally produced by a mouse pointer type.
void mouseEntered(final MouseEvent e)
Only generated for PointerType#Mouse.
Basic UIShape and Type Rendering demo.
static void main(final String[] args)
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void reshape(final GLAutoDrawable drawable, final int xstart, final int ystart, final int width, final int height)
Called by the drawable during the first repaint after the component has been resized.
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
UITypeDemo01(final Font font, final int glyph_id, final String text, final int renderModes, final boolean debug, final boolean trace)
void attachInputListenerTo(final GLWindow window)
Attach the input listener to the window.
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void printScreen(final GLAutoDrawable drawable)
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.
static int atoi(final String str, final int def)
Definition: MiscUtils.java:60
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
void write(final File dest)
Write the TextureData filled by readPixels(GLAutoDrawable, boolean) to file.
boolean readPixels(final GL gl, final boolean mustFlipVertically)
Read the drawable's pixels to TextureData and Texture, if requested at construction.
static final int FAMILY_LIGHT
Font family LIGHT, {@value}.
Definition: FontSet.java:39
Font get(int family, int stylebits)
static final int STYLE_SERIF
SERIF style/family bit flag.
Definition: FontSet.java:54
static final int ID_UNKNOWN
Definition: Font.java:167
Interface wrapper for font implementation.
Definition: Font.java:60
Glyph getGlyph(final String name)
Returns the Glyph mapped to given name.
AABBox getGlyphShapeBounds(final AffineTransform transform, final CharSequence string)
Returns accurate bounding box by taking each glyph's font em-sized OutlineShape into account.
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...
Specifying NEWT's Window functionality:
Definition: Window.java:115
Listener for KeyEvents.
FPSCounter feature.
Definition: FPSCounter.java:37
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.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GLEventListener removeGLEventListener(GLEventListener listener)
Removes the given listener from this drawable queue.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
GLContext getContext()
Returns the GLContext associated which this GL object.
int getSwapInterval()
Return the current swap interval.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
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_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" wit...
Definition: GL.java:390
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...
void glEnable(int cap)
Entry point to C language function: void {@native glEnable}(GLenum cap) Part of GL_ES_VERSION_2_0,...
static final int GL_DEPTH_TEST
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_TEST" with expr...
Definition: GL.java:43
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
void glViewport(int x, int y, int width, int height)
Entry point to C language function: void {@native glViewport}(GLint x, GLint y, GLsizei width,...
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...
Definition: GL.java:738