JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
GPURegionGLListener01.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 */
28
29package com.jogamp.opengl.test.junit.graph;
30
31import com.jogamp.opengl.GL;
32import com.jogamp.opengl.GL2ES2;
33import com.jogamp.opengl.GLAutoDrawable;
34import com.jogamp.graph.curve.OutlineShape;
35import com.jogamp.graph.curve.Region;
36import com.jogamp.graph.curve.opengl.GLRegion;
37import com.jogamp.graph.curve.opengl.RenderState;
38import com.jogamp.math.Vec4f;
39import com.jogamp.math.geom.plane.Path2F;
40import com.jogamp.math.geom.plane.WindingRule;
41import com.jogamp.math.util.PMVMatrix4f;
42import com.jogamp.graph.curve.opengl.RegionRenderer;
43
44/** Demonstrate the rendering of multiple outlines into one region/OutlineShape
45 * These Outlines are not necessary connected or contained.
46 * The output of this demo shows two identical shapes but the left one
47 * has some vertices with off-curve flag set to true, and the right allt he vertices
48 * are on the curve. Demos the Res. Independent Nurbs based Curve rendering
49 *
50 */
52 final int shape_ctor_mode;
53 OutlineShape outlineShape = null;
54
55 public GPURegionGLListener01 (final int renderModes, final int aaQuality, final int sampleCount, final boolean debug, final boolean trace) {
56 this(1, renderModes, aaQuality, sampleCount, debug, trace);
57 }
58
59 public GPURegionGLListener01 (final int shape_ctor_mode, final int renderModes, final int aaQuality, final int sampleCount, final boolean debug, final boolean trace) {
61 this.shape_ctor_mode = shape_ctor_mode;
63 setMatrix(-20, 00, -50, 0f);
64 getRenderer().setAAQuality(aaQuality);
65 getRenderer().setSampleCount(sampleCount);
66 }
67
68 private void createTestOutline00(){
69 outlineShape.addVertex(0.0f,-10.0f, true);
70 outlineShape.addVertex(15.0f,-10.0f, true);
71 outlineShape.addVertex(10.0f,5.0f, false);
72 outlineShape.addVertex(15.0f,10.0f, true);
73 outlineShape.addVertex(6.0f,15.0f, false);
74 outlineShape.addVertex(5.0f,8.0f, false);
75 outlineShape.addVertex(0.0f,10.0f,true);
76 outlineShape.closeLastOutline(true);
77 outlineShape.addEmptyOutline();
78 outlineShape.addVertex(5.0f,-5.0f,true);
79 outlineShape.addVertex(10.0f,-5.0f, false);
80 outlineShape.addVertex(10.0f,0.0f, true);
81 outlineShape.addVertex(5.0f,0.0f, false);
82 outlineShape.closeLastOutline(true);
83
84 /** Same shape as above but without any off-curve vertices */
85 final float offset = 30;
86 outlineShape.addEmptyOutline();
87 outlineShape.addVertex(offset+0.0f,-10.0f, true);
88 outlineShape.addVertex(offset+17.0f,-10.0f, true);
89 outlineShape.addVertex(offset+11.0f,5.0f, true);
90 outlineShape.addVertex(offset+16.0f,10.0f, true);
91 outlineShape.addVertex(offset+7.0f,15.0f, true);
92 outlineShape.addVertex(offset+6.0f,8.0f, true);
93 outlineShape.addVertex(offset+0.0f,10.0f, true);
94 outlineShape.closeLastOutline(true);
95 outlineShape.addEmptyOutline();
96 outlineShape.addVertex(offset+5.0f,0.0f, true);
97 outlineShape.addVertex(offset+5.0f,-5.0f, true);
98 outlineShape.addVertex(offset+10.0f,-5.0f, true);
99 outlineShape.addVertex(offset+10.0f,0.0f, true);
100 outlineShape.closeLastOutline(true);
101 }
102
103 private void createTestOutline01(){
104 outlineShape.moveTo(0.0f,-10.0f, 0f);
105 outlineShape.lineTo(15.0f,-10.0f, 0f);
106 outlineShape.quadTo(10.0f,5.0f,0f, 15.0f,10.0f,0f);
107 outlineShape.cubicTo(6.0f,15.0f,0f, 5.0f,8.0f,0f, 0.0f,10.0f,0f);
108 outlineShape.closePath();
109 outlineShape.moveTo(5.0f,-5.0f,0f);
110 outlineShape.quadTo(10.0f,-5.0f,0f, 10.0f,0.0f,0f);
111 outlineShape.quadTo(5.0f,0.0f,0f, 5.0f,-5.0f,0f);
112 outlineShape.closePath();
113
114 /** Same shape as above but without any off-curve vertices */
115 final float offset = 30;
116 outlineShape.moveTo(offset+0.0f,-10.0f,0f);
117 outlineShape.lineTo(offset+17.0f,-10.0f,0f);
118 outlineShape.lineTo(offset+11.0f,5.0f,0f);
119 outlineShape.lineTo(offset+16.0f,10.0f,0f);
120 outlineShape.lineTo(offset+7.0f,15.0f,0f);
121 outlineShape.lineTo(offset+6.0f,8.0f,0f);
122 outlineShape.lineTo(offset+0.0f,10.0f,0f);
123 outlineShape.closePath();
124 outlineShape.moveTo(offset+5.0f,0.0f,0f);
125 outlineShape.lineTo(offset+5.0f,-5.0f,0f);
126 outlineShape.lineTo(offset+10.0f,-5.0f,0f);
127 outlineShape.lineTo(offset+10.0f,0.0f,0f);
128 outlineShape.closePath();
129 }
130
131 private void createTestOutline02(){
132 final Path2F path = new Path2F(WindingRule.NON_ZERO);
133 path.moveTo(0.0f,-10.0f);
134 path.lineTo(15.0f,-10.0f);
135 path.quadTo(10.0f,5.0f, 15.0f,10.0f);
136 path.cubicTo(6.0f,15.0f, 5.0f,8.0f, 0.0f,10.0f);
137 path.closePath();
138 path.moveTo(5.0f,-5.0f);
139 path.quadTo(10.0f,-5.0f, 10.0f,0.0f);
140 path.quadTo(5.0f,0.0f, 5.0f,-5.0f);
141 path.closePath();
142
143 /** Same shape as above but without any off-curve vertices */
144 final float offset = 30;
145 path.moveTo(offset+0.0f,-10.0f);
146 path.lineTo(offset+17.0f,-10.0f);
147 path.lineTo(offset+11.0f,5.0f);
148 path.lineTo(offset+16.0f,10.0f);
149 path.lineTo(offset+7.0f,15.0f);
150 path.lineTo(offset+6.0f,8.0f);
151 path.lineTo(offset+0.0f,10.0f);
152 path.closePath();
153 path.moveTo(offset+5.0f,0.0f);
154 path.lineTo(offset+5.0f,-5.0f);
155 path.lineTo(offset+10.0f,-5.0f);
156 path.lineTo(offset+10.0f,0.0f);
157 path.closePath();
158
159 System.err.println("GPURegionGLListener01.createTestOutline02.X: path "+path);
160 path.printSegments(System.err);
161 outlineShape.addPath(path, false /* connect */);
162 }
163
164 private void createTestOutline03(){
165 {
166 final Path2F path = new Path2F(WindingRule.NON_ZERO);
167 path.moveTo(0.0f,-10.0f);
168 path.lineTo(15.0f,-10.0f);
169 path.quadTo(10.0f,5.0f, 15.0f,10.0f);
170 path.cubicTo(6.0f,15.0f, 5.0f,8.0f, 0.0f,10.0f);
171 path.closePath();
172 System.err.println("GPURegionGLListener01.createTestOutline03.0: path "+path);
173 path.printSegments(System.err);
174 {
175 final Path2F path2 = new Path2F(WindingRule.NON_ZERO);
176 path2.moveTo(5.0f,-5.0f);
177 path2.quadTo(10.0f,-5.0f, 10.0f,0.0f);
178 path2.quadTo(5.0f,0.0f, 5.0f,-5.0f);
179 path2.closePath();
180 System.err.println("GPURegionGLListener01.createTestOutline03.0: path2 "+path2);
181 path2.printSegments(System.err);
182 path.append(path2, false);
183 System.err.println("GPURegionGLListener01.createTestOutline03.1: path "+path);
184 path.printSegments(System.err);
185 }
186 outlineShape.addPath(path, false /* connect */);
187 }
188 {
189 /** Same shape as above but without any off-curve vertices */
190 final float offset = 30;
191 final Path2F path = new Path2F(WindingRule.NON_ZERO);
192 path.moveTo(offset+0.0f,-10.0f);
193 path.lineTo(offset+17.0f,-10.0f);
194 path.lineTo(offset+11.0f,5.0f);
195 path.lineTo(offset+16.0f,10.0f);
196 path.lineTo(offset+7.0f,15.0f);
197 path.lineTo(offset+6.0f,8.0f);
198 path.lineTo(offset+0.0f,10.0f);
199 path.closePath();
200 path.moveTo(offset+5.0f,0.0f);
201 path.lineTo(offset+5.0f,-5.0f);
202 path.lineTo(offset+10.0f,-5.0f);
203 path.lineTo(offset+10.0f,0.0f);
204 path.closePath();
205 System.err.println("GPURegionGLListener01.createTestOutline03.3: path "+path);
206 path.printSegments(System.err);
207 outlineShape.addPath(path, false /* connect */);
208 }
209
210 }
211
212 private void createTestOutline04(){
213 final Path2F path = new Path2F(WindingRule.NON_ZERO);
214
215 path.moveTo(0.0f,10.0f);
216 path.cubicTo(5.0f,8.0f, 6.0f,15.0f, 15.0f,10.0f);
217 path.quadTo(10.0f,5.0f, 15.0f,-10.0f);
218 path.lineTo(0.0f,-10.0f);
219 path.closePath();
220 path.moveTo(5.0f,-5.0f);
221 path.quadTo(5.0f,0.0f, 10.0f,0.0f);
222 path.quadTo(10.0f,-5.0f, 5.0f,-5.0f);
223 path.closePath();
224
225 /** Same shape as above but without any off-curve vertices */
226 final float offset = 30;
227 path.moveTo(offset+0.0f,10.0f);
228 path.lineTo(offset+6.0f,8.0f);
229 path.lineTo(offset+7.0f,15.0f);
230 path.lineTo(offset+16.0f,10.0f);
231 path.lineTo(offset+11.0f,5.0f);
232 path.lineTo(offset+17.0f,-10.0f);
233 path.lineTo(offset+0.0f,-10.0f);
234 path.closePath();
235 path.moveTo(offset+10.0f,0.0f);
236 path.lineTo(offset+10.0f,-5.0f);
237 path.lineTo(offset+5.0f,-5.0f);
238 path.lineTo(offset+5.0f,0.0f);
239 path.closePath();
240
241 System.err.println("GPURegionGLListener01.createTestOutline04.X: path "+path);
242 path.printSegments(System.err);
243 outlineShape.addPathRev(path, false /* connect */);
244 }
245
246 @Override
247 public void init(final GLAutoDrawable drawable) {
248 super.init(drawable);
249
250 final GL2ES2 gl = drawable.getGL().getGL2ES2();
251
252 gl.setSwapInterval(1);
254 gl.glEnable(GL.GL_BLEND);
255 getRenderer().setColorStatic(0.0f, 0.0f, 0.0f, 1.0f);
256
257 outlineShape = new OutlineShape();
258 switch( shape_ctor_mode ) {
259 case 0:
260 createTestOutline00();
261 break;
262 case 2:
263 createTestOutline02();
264 break;
265 case 3:
266 createTestOutline03();
267 break;
268 case 4:
269 createTestOutline04();
270 break;
271 default:
272 createTestOutline01();
273 break;
274 }
275 region = GLRegion.create(gl.getGLProfile(), getRenderModes(), null, outlineShape);
276 region.addOutlineShape(outlineShape, null, region.hasColorChannel() ? getRenderer().getColorStatic(new Vec4f()) : null);
277 }
278
279 @Override
280 public void display(final GLAutoDrawable drawable) {
281 final GL2ES2 gl = drawable.getGL().getGL2ES2();
282
283 gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
285
286 final RegionRenderer regionRenderer = getRenderer();
287 final PMVMatrix4f pmv = regionRenderer.getMatrix();
288 pmv.loadMvIdentity();
290 pmv.rotateMv(getAngleRad(), 0, 1, 0);
291 if( weight != regionRenderer.getWeight() ) {
292 regionRenderer.setWeight(weight);
293 }
294 regionRenderer.enable(gl, true);
295 region.draw(gl, regionRenderer);
296 regionRenderer.enable(gl, false);
297 }
298}
A Generic shape objects which is defined by a list of Outlines.
void addPath(final Path2F path, final boolean connect)
Append the given path geometry to this outline shape.
final void addVertex(final Vertex v)
Adds a vertex to the last open outline to the shape's tail.
final void moveTo(final float x, final float y, final float z)
Start a new position for the next line segment at given point x/y (P1).
final void quadTo(final float x1, final float y1, final float z1, final float x2, final float y2, final float z2)
Add a quadratic curve segment, intersecting the last point and the second given point x2/y2 (P2).
final void lineTo(final float x, final float y, final float z)
Add a line segment, intersecting the last point and the given point x/y (P1).
void addPathRev(final Path2F path, final boolean connect)
Append the given path geometry to this outline shape in reverse order.
final void closeLastOutline(final boolean closeTail)
Closes the last outline in the shape.
final void cubicTo(final float x1, final float y1, final float z1, final float x2, final float y2, final float z2, final float x3, final float y3, final float z3)
Add a cubic Bézier curve segment, intersecting the last point and the second given point x3/y3 (P3).
final void closePath()
Closes the current sub-path segment by drawing a straight line back to the coordinates of the last mo...
final void addEmptyOutline()
Add a new empty Outline to the end of this shape's outline list.
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 boolean hasColorChannel(final int renderModes)
Returns true if render mode has a color channel, i.e.
Definition: Region.java:231
A GLRegion is the OGL binding of one or more OutlineShapes Defined by its vertices and generated tria...
Definition: GLRegion.java:70
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 void setColorStatic(final Vec4f rgbaColor)
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...
static RegionRenderer create()
Create a hardware accelerated RegionRenderer including its RenderState composition.
The RenderState is owned by RegionRenderer.
static final int BITHINT_GLOBAL_DEPTH_TEST_ENABLED
Bitfield hint, if set stating globally enabled GL#GL_DEPTH_TEST, otherwise disabled.
4D Vector based upon four float components.
Definition: Vec4f.java:37
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 rotateMv(final float ang_rad, final float x, final float y, final float z)
Rotate the modelview matrix by the given axis and angle in radians.
final PMVMatrix4f loadMvIdentity()
Load the modelview matrix with the values of the given Matrix4f.
Demonstrate the rendering of multiple outlines into one region/OutlineShape These Outlines are not ne...
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
GPURegionGLListener01(final int renderModes, final int aaQuality, final int sampleCount, final boolean debug, final boolean trace)
GPURegionGLListener01(final int shape_ctor_mode, final int renderModes, final int aaQuality, final int sampleCount, final boolean debug, final boolean trace)
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void setMatrix(final float xtrans, final float ytrans, final float zTran, final float angle)
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
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.
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_BLEND
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_BLEND" with expressio...
Definition: GL.java:704
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