JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
GPURegionGLListener10.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 java.util.ArrayList;
32import java.util.List;
33
34import com.jogamp.opengl.GL;
35import com.jogamp.opengl.GL2ES2;
36import com.jogamp.opengl.GLAutoDrawable;
37import com.jogamp.opengl.GLProfile;
38import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
39
40import com.jogamp.graph.curve.OutlineShape;
41import com.jogamp.graph.curve.Region;
42import com.jogamp.graph.curve.opengl.GLRegion;
43import com.jogamp.graph.curve.opengl.RenderState;
44import com.jogamp.math.util.PMVMatrix4f;
45import com.jogamp.graph.curve.opengl.RegionRenderer;
46import com.jogamp.opengl.util.PMVMatrix;
47
48/** Demonstrate the rendering of multiple OutlineShapes
49 * into one region
50 *
51 */
53 List<OutlineShape> outlineShapes = new ArrayList<OutlineShape>();
54
55 public GPURegionGLListener10 (final int renderModes, final int aaQuality, final int sampleCount, final boolean debug, final boolean trace) {
58 setMatrix(-20, 00, -50, 0f);
59 getRenderer().setAAQuality(aaQuality);
60 getRenderer().setSampleCount(sampleCount);
61 }
62
63 private void createTestOutline(final GLProfile glp){
64 OutlineShape shape = new OutlineShape();
65 outlineShapes.add(shape);
66 shape.addVertex(0.0f,-10.0f,true);
67 shape.addVertex(15.0f,-10.0f, true);
68 shape.addVertex(10.0f,5.0f, false);
69 shape.addVertex(15.0f,10.0f, true);
70 shape.addVertex(6.0f,15.0f, false);
71 shape.addVertex(5.0f,8.0f, false);
72 shape.addVertex(0.0f,10.0f,true);
73 shape.closeLastOutline(true);
74 shape.addEmptyOutline();
75 shape.addVertex(5.0f,-5.0f,true);
76 shape.addVertex(10.0f,-5.0f, false);
77 shape.addVertex(10.0f,0.0f, true);
78 shape.addVertex(5.0f,0.0f, false);
79 shape.closeLastOutline(true);
80 final int[/*2*/] vertIndexCount = Region.countOutlineShape(shape, new int[2]);
81
82 /** Same shape as above but without any off-curve vertices */
83 shape = new OutlineShape();
84 outlineShapes.add(shape);
85 final float offset = 30;
86 shape.addVertex(offset+0.0f,-10.0f, true);
87 shape.addVertex(offset+17.0f,-10.0f, true);
88 shape.addVertex(offset+11.0f,5.0f, true);
89 shape.addVertex(offset+16.0f,10.0f, true);
90 shape.addVertex(offset+7.0f,15.0f, true);
91 shape.addVertex(offset+6.0f,8.0f, true);
92 shape.addVertex(offset+0.0f,10.0f, true);
93 shape.closeLastOutline(true);
94 shape.addEmptyOutline();
95 shape.addVertex(offset+5.0f,0.0f, true);
96 shape.addVertex(offset+5.0f,-5.0f, true);
97 shape.addVertex(offset+10.0f,-5.0f, true);
98 shape.addVertex(offset+10.0f,0.0f, true);
99 shape.closeLastOutline(true);
100 Region.countOutlineShape(shape, vertIndexCount);
101
102 region = GLRegion.create(glp, getRenderModes(), null, vertIndexCount[0], vertIndexCount[1]);
103 region.addOutlineShapes(outlineShapes, null, null);
104 }
105
106 @Override
107 public void init(final GLAutoDrawable drawable) {
108 super.init(drawable);
109
110 final GL2ES2 gl = drawable.getGL().getGL2ES2();
111
112 gl.setSwapInterval(1);
114 gl.glEnable(GL.GL_BLEND);
115 getRenderer().setColorStatic(0.0f, 0.0f, 0.0f, 1.0f);
116
117 createTestOutline(gl.getGLProfile());
118 }
119
120 @Override
121 public void display(final GLAutoDrawable drawable) {
122 final GL2ES2 gl = drawable.getGL().getGL2ES2();
123
124 gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
126
127 final RegionRenderer regionRenderer = getRenderer();
128
129 final PMVMatrix4f pmv = regionRenderer.getMatrix();
130 pmv.loadMvIdentity();
132 pmv.rotateMv(getAngleRad(), 0, 1, 0);
133 if( weight != regionRenderer.getWeight() ) {
134 regionRenderer.setWeight(weight);
135 }
136 regionRenderer.enable(gl, true);
137 region.draw(gl, regionRenderer);
138 regionRenderer.enable(gl, false);
139
140 }
141}
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.
Abstract Outline shape representation define the method an OutlineShape(s) is bound and rendered.
Definition: Region.java:62
final void addOutlineShapes(final List< OutlineShape > shapes, final AffineTransform transform, final Vec4f rgbaColor)
Add the given list of OutlineShapes to this region with the given optional AffineTransform.
Definition: Region.java:776
static final int[] countOutlineShape(final OutlineShape shape, final int[] vertIndexCount)
Count required number of vertices and indices adding to given int[2] vertIndexCount array.
Definition: Region.java:572
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.
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 OutlineShapes into one region.
GPURegionGLListener10(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 init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
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