JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
UIShapeDemo00.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.IOException;
31
32import com.jogamp.common.util.InterruptSource;
33import com.jogamp.graph.curve.Region;
34import com.jogamp.graph.font.Font;
35import com.jogamp.graph.font.FontFactory;
36import com.jogamp.graph.font.FontSet;
37import com.jogamp.graph.ui.GraphShape;
38import com.jogamp.graph.ui.Scene;
39import com.jogamp.graph.ui.shapes.Button;
40import com.jogamp.math.Recti;
41import com.jogamp.math.geom.AABBox;
42import com.jogamp.math.util.PMVMatrix4f;
43import com.jogamp.newt.event.KeyAdapter;
44import com.jogamp.newt.event.KeyEvent;
45import com.jogamp.newt.event.WindowAdapter;
46import com.jogamp.newt.event.WindowEvent;
47import com.jogamp.newt.opengl.GLWindow;
48import com.jogamp.opengl.GL;
49import com.jogamp.opengl.GLCapabilities;
50import com.jogamp.opengl.GLProfile;
51import com.jogamp.opengl.demos.util.CommandlineOptions;
52import com.jogamp.opengl.util.Animator;
53
54/**
55 * Res independent Shape, Scene attached to GLWindow showing simple shape.
56 * <p>
57 * The shape is created using the normalized scene's default bounding box, normalized to 1 for the greater of width and height.
58 * </p>
59 */
60public class UIShapeDemo00 {
61 static CommandlineOptions options = new CommandlineOptions(1280, 720, Region.VBAA_RENDERING_BIT);
62
63 public static void main(final String[] args) throws IOException {
64 options.parse(args);
65 System.err.println(options);
66 final GLProfile reqGLP = GLProfile.get(options.glProfileName);
67 System.err.println("GLProfile: "+reqGLP);
68
69 // Resolution independent, no screen size
70 //
72 System.err.println("Font: "+font.getFullFamilyName());
73
74 final GraphShape shape = new Button(options.renderModes, font, "Hello JogAmp", 0.30f, 0.30f/2.5f); // normalized: 1 is 100% surface size (width and/or height)
75 System.err.println("Shape bounds "+shape.getBounds(reqGLP));
76
77 final Scene scene = new Scene(options.graphAASamples);
78 scene.setPMVMatrixSetup(new MyPMVMatrixSetup());
79 scene.setClearParams(new float[] { 1f, 1f, 1f, 1f}, GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
80 scene.addShape(shape);
81 scene.setAAQuality(options.graphAAQuality);
82
83 final Animator animator = new Animator(0 /* w/o AWT */);
84
85 final GLCapabilities caps = new GLCapabilities(reqGLP);
86 caps.setAlphaBits(4);
87 System.out.println("Requested: " + caps);
88
89 final GLWindow window = GLWindow.create(caps);
90 window.setSize(options.surface_width, options.surface_height);
91 window.setTitle(UIShapeDemo00.class.getSimpleName()+": "+window.getSurfaceWidth()+" x "+window.getSurfaceHeight());
92 window.setVisible(true);
93 window.addGLEventListener(scene);
94 window.addWindowListener(new WindowAdapter() {
95 @Override
96 public void windowResized(final WindowEvent e) {
97 window.setTitle(UIShapeDemo00.class.getSimpleName()+": "+window.getSurfaceWidth()+" x "+window.getSurfaceHeight());
98 }
99 @Override
100 public void windowDestroyNotify(final WindowEvent e) {
101 animator.stop();
102 }
103 });
104
105 scene.attachInputListenerTo(window);
106 window.addKeyListener(new KeyAdapter() {
107 @Override
108 public void keyPressed(final KeyEvent arg0) {
109 final short keySym = arg0.getKeySymbol();
110 if( keySym == KeyEvent.VK_RIGHT ) {
111 scene.setAAQuality( scene.getAAQuality() + 1 );
112 System.err.println("AA Quality "+scene.getAAQuality());
113 } else if( keySym == KeyEvent.VK_LEFT ) {
114 scene.setAAQuality( scene.getAAQuality() - 1 );
115 System.err.println("AA Quality "+scene.getAAQuality());
116 } else if( keySym == KeyEvent.VK_UP ) {
117 scene.setSampleCount(scene.getSampleCount() + 1); // validated / clipped
118 System.err.println("AA Samples "+scene.getSampleCount());
119 } else if( keySym == KeyEvent.VK_DOWN ) {
120 scene.setSampleCount(scene.getSampleCount() - 1); // validated / clipped
121 System.err.println("AA Samples "+scene.getSampleCount());
122 } else if( keySym == KeyEvent.VK_F4 || keySym == KeyEvent.VK_ESCAPE || keySym == KeyEvent.VK_Q ) {
123 new InterruptSource.Thread( () -> { window.destroy(); } ).start();
124 }
125 }
126 });
127 window.addWindowListener(new WindowAdapter() {
128 @Override
129 public void windowDestroyed(final WindowEvent e) {
130 animator.stop();
131 }
132 });
133
134 animator.add(window);
135 animator.start();
136 }
137
138 static class MyPMVMatrixSetup extends Scene.DefaultPMVMatrixSetup {
139 @Override
140 public void set(final PMVMatrix4f pmv, final Recti viewport) {
141 super.set(pmv, viewport);
142
143 // Scale (back) to have normalized plane dimensions, 1 for the greater of width and height.
144 final AABBox planeBox0 = new AABBox();
145 setPlaneBox(planeBox0, pmv, viewport);
146 final float sx = planeBox0.getWidth();
147 final float sy = planeBox0.getHeight();
148 final float sxy = sx > sy ? sx : sy;
149 pmv.scaleP(sxy, sxy, 1f);
150 }
151 };
152
153}
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
Definition: Region.java:62
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:115
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
GraphUI Scene.
Definition: Scene.java:102
void addShape(final Shape s)
Adds a Shape.
Definition: Scene.java:287
final void setClearParams(final float[] clearColor, final int clearMask)
Sets the clear parameter for glClearColor(..) and glClear(..) to be issued at display(GLAutoDrawable)...
Definition: Scene.java:221
int setSampleCount(final int v)
Sets RegionRenderer#setSampleCount(int).
Definition: Scene.java:375
int getSampleCount()
Returns RegionRenderer#getSampleCount().
Definition: Scene.java:370
int setAAQuality(final int v)
Sets RegionRenderer#setAAQuality(int).
Definition: Scene.java:383
final void setPMVMatrixSetup(final PMVMatrixSetup setup)
Set a custom PMVMatrixSetup.
Definition: Scene.java:745
synchronized void attachInputListenerTo(final GLWindow window)
Definition: Scene.java:246
int getAAQuality()
Returns RegionRenderer#getAAQuality().
Definition: Scene.java:378
final AABBox getBounds()
Returns the unscaled bounding AABBox for this shape, borrowing internal instance.
Definition: Shape.java:732
A GraphUI text labeled BaseButton GraphShape.
Definition: Button.java:61
Rectangle with x, y, width and height integer components.
Definition: Recti.java:34
Axis Aligned Bounding Box.
Definition: AABBox.java:54
final float getWidth()
Definition: AABBox.java:879
final float getHeight()
Definition: AABBox.java:883
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
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_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_Q
See VK_A.
Definition: KeyEvent.java:627
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 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 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.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
Res independent Shape, Scene attached to GLWindow showing simple shape.
static void main(final String[] args)
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 synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368
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
String getFullFamilyName()
Shall return the family and subfamily name, separated a dash.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" wit...
Definition: GL.java:738