JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
UIShapeDemo01.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.opengl.FPSCounter;
34import com.jogamp.opengl.GL;
35import com.jogamp.opengl.GL2ES2;
36import com.jogamp.opengl.GLAnimatorControl;
37import com.jogamp.opengl.GLAutoDrawable;
38import com.jogamp.opengl.GLCapabilities;
39import com.jogamp.opengl.GLEventListener;
40import com.jogamp.opengl.GLException;
41import com.jogamp.opengl.GLPipelineFactory;
42import com.jogamp.opengl.GLRunnable;
43import com.jogamp.opengl.demos.graph.MSAATool;
44import com.jogamp.opengl.demos.util.CommandlineOptions;
45import com.jogamp.common.util.InterruptSource;
46import com.jogamp.graph.curve.Region;
47import com.jogamp.graph.curve.opengl.RegionRenderer;
48import com.jogamp.graph.curve.opengl.TextRegionUtil;
49import com.jogamp.graph.font.Font;
50import com.jogamp.graph.font.FontFactory;
51import com.jogamp.graph.font.FontSet;
52import com.jogamp.graph.ui.Shape;
53import com.jogamp.graph.ui.shapes.Button;
54import com.jogamp.graph.ui.shapes.CrossHair;
55import com.jogamp.math.FloatUtil;
56import com.jogamp.math.Recti;
57import com.jogamp.math.Vec3f;
58import com.jogamp.math.Vec4f;
59import com.jogamp.math.geom.AABBox;
60import com.jogamp.math.geom.plane.AffineTransform;
61import com.jogamp.math.util.PMVMatrix4f;
62import com.jogamp.newt.Window;
63import com.jogamp.newt.event.KeyAdapter;
64import com.jogamp.newt.event.KeyEvent;
65import com.jogamp.newt.event.KeyListener;
66import com.jogamp.newt.event.MouseEvent;
67import com.jogamp.newt.event.MouseListener;
68import com.jogamp.newt.event.WindowAdapter;
69import com.jogamp.newt.event.WindowEvent;
70import com.jogamp.newt.opengl.GLWindow;
71import com.jogamp.opengl.util.Animator;
72import com.jogamp.opengl.util.GLReadBufferUtil;
73
74/**
75 * Basic UIShape and Type Rendering demo.
76 *
77 * Action Keys:
78 * - 1/2: zoom in/out
79 * - 4/5: increase/decrease shape/text spacing
80 * - 6/7: increase/decrease corner size
81 * - 0/9: rotate
82 * - v: toggle v-sync
83 * - s: screenshot
84 */
85public class UIShapeDemo01 implements GLEventListener {
86 static final boolean DEBUG = false;
87 static final boolean TRACE = false;
88
89 static CommandlineOptions options = new CommandlineOptions(1280, 720, Region.VBAA_RENDERING_BIT);
90
91 public static void main(final String[] args) throws IOException {
92 Font font = null;
93 final int[] idx = { 0 };
94 for (idx[0] = 0; idx[0] < args.length; ++idx[0]) {
95 if( options.parse(args, idx) ) {
96 continue;
97 } else if(args[idx[0]].equals("-font")) {
98 idx[0]++;
99 font = FontFactory.get(new File(args[idx[0]]));
100 }
101 }
102 System.err.println(options);
103 if( null == font ) {
105 }
106 System.err.println("Font: "+font.getFullFamilyName());
107
108 final GLCapabilities reqCaps = options.getGLCaps();
109 System.out.println("Requested: " + reqCaps);
110
111 final GLWindow window = GLWindow.create(reqCaps);
112 // window.setPosition(10, 10);
113 window.setSize(options.surface_width, options.surface_height);
114 window.setTitle(UIShapeDemo01.class.getSimpleName()+": "+window.getSurfaceWidth()+" x "+window.getSurfaceHeight());
115 final UIShapeDemo01 uiGLListener = new UIShapeDemo01(font, options.renderModes, DEBUG, TRACE);
116 uiGLListener.attachInputListenerTo(window);
117 window.addGLEventListener(uiGLListener);
118 window.setVisible(true);
119
120 final Animator animator = new Animator(0 /* w/o AWT */);
121 animator.setUpdateFPSFrames(5*60, null);
122 animator.add(window);
123
124 window.addKeyListener(new KeyAdapter() {
125 @Override
126 public void keyPressed(final KeyEvent arg0) {
127 final short keySym = arg0.getKeySymbol();
128 if( keySym == KeyEvent.VK_F4 || keySym == KeyEvent.VK_ESCAPE || keySym == KeyEvent.VK_Q ) {
129 new InterruptSource.Thread( () -> { window.destroy(); } ).start();
130 }
131 }
132 });
133 window.addWindowListener(new WindowAdapter() {
134 @Override
135 public void windowDestroyed(final WindowEvent e) {
136 animator.stop();
137 }
138 });
139
140 animator.start();
141 }
142
143 private final Font font;
144 private final GLReadBufferUtil screenshot;
145 private final int renderModes;
146 private final RegionRenderer rRenderer;
147 private final boolean debug;
148 private final boolean trace;
149
150 private final Button button;
151 private final CrossHair crossHair;
152
153 private KeyAction keyAction;
154 private MouseAction mouseAction;
155
156 private volatile GLAutoDrawable autoDrawable = null;
157
158 private final float[] position = new float[] {0,0,0};
159
160 private static final float xTran = 0f;
161 private static final float yTran = 0f;
162 private static final float zTran = -1/5f;
163 private static final float zNear = 0.1f;
164 private static final float zFar = 7000.0f;
165
166 boolean ignoreInput = false;
167
168 protected final AffineTransform tempT1 = new AffineTransform();
169 protected final AffineTransform tempT2 = new AffineTransform();
170
171 public UIShapeDemo01(final Font font, final int renderModes, final boolean debug, final boolean trace) {
172 this.font = font;
173 this.renderModes = renderModes;
175 this.rRenderer.setAAQuality(options.graphAAQuality);
176 this.rRenderer.setSampleCount(options.graphAASamples);
177 this.debug = debug;
178 this.trace = trace;
179 this.screenshot = new GLReadBufferUtil(false, false);
180
181 final float sz1_w = 1/8f;
182 final float sz2 = 1/20f;
183 button = new Button(renderModes, font, "Click me!", sz1_w, sz1_w/2f);
184 button.setLabelColor(0.0f,0.0f,0.0f, 1.0f);
185 /** Button defaults !
186 button.setLabelColor(1.0f,1.0f,1.0f);
187 button.setButtonColor(0.6f,0.6f,0.6f);
188 button.setCorner(1.0f);
189 button.setSpacing(2.0f);
190 */
191 System.err.println(button);
192 crossHair = new CrossHair(renderModes, sz2, sz2, 1/1000f);
193 crossHair.setColor(0f,0f,1f,1f);
194 crossHair.setVisible(true);
195 }
196
197 public final RegionRenderer getRegionRenderer() { return rRenderer; }
198 public final float[] getPosition() { return position; }
199
200 @Override
201 public void init(final GLAutoDrawable drawable) {
202 autoDrawable = drawable;
203 GL2ES2 gl = drawable.getGL().getGL2ES2();
204 if(debug) {
205 gl = gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Debug", null, gl, null) ).getGL2ES2();
206 }
207 if(trace) {
208 gl = gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Trace", null, gl, new Object[] { System.err } ) ).getGL2ES2();
209 }
210 gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
212
213 gl.setSwapInterval(1);
215 // gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
216 MSAATool.dump(drawable);
217 }
218
219 @Override
220 public void reshape(final GLAutoDrawable drawable, final int xstart, final int ystart, final int width, final int height) {
221 // final GL2ES2 gl = drawable.getGL().getGL2ES2();
222 // gl.glViewport(xstart, ystart, width, height);
223
224 rRenderer.reshapePerspective(FloatUtil.QUARTER_PI, width, height, zNear, zFar);
225 // rRenderer.reshapeOrtho(width, height, zNear, zFar);
226
227 final PMVMatrix4f pmv = rRenderer.getMatrix();
228 pmv.loadMvIdentity();
229 pmv.translateMv(xTran, yTran, zTran);
230
231 if( drawable instanceof Window ) {
232 ((Window)drawable).setTitle(UIShapeDemo01.class.getSimpleName()+": "+drawable.getSurfaceWidth()+" x "+drawable.getSurfaceHeight());
233 }
234 }
235
236 private void drawShape(final GL2ES2 gl, final RegionRenderer renderer, final Shape shape) {
237 final PMVMatrix4f pmv = renderer.getMatrix();
238 pmv.pushMv();
239 shape.applyMatToMv(pmv);
240 shape.draw(gl, renderer);
241 if( once ) {
242 System.err.println("draw.0: "+shape);
243 final int[] winSize = shape.getSurfaceSize(pmv, renderer.getViewport(), new int[2]);
244 System.err.println("draw.1: surfaceSize "+winSize[0]+" x "+winSize[1]);
245 final int[] winPos = shape.shapeToWinCoord(pmv, renderer.getViewport(), shape.getPosition(), new int[2]);
246 System.err.println("draw.2: winCoord "+winPos[0]+" x "+winPos[1]);
247 }
248 pmv.popMv();
249 }
250
251 @Override
252 public void display(final GLAutoDrawable drawable) {
253 final GL2ES2 gl = drawable.getGL().getGL2ES2();
254
255 gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
257
258 final RegionRenderer renderer = getRegionRenderer();
259 final PMVMatrix4f pmv = renderer.getMatrix();
260 renderer.enable(gl, true);
261 drawShape(gl, renderer, button);
262 drawShape(gl, renderer, crossHair);
263 {
264 final String text = "Hello Origin.";
265 final float full_width_o;
266 {
267 final float orthoDist = -zTran; // assume orthogonal plane at -zTran
268 float glWinX = 0;
269 float glWinY = 0;
270 final float winZ = FloatUtil.getOrthoWinZ(orthoDist, zNear, zFar);
271 final Vec3f objCoord0 = new Vec3f();
272 final Vec3f objCoord1 = new Vec3f();
273 if( pmv.mapWinToObj(glWinX, glWinY, winZ, renderer.getViewport(), objCoord0) ) {
274 if( once ) {
275 System.err.printf("winToObjCoord: win [%f, %f, %f] -> obj [%s]%n", glWinX, glWinY, winZ, objCoord0);
276 }
277 }
278 glWinX = drawable.getSurfaceWidth();
279 glWinY = drawable.getSurfaceHeight();
280 if( pmv.mapWinToObj(glWinX, glWinY, winZ, renderer.getViewport(), objCoord1) ) {
281 if( once ) {
282 System.err.printf("winToObjCoord: win [%f, %f, %f] -> obj [%s]%n", glWinX, glWinY, winZ, objCoord1);
283 }
284 }
285 full_width_o = objCoord1.x() - objCoord0.x();
286 }
287 final AABBox txt_box_em = font.getGlyphBounds(text, tempT1, tempT2);
288 final float full_width_s = full_width_o / txt_box_em.getWidth();
289 final float txt_scale = full_width_s/2f;
290 pmv.pushMv();
291 pmv.scaleMv(txt_scale, txt_scale, 1f);
292 pmv.translateMv(-txt_box_em.getWidth(), 0f, 0f);
293 final AABBox txt_box_r = TextRegionUtil.drawString3D(gl, renderModes, renderer, font, text, new Vec4f( 0, 0, 0, 1 ));
294 if( once ) {
295 final AABBox txt_box_em2 = font.getGlyphShapeBounds(null, text);
296 System.err.println("XXX: full_width: "+full_width_o+" / "+txt_box_em.getWidth()+" -> "+full_width_s);
297 System.err.println("XXX: txt_box_em "+txt_box_em);
298 System.err.println("XXX: txt_box_e2 "+txt_box_em2);
299 System.err.println("XXX: txt_box_rg "+txt_box_r);
300 }
301 pmv.popMv();
302 }
303 once = false;
304 renderer.enable(gl, false);
305 }
306 static boolean once = true;
307
308 @Override
309 public void dispose(final GLAutoDrawable drawable) {
310 final GL2ES2 gl = drawable.getGL().getGL2ES2();
311 button.destroy(gl, getRegionRenderer());
312 crossHair.destroy(gl, getRegionRenderer());
313
314 autoDrawable = null;
315 screenshot.dispose(gl);
316 rRenderer.destroy(gl);
317 }
318
319 /** Attach the input listener to the window */
320 public void attachInputListenerTo(final GLWindow window) {
321 if ( null == keyAction ) {
322 keyAction = new KeyAction();
323 window.addKeyListener(keyAction);
324 }
325 if ( null == mouseAction ) {
326 mouseAction = new MouseAction();
327 window.addMouseListener(mouseAction);
328 }
329 }
330
331 public void detachFrom(final GLWindow window) {
332 if ( null == keyAction ) {
333 return;
334 }
335 if ( null == mouseAction ) {
336 return;
337 }
338 window.removeGLEventListener(this);
339 window.removeKeyListener(keyAction);
340 window.removeMouseListener(mouseAction);
341 }
342
343 public void printScreen(final GLAutoDrawable drawable, final String dir, final String tech, final String objName, final boolean exportAlpha) throws GLException, IOException {
344 final String sw = String.format("-%03dx%03d-Z%04d-T%04d-%s", drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), (int)Math.abs(zTran), 0, objName);
345
346 final String filename = dir + tech + sw +".png";
347 if(screenshot.readPixels(drawable.getGL(), false)) {
348 screenshot.write(new File(filename));
349 }
350 }
351
352 int screenshot_num = 0;
353
354 public void setIgnoreInput(final boolean v) {
355 ignoreInput = v;
356 }
357 public boolean getIgnoreInput() {
358 return ignoreInput;
359 }
360
361 public class MouseAction implements MouseListener{
362
363 @Override
364 public void mouseClicked(final MouseEvent e) {
365
366 }
367
368 @Override
369 public void mouseEntered(final MouseEvent e) {
370 }
371
372 @Override
373 public void mouseExited(final MouseEvent e) {
374 }
375
376 @Override
377 public void mousePressed(final MouseEvent e) {
378 autoDrawable.invoke(false, new GLRunnable() { // avoid data-race
379 @Override
380 public boolean run(final GLAutoDrawable drawable) {
381 System.err.println("\n\nMouse: "+e);
382
383 final RegionRenderer renderer = getRegionRenderer();
384 final PMVMatrix4f pmv = renderer.getMatrix();
385 pmv.loadMvIdentity();
386 pmv.translateMv(xTran, yTran, zTran);
387
388 // flip to GL window coordinates, origin bottom-left
389 final Recti viewport = renderer.getViewport(new Recti());
390 final int glWinX = e.getX();
391 final int glWinY = viewport.height() - e.getY() - 1;
392
393 {
394 pmv.pushMv();
395 button.applyMatToMv(pmv);
396
397 System.err.println("\n\nButton: "+button);
398 final Vec3f objPos = button.winToShapeCoord(pmv, viewport, glWinX, glWinY, new Vec3f());
399 if( null != objPos ) {
400 System.err.println("Button: Click: Win "+glWinX+"/"+glWinY+" -> Obj "+objPos);
401 }
402
403 final int[] surfaceSize = button.getSurfaceSize(pmv, viewport, new int[2]);
404 if( null != surfaceSize ) {
405 System.err.println("Button: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]);
406 }
407
408 pmv.popMv();
409 }
410 {
411 pmv.pushMv();
412 crossHair.applyMatToMv(pmv);
413
414 final Vec3f objPosC = crossHair.getBounds().getCenter();
415 System.err.println("\n\nCrossHair: "+crossHair);
416 final int[] objWinPos = crossHair.shapeToWinCoord(pmv, viewport, objPosC, new int[2]);
417 System.err.println("CrossHair: Obj: Obj "+objPosC+" -> Win "+objWinPos[0]+"/"+objWinPos[1]);
418
419 final Vec3f objPos2 = crossHair.winToShapeCoord(pmv, viewport, objWinPos[0], objWinPos[1], new Vec3f());
420 System.err.println("CrossHair: Obj: Win "+objWinPos[0]+"/"+objWinPos[1]+" -> Obj "+objPos2);
421
422 final Vec3f winObjPos = crossHair.winToShapeCoord(pmv, viewport, glWinX, glWinY, new Vec3f());
423 if( null != winObjPos ) {
424 // final float[] translate = crossHair.getTranslate();
425 // final float[] objPosT = new float[] { objPosC[0]+translate[0], objPosC[1]+translate[1], objPosC[2]+translate[2] };
426 final Vec3f diff = winObjPos.minus(objPosC);
427 if( !FloatUtil.isZero(diff.x()) || !FloatUtil.isZero(diff.y()) ) {
428 System.err.println("CrossHair: Move.1: Win "+glWinX+"/"+glWinY+" -> Obj "+winObjPos+" -> diff "+diff);
429 crossHair.move(diff.x(), diff.y(), 0f);
430 } else {
431 System.err.println("CrossHair: Move.0: Win "+glWinX+"/"+glWinY+" -> Obj "+winObjPos+" -> diff "+diff);
432 }
433 }
434
435 final int[] surfaceSize = crossHair.getSurfaceSize(pmv, viewport, new int[2]);
436 System.err.println("CrossHair: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]);
437
438 pmv.popMv();
439 }
440 return true;
441 } } );
442
443 }
444
445 @Override
446 public void mouseReleased(final MouseEvent e) {
447 }
448
449 @Override
450 public void mouseMoved(final MouseEvent e) {
451 }
452
453 @Override
454 public void mouseDragged(final MouseEvent e) {
455 }
456
457 @Override
458 public void mouseWheelMoved(final MouseEvent e) {
459 }
460
461 }
462
463 public class KeyAction implements KeyListener {
464 @Override
465 public void keyPressed(final KeyEvent arg0) {
466 if(ignoreInput) {
467 return;
468 }
469
470 if(arg0.getKeyCode() == KeyEvent.VK_1){
471 button.move(0f, 0f, -zTran/10f);
472 }
473 else if(arg0.getKeyCode() == KeyEvent.VK_2){
474 button.move(0f, 0f, zTran/10f);
475 }
476 else if(arg0.getKeyCode() == KeyEvent.VK_UP){
477 button.move(0f, button.getHeight()/10f, 0f);
478 }
479 else if(arg0.getKeyCode() == KeyEvent.VK_DOWN){
480 button.move(0f, -button.getHeight()/10f, 0f);
481 }
482 else if(arg0.getKeyCode() == KeyEvent.VK_LEFT){
483 button.move(-button.getWidth()/10f, 0f, 0f);
484 }
485 else if(arg0.getKeyCode() == KeyEvent.VK_RIGHT){
486 button.move(button.getWidth()/10f, 0f, 0f);
487 }
488 else if(arg0.getKeyCode() == KeyEvent.VK_4){
489 button.setSpacing(button.getSpacing().x()-0.01f, button.getSpacing().y()-0.005f);
490 System.err.println("Button Spacing: " + button.getSpacing());
491 }
492 else if(arg0.getKeyCode() == KeyEvent.VK_5){
493 button.setSpacing(button.getSpacing().x()+0.01f, button.getSpacing().y()+0.005f);
494 System.err.println("Button Spacing: " + button.getSpacing());
495 }
496 else if(arg0.getKeyCode() == KeyEvent.VK_6){
497 button.setCorner(button.getCorner()-0.01f);
498 System.err.println("Button Corner: " + button.getCorner());
499 }
500 else if(arg0.getKeyCode() == KeyEvent.VK_7){
501 button.setCorner(button.getCorner()+0.01f);
502 System.err.println("Button Corner: " + button.getCorner());
503 }
504 else if(arg0.getKeyCode() == KeyEvent.VK_0){
505 // rotate(1);
506 }
507 else if(arg0.getKeyCode() == KeyEvent.VK_9){
508 // rotate(-1);
509 }
510 else if(arg0.getKeyCode() == KeyEvent.VK_V) {
511 if(null != autoDrawable) {
512 autoDrawable.invoke(false, new GLRunnable() {
513 @Override
514 public boolean run(final GLAutoDrawable drawable) {
515 final GL gl = drawable.getGL();
516 final int _i = gl.getSwapInterval();
517 final int i;
518 switch(_i) {
519 case 0: i = 1; break;
520 case 1: i = -1; break;
521 case -1: i = 0; break;
522 default: i = 1; break;
523 }
524 gl.setSwapInterval(i);
525
526 final GLAnimatorControl a = drawable.getAnimator();
527 if( null != a ) {
528 a.resetFPSCounter();
529 }
530 if(drawable instanceof FPSCounter) {
531 ((FPSCounter)drawable).resetFPSCounter();
532 }
533 System.err.println("Swap Interval: "+_i+" -> "+i+" -> "+gl.getSwapInterval());
534 return true;
535 }
536 });
537 }
538 }
539 else if(arg0.getKeyCode() == KeyEvent.VK_S){
540 if(null != autoDrawable) {
541 autoDrawable.invoke(false, new GLRunnable() {
542 @Override
543 public boolean run(final GLAutoDrawable drawable) {
544 try {
545 final String type = Region.getRenderModeString(renderModes);
546 printScreen(drawable, "./", "demo-"+type, "snap"+screenshot_num, false);
547 screenshot_num++;
548 } catch (final GLException e) {
549 e.printStackTrace();
550 } catch (final IOException e) {
551 e.printStackTrace();
552 }
553 return true;
554 }
555 });
556 }
557 }
558 }
559 @Override
560 public void keyReleased(final KeyEvent arg0) {}
561 }
562}
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
Definition: Region.java:62
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
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}.
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 Vec3f getPosition()
Returns position Vec3f reference, i.e.
Definition: Shape.java:587
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 setVisible(final boolean v)
Enable (default) or disable this shape's visibility.
Definition: Shape.java:363
BaseButton setCorner(final float corner)
Set corner size with range [0.01 .
Definition: BaseButton.java:95
A GraphUI text labeled BaseButton GraphShape.
Definition: Button.java:61
final Button setLabelColor(final Vec4f c)
Sets the label color, consider using alpha 1.
Definition: Button.java:333
final Button setSpacing(final float spacingX, final float spacingY)
Sets spacing in percent of text label, clipped to range [0 .
Definition: Button.java:300
final Vec2f getSpacing()
Returns the current spacing size, see {@Link setSpacing(Vec2f)} and setSpacing(Vec2f,...
Definition: Button.java:291
A GraphUI Crosshair GraphShape.
Definition: CrossHair.java:41
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 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.
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_4
See VK_0.
Definition: KeyEvent.java:561
static final short VK_9
See VK_0.
Definition: KeyEvent.java:571
static final short VK_5
See VK_0.
Definition: KeyEvent.java:563
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
static final short VK_7
See VK_0.
Definition: KeyEvent.java:567
static final short VK_6
See VK_0.
Definition: KeyEvent.java:565
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...
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 mouseEntered(final MouseEvent e)
Only generated for PointerType#Mouse.
void mouseWheelMoved(final MouseEvent e)
Traditional event name originally produced by a mouse pointer type.
void mouseExited(final MouseEvent e)
Only generated for PointerType#Mouse.
Basic UIShape and Type Rendering demo.
void attachInputListenerTo(final GLWindow window)
Attach the input listener to the window.
static void main(final String[] args)
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
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 display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void printScreen(final GLAutoDrawable drawable, final String dir, final String tech, final String objName, final boolean exportAlpha)
UIShapeDemo01(final Font font, final int renderModes, final boolean debug, final boolean trace)
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
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.
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.
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
Interface wrapper for font implementation.
Definition: Font.java:60
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.
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_...
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