JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
GPURegionGLListener00.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.GLProfile;
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.util.PMVMatrix4f;
41import com.jogamp.graph.curve.opengl.RegionRenderer;
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 */
51 OutlineShape outlineShape = null;
52
53 public GPURegionGLListener00 (final int renderModes, final int aaQuality, final int sampleCount, final boolean debug, final boolean trace) {
56 setMatrix(-20, 00, -50, 0f);
57 getRenderer().setAAQuality(aaQuality);
58 getRenderer().setSampleCount(sampleCount);
59 }
60
61 private void createTestOutline(final GLProfile glp){
62 outlineShape = new OutlineShape();
63 outlineShape.addVertex(0.0f,-10.0f, true);
64 outlineShape.addVertex(15.0f,-10.0f, true);
65 outlineShape.addVertex(10.0f,5.0f, false);
66 outlineShape.addVertex(15.0f,10.0f, true);
67 outlineShape.addVertex(6.0f,15.0f, false);
68 outlineShape.addVertex(5.0f,8.0f, false);
69 outlineShape.addVertex(0.0f,10.0f,true);
70 outlineShape.closeLastOutline(true);
71 outlineShape.addEmptyOutline();
72 outlineShape.addVertex(5.0f,-5.0f,true);
73 outlineShape.addVertex(10.0f,-5.0f, false);
74 outlineShape.addVertex(10.0f,0.0f, true);
75 outlineShape.addVertex(5.0f,0.0f, false);
76 outlineShape.closeLastOutline(true);
77
78 /** Same shape as above but without any off-curve vertices */
79 final float offset = 30;
80 outlineShape.addEmptyOutline();
81 outlineShape.addVertex(offset+0.0f,-10.0f, true);
82 outlineShape.addVertex(offset+17.0f,-10.0f, true);
83 outlineShape.addVertex(offset+11.0f,5.0f, true);
84 outlineShape.addVertex(offset+16.0f,10.0f, true);
85 outlineShape.addVertex(offset+7.0f,15.0f, true);
86 outlineShape.addVertex(offset+6.0f,8.0f, true);
87 outlineShape.addVertex(offset+0.0f,10.0f, true);
88 outlineShape.closeLastOutline(true);
89 outlineShape.addEmptyOutline();
90 outlineShape.addVertex(offset+5.0f,0.0f, true);
91 outlineShape.addVertex(offset+5.0f,-5.0f, true);
92 outlineShape.addVertex(offset+10.0f,-5.0f, true);
93 outlineShape.addVertex(offset+10.0f,0.0f, true);
94 outlineShape.closeLastOutline(true);
95
96 region = GLRegion.create(glp, getRenderModes(), null, outlineShape);
97 region.addOutlineShape(outlineShape, null, region.hasColorChannel() ? getRenderer().getColorStatic(new Vec4f()) : null);
98 }
99
100 @Override
101 public void init(final GLAutoDrawable drawable) {
102 super.init(drawable);
103
104 final GL2ES2 gl = drawable.getGL().getGL2ES2();
105
106 gl.setSwapInterval(1);
108 gl.glEnable(GL.GL_BLEND);
109 getRenderer().setColorStatic(0.0f, 0.0f, 0.0f, 1.0f);
110
111 createTestOutline(gl.getGLProfile());
112 }
113
114 @Override
115 public void display(final GLAutoDrawable drawable) {
116 final GL2ES2 gl = drawable.getGL().getGL2ES2();
117
118 gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
120
121 final RegionRenderer regionRenderer = getRenderer();
122 final PMVMatrix4f pmv = regionRenderer.getMatrix();
123 pmv.loadMvIdentity();
125 pmv.rotateMv(getAngleRad(), 0, 1, 0);
126 if( weight != regionRenderer.getWeight() ) {
127 regionRenderer.setWeight(weight);
128 }
129 regionRenderer.enable(gl, true);
130 region.draw(gl, regionRenderer);
131 regionRenderer.enable(gl, false);
132 }
133}
A Generic shape objects which is defined by a list of Outlines.
final void addVertex(final Vertex v)
Adds a vertex to the last open outline to the shape's tail.
final void closeLastOutline(final boolean closeTail)
Closes the last outline in the shape.
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.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
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.
GPURegionGLListener00(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