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.demos.graph;
30
31import com.jogamp.opengl.GL;
32import com.jogamp.opengl.GL2ES2;
33import com.jogamp.opengl.GLAutoDrawable;
34import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
35import com.jogamp.graph.curve.OutlineShape;
36import com.jogamp.graph.curve.Region;
37import com.jogamp.graph.curve.opengl.GLRegion;
38import com.jogamp.graph.curve.opengl.RenderState;
39import com.jogamp.math.Vec4f;
40import com.jogamp.math.geom.plane.Path2F;
41import com.jogamp.math.geom.plane.WindingRule;
42import com.jogamp.math.util.PMVMatrix4f;
43import com.jogamp.graph.curve.opengl.RegionRenderer;
44import com.jogamp.opengl.util.PMVMatrix;
45
46/** Demonstrate the rendering of multiple outlines into one region/OutlineShape
47 * These Outlines are not necessary connected or contained.
48 * The output of this demo shows two identical shapes but the left one
49 * has some vertices with off-curve flag set to true, and the right allt he vertices
50 * are on the curve. Demos the Res. Independent Nurbs based Curve rendering
51 *
52 */
54 final int shape_ctor_mode;
55 OutlineShape outlineShape = null;
56
57 public GPURegionGLListener01 (final int renderModes, final int sampleCount, final boolean debug, final boolean trace) {
58 this(1, renderModes, Region.DEFAULT_AA_QUALITY, sampleCount, debug, trace);
59 }
60
61 public GPURegionGLListener01 (final int shape_ctor_mode, final int renderModes, final int aaQuality, final int sampleCount, final boolean debug, final boolean trace) {
63 this.shape_ctor_mode = shape_ctor_mode;
65 setMatrix(-20, 00, -50, 0f);
66 getRenderer().setAAQuality(aaQuality);
67 getRenderer().setSampleCount(sampleCount);
68 }
69
70 private void createTestOutline00(){
71 outlineShape.addVertex(0.0f,-10.0f, true);
72 outlineShape.addVertex(15.0f,-10.0f, true);
73 outlineShape.addVertex(10.0f,5.0f, false);
74 outlineShape.addVertex(15.0f,10.0f, true);
75 outlineShape.addVertex(6.0f,15.0f, false);
76 outlineShape.addVertex(5.0f,8.0f, false);
77 outlineShape.addVertex(0.0f,10.0f,true);
78 outlineShape.closeLastOutline(true);
79 outlineShape.addEmptyOutline();
80 outlineShape.addVertex(5.0f,-5.0f,true);
81 outlineShape.addVertex(10.0f,-5.0f, false);
82 outlineShape.addVertex(10.0f,0.0f, true);
83 outlineShape.addVertex(5.0f,0.0f, false);
84 outlineShape.closeLastOutline(true);
85
86 /** Same shape as above but without any off-curve vertices */
87 final float offset = 30;
88 outlineShape.addEmptyOutline();
89 outlineShape.addVertex(offset+0.0f,-10.0f, true);
90 outlineShape.addVertex(offset+17.0f,-10.0f, true);
91 outlineShape.addVertex(offset+11.0f,5.0f, true);
92 outlineShape.addVertex(offset+16.0f,10.0f, true);
93 outlineShape.addVertex(offset+7.0f,15.0f, true);
94 outlineShape.addVertex(offset+6.0f,8.0f, true);
95 outlineShape.addVertex(offset+0.0f,10.0f, true);
96 outlineShape.closeLastOutline(true);
97 outlineShape.addEmptyOutline();
98 outlineShape.addVertex(offset+5.0f,0.0f, true);
99 outlineShape.addVertex(offset+5.0f,-5.0f, true);
100 outlineShape.addVertex(offset+10.0f,-5.0f, true);
101 outlineShape.addVertex(offset+10.0f,0.0f, true);
102 outlineShape.closeLastOutline(true);
103 System.err.println("createTestOutline00: "+outlineShape);
104 }
105
106 private void createTestOutline01a(){
107 final float lineWidth = 1/2.5f;
108 final float dz = 0.001f;
109 // Rectangle
110 final float width = 1.5f;
111 final float height = 1.5f;
112 final float x1 = -width/2.0f;
113 final float y1 = -height/2.0f;
114 final float x2 = x1 + width;
115 final float y2 = y1 + height;
116 final float z = dz;
117 {
118 // Outer OutlineShape as Winding.CCW.
119 outlineShape.moveTo(x1, y1, z);
120 outlineShape.lineTo(x2, y1, z);
121 outlineShape.lineTo(x2, y2, z);
122 outlineShape.lineTo(x1, y2, z);
123 outlineShape.lineTo(x1, y1, z);
124 outlineShape.closePath();
125 // outlineShape.closeLastOutline(true);
126 }
127 {
128 // Inner OutlineShape as Winding.CW.
129 // final float dxy0 = getWidth() < getHeight() ? getWidth() : getHeight();
130 final float dxy = lineWidth; // dxy0 * getDebugBox();
131 outlineShape.moveTo(x1+dxy, y1+dxy, z);
132 outlineShape.lineTo(x1+dxy, y2-dxy, z);
133 outlineShape.lineTo(x2-dxy, y2-dxy, z);
134 outlineShape.lineTo(x2-dxy, y1+dxy, z);
135 outlineShape.lineTo(x1+dxy, y1+dxy, z);
136 outlineShape.closePath();
137 }
138 System.err.println("createTestOutline01: "+outlineShape);
139 }
140 private void createTestOutline01(){
141 outlineShape.moveTo(0.0f,-10.0f, 0f);
142 outlineShape.lineTo(15.0f,-10.0f, 0f);
143 outlineShape.quadTo(10.0f,5.0f,0f, 15.0f,10.0f,0f);
144 outlineShape.cubicTo(6.0f,15.0f,0f, 5.0f,8.0f,0f, 0.0f,10.0f,0f);
145 outlineShape.closePath();
146 outlineShape.moveTo(5.0f,-5.0f,0f);
147 outlineShape.quadTo(10.0f,-5.0f,0f, 10.0f,0.0f,0f);
148 outlineShape.quadTo(5.0f,0.0f,0f, 5.0f,-5.0f,0f);
149 outlineShape.closePath();
150
151 /** Same shape as above but without any off-curve vertices */
152 final float offset = 30;
153 outlineShape.moveTo(offset+0.0f,-10.0f,0f);
154 outlineShape.lineTo(offset+17.0f,-10.0f,0f);
155 outlineShape.lineTo(offset+11.0f,5.0f,0f);
156 outlineShape.lineTo(offset+16.0f,10.0f,0f);
157 outlineShape.lineTo(offset+7.0f,15.0f,0f);
158 outlineShape.lineTo(offset+6.0f,8.0f,0f);
159 outlineShape.lineTo(offset+0.0f,10.0f,0f);
160 outlineShape.closePath();
161 outlineShape.moveTo(offset+5.0f,0.0f,0f);
162 outlineShape.lineTo(offset+5.0f,-5.0f,0f);
163 outlineShape.lineTo(offset+10.0f,-5.0f,0f);
164 outlineShape.lineTo(offset+10.0f,0.0f,0f);
165 outlineShape.closePath();
166 System.err.println("createTestOutline01b: "+outlineShape);
167 }
168
169 private void createTestOutline02(){
170 final Path2F path = new Path2F(WindingRule.NON_ZERO);
171 path.moveTo(0.0f,-10.0f);
172 path.lineTo(15.0f,-10.0f);
173 path.quadTo(10.0f,5.0f, 15.0f,10.0f);
174 path.cubicTo(6.0f,15.0f, 5.0f,8.0f, 0.0f,10.0f);
175 path.closePath();
176 path.moveTo(5.0f,-5.0f);
177 path.quadTo(10.0f,-5.0f, 10.0f,0.0f);
178 path.quadTo(5.0f,0.0f, 5.0f,-5.0f);
179 path.closePath();
180
181 /** Same shape as above but without any off-curve vertices */
182 final float offset = 30;
183 path.moveTo(offset+0.0f,-10.0f);
184 path.lineTo(offset+17.0f,-10.0f);
185 path.lineTo(offset+11.0f,5.0f);
186 path.lineTo(offset+16.0f,10.0f);
187 path.lineTo(offset+7.0f,15.0f);
188 path.lineTo(offset+6.0f,8.0f);
189 path.lineTo(offset+0.0f,10.0f);
190 path.closePath();
191 path.moveTo(offset+5.0f,0.0f);
192 path.lineTo(offset+5.0f,-5.0f);
193 path.lineTo(offset+10.0f,-5.0f);
194 path.lineTo(offset+10.0f,0.0f);
195 path.closePath();
196
197 System.err.println("GPURegionGLListener01.createTestOutline02.X: path "+path);
198 path.printSegments(System.err);
199 outlineShape.addPath(path, false /* connect */);
200 System.err.println("createTestOutline02: "+outlineShape);
201 }
202
203 private void createTestOutline03(){
204 {
205 final Path2F path = new Path2F(WindingRule.NON_ZERO);
206 path.moveTo(0.0f,-10.0f);
207 path.lineTo(15.0f,-10.0f);
208 path.quadTo(10.0f,5.0f, 15.0f,10.0f);
209 path.cubicTo(6.0f,15.0f, 5.0f,8.0f, 0.0f,10.0f);
210 path.closePath();
211 System.err.println("GPURegionGLListener01.createTestOutline03.0: path "+path);
212 path.printSegments(System.err);
213 {
214 final Path2F path2 = new Path2F(WindingRule.NON_ZERO);
215 path2.moveTo(5.0f,-5.0f);
216 path2.quadTo(10.0f,-5.0f, 10.0f,0.0f);
217 path2.quadTo(5.0f,0.0f, 5.0f,-5.0f);
218 path2.closePath();
219 System.err.println("GPURegionGLListener01.createTestOutline03.0: path2 "+path2);
220 path2.printSegments(System.err);
221 path.append(path2, false);
222 System.err.println("GPURegionGLListener01.createTestOutline03.1: path "+path);
223 path.printSegments(System.err);
224 }
225 outlineShape.addPath(path, false /* connect */);
226 }
227 {
228 /** Same shape as above but without any off-curve vertices */
229 final float offset = 30;
230 final Path2F path = new Path2F(WindingRule.NON_ZERO);
231 path.moveTo(offset+0.0f,-10.0f);
232 path.lineTo(offset+17.0f,-10.0f);
233 path.lineTo(offset+11.0f,5.0f);
234 path.lineTo(offset+16.0f,10.0f);
235 path.lineTo(offset+7.0f,15.0f);
236 path.lineTo(offset+6.0f,8.0f);
237 path.lineTo(offset+0.0f,10.0f);
238 path.closePath();
239 path.moveTo(offset+5.0f,0.0f);
240 path.lineTo(offset+5.0f,-5.0f);
241 path.lineTo(offset+10.0f,-5.0f);
242 path.lineTo(offset+10.0f,0.0f);
243 path.closePath();
244 System.err.println("GPURegionGLListener01.createTestOutline03.3: path "+path);
245 path.printSegments(System.err);
246 outlineShape.addPath(path, false /* connect */);
247 }
248 System.err.println("createTestOutline03: "+outlineShape);
249
250 }
251
252 private void createTestOutline04(){
253 final Path2F path = new Path2F(WindingRule.NON_ZERO);
254
255 path.moveTo(0.0f,10.0f);
256 path.cubicTo(5.0f,8.0f, 6.0f,15.0f, 15.0f,10.0f);
257 path.quadTo(10.0f,5.0f, 15.0f,-10.0f);
258 path.lineTo(0.0f,-10.0f);
259 path.closePath();
260 path.moveTo(5.0f,-5.0f);
261 path.quadTo(5.0f,0.0f, 10.0f,0.0f);
262 path.quadTo(10.0f,-5.0f, 5.0f,-5.0f);
263 path.closePath();
264
265 /** Same shape as above but without any off-curve vertices */
266 final float offset = 30;
267 path.moveTo(offset+0.0f,10.0f);
268 path.lineTo(offset+6.0f,8.0f);
269 path.lineTo(offset+7.0f,15.0f);
270 path.lineTo(offset+16.0f,10.0f);
271 path.lineTo(offset+11.0f,5.0f);
272 path.lineTo(offset+17.0f,-10.0f);
273 path.lineTo(offset+0.0f,-10.0f);
274 path.closePath();
275 path.moveTo(offset+10.0f,0.0f);
276 path.lineTo(offset+10.0f,-5.0f);
277 path.lineTo(offset+5.0f,-5.0f);
278 path.lineTo(offset+5.0f,0.0f);
279 path.closePath();
280
281 System.err.println("GPURegionGLListener01.createTestOutline04.X: path "+path);
282 path.printSegments(System.err);
283 outlineShape.addPathRev(path, false /* connect */);
284
285 System.err.println("createTestOutline04: "+outlineShape);
286 }
287
288 @Override
289 public void init(final GLAutoDrawable drawable) {
290 super.init(drawable);
291
292 final GL2ES2 gl = drawable.getGL().getGL2ES2();
293
294 gl.setSwapInterval(1);
296 gl.glEnable(GL.GL_BLEND);
297 getRenderer().setColorStatic(0.0f, 0.0f, 0.0f, 1.0f);
298
299 outlineShape = new OutlineShape();
300 switch( shape_ctor_mode ) {
301 case 0:
302 createTestOutline00();
303 break;
304 case 2:
305 createTestOutline02();
306 break;
307 case 3:
308 createTestOutline03();
309 break;
310 case 4:
311 createTestOutline04();
312 break;
313 default:
314 createTestOutline01();
315 break;
316 }
317 region = GLRegion.create(gl.getGLProfile(), getRenderModes(), null, outlineShape);
318 region.addOutlineShape(outlineShape, null, region.hasColorChannel() ? getRenderer().getColorStatic(new Vec4f()) : null);
319 }
320
321 @Override
322 public void display(final GLAutoDrawable drawable) {
323 final GL2ES2 gl = drawable.getGL().getGL2ES2();
324
325 gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
327
328 final RegionRenderer regionRenderer = getRenderer();
329 final PMVMatrix4f pmv = regionRenderer.getMatrix();
330 pmv.loadMvIdentity();
332 pmv.rotateMv(getAngleRad(), 0, 1, 0);
333 if( weight != regionRenderer.getWeight() ) {
334 regionRenderer.setWeight(weight);
335 }
336 regionRenderer.enable(gl, true);
337 region.draw(gl, regionRenderer);
338 regionRenderer.enable(gl, false);
339 }
340}
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.
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 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 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...
GPURegionGLListener01(final int renderModes, final int sampleCount, final boolean debug, final boolean trace)
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
GPURegionGLListener01(final int shape_ctor_mode, final int renderModes, final int aaQuality, final int sampleCount, final boolean debug, final boolean trace)
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