JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
GPURegionNewtDemo.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 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 */
28
29package com.jogamp.opengl.demos.graph;
30
31import com.jogamp.opengl.GLCapabilities;
32import com.jogamp.opengl.GLProfile;
33import com.jogamp.opengl.demos.util.MiscUtils;
34import com.jogamp.common.util.InterruptSource;
35import com.jogamp.graph.curve.Region;
36import com.jogamp.newt.event.KeyAdapter;
37import com.jogamp.newt.event.KeyEvent;
38import com.jogamp.newt.event.WindowAdapter;
39import com.jogamp.newt.event.WindowEvent;
40import com.jogamp.newt.opengl.GLWindow;
41import com.jogamp.opengl.util.Animator;
42
43/** Demonstrate the rendering of multiple outlines into one region/OutlineShape
44 * These Outlines are not necessary connected or contained.
45 * The output of this demo shows two identical shapes but the left one
46 * has some vertices with off-curve flag set to true, and the right allt he vertices
47 * are on the curve. Demos the Res. Independent Nurbs based Curve rendering
48 *
49 */
50public class GPURegionNewtDemo {
51 static final boolean DEBUG = false;
52 static final boolean TRACE = false;
53
54 static int shape_ctor_mode = 1;
55 static int SceneMSAASamples = 0;
56 static int GraphVBAASamples = 4;
57 static int GraphMSAASamples = 0;
58 static boolean GraphUseWeight = true;
59
60 public static void main(final String[] args) {
61 int width = 800, height = 400;
62 int x = 10, y = 10;
63 if( 0 != args.length ) {
64 SceneMSAASamples = 0;
65 GraphMSAASamples = 0;
66 GraphVBAASamples = 0;
67 GraphUseWeight = false;
68
69 for(int i=0; i<args.length; i++) {
70 if(args[i].equals("-smsaa")) {
71 i++;
72 SceneMSAASamples = MiscUtils.atoi(args[i], SceneMSAASamples);
73 } else if(args[i].equals("-gmsaa")) {
74 i++;
75 GraphMSAASamples = MiscUtils.atoi(args[i], GraphMSAASamples);
76 GraphVBAASamples = 0;
77 } else if(args[i].equals("-gvbaa")) {
78 i++;
79 GraphMSAASamples = 0;
80 GraphVBAASamples = MiscUtils.atoi(args[i], GraphVBAASamples);
81 } else if(args[i].equals("-gweight")) {
82 GraphUseWeight = true;
83 } else if(args[i].equals("-width")) {
84 i++;
85 width = MiscUtils.atoi(args[i], width);
86 } else if(args[i].equals("-height")) {
87 i++;
88 height = MiscUtils.atoi(args[i], height);
89 } else if(args[i].equals("-x")) {
90 i++;
91 x = MiscUtils.atoi(args[i], x);
92 } else if(args[i].equals("-y")) {
93 i++;
94 y = MiscUtils.atoi(args[i], y);
95 } else if(args[i].equals("-shape_ctor")) {
96 i++;
97 shape_ctor_mode = MiscUtils.atoi(args[i], shape_ctor_mode);
98 }
99 }
100 }
101 System.err.println("Desired win size "+width+"x"+height);
102 System.err.println("Desired win pos "+x+"/"+y);
103 System.err.println("Shape_ctor_mode "+shape_ctor_mode);
104 System.err.println("Scene MSAA Samples "+SceneMSAASamples);
105 System.err.println("Graph MSAA Samples"+GraphMSAASamples);
106 System.err.println("Graph VBAA Samples "+GraphVBAASamples);
107 System.err.println("Graph Weight Mode "+GraphUseWeight);
108
109 final GLProfile glp = GLProfile.getGL2ES2();
110 final GLCapabilities caps = new GLCapabilities(glp);
111 caps.setAlphaBits(4);
112 if( SceneMSAASamples > 0 ) {
113 caps.setSampleBuffers(true);
114 caps.setNumSamples(SceneMSAASamples);
115 }
116 System.out.println("Requested: " + caps);
117
118 int rmode = GraphUseWeight ? Region.VARWEIGHT_RENDERING_BIT : 0;
119 int sampleCount = 0;
120 if( GraphVBAASamples > 0 ) {
121 rmode |= Region.VBAA_RENDERING_BIT;
122 sampleCount += GraphVBAASamples;
123 } else if( GraphMSAASamples > 0 ) {
124 rmode |= Region.MSAA_RENDERING_BIT;
125 sampleCount += GraphMSAASamples;
126 }
127
128 final GLWindow window = GLWindow.create(caps);
129 window.setPosition(x, y);
130 window.setSize(width, height);
131 window.setTitle("GPU Curve Region Newt Demo - graph[vbaa"+GraphVBAASamples+" msaa"+GraphMSAASamples+"], msaa "+SceneMSAASamples);
132
133 final GPURegionGLListener01 regionGLListener = new GPURegionGLListener01 (shape_ctor_mode, rmode, Region.DEFAULT_AA_QUALITY, sampleCount, DEBUG, TRACE);
134 regionGLListener.attachInputListenerTo(window);
135 window.addGLEventListener(regionGLListener);
136 window.setVisible(true);
137
138 //FPSAnimator animator = new FPSAnimator(60);
139 final Animator animator = new Animator(0 /* w/o AWT */);
140 animator.setUpdateFPSFrames(60, System.err);
141 animator.add(window);
142
143 window.addKeyListener(new KeyAdapter() {
144 @Override
145 public void keyPressed(final KeyEvent arg0) {
146 final short keySym = arg0.getKeySymbol();
147 if( keySym == KeyEvent.VK_F4 || keySym == KeyEvent.VK_ESCAPE || keySym == KeyEvent.VK_Q ) {
148 new InterruptSource.Thread( () -> { window.destroy(); } ).start();
149 }
150 }
151 });
152 window.addWindowListener(new WindowAdapter() {
153 @Override
154 public void windowDestroyed(final WindowEvent e) {
155 animator.stop();
156 }
157 });
158
159 animator.start();
160 }
161}
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
Definition: Region.java:62
static final int MSAA_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:95
static final int DEFAULT_AA_QUALITY
Default pass2 AA-quality rendering {@value} for Graph Region AA render-modes: VBAA_RENDERING_BIT.
Definition: Region.java:168
static final int VBAA_RENDERING_BIT
Rendering-Mode bit for Region.
Definition: Region.java:115
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
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
final short getKeySymbol()
Returns the virtual key symbol reflecting the current keyboard layout.
Definition: KeyEvent.java:176
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 void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
Definition: GLWindow.java:525
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 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.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
void setSampleBuffers(final boolean enable)
Defaults to false.
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
Demonstrate the rendering of multiple outlines into one region/OutlineShape These Outlines are not ne...
Demonstrate the rendering of multiple outlines into one region/OutlineShape These Outlines are not ne...
void attachInputListenerTo(final GLWindow window)
Attach the input listener to the window.
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 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
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.