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.test.junit.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;
38
39import com.jogamp.graph.curve.OutlineShape;
40import com.jogamp.graph.curve.Region;
41import com.jogamp.graph.curve.opengl.GLRegion;
42import com.jogamp.graph.curve.opengl.RenderState;
43import com.jogamp.math.util.PMVMatrix4f;
44import com.jogamp.graph.curve.opengl.RegionRenderer;
45
46/** Demonstrate the rendering of multiple OutlineShapes
47 * into one region
48 *
49 */
51 List<OutlineShape> outlineShapes = new ArrayList<OutlineShape>();
52
53 public GPURegionGLListener10 (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 shape = new OutlineShape();
63 outlineShapes.add(shape);
64 shape.addVertex(0.0f,-10.0f,true);
65 shape.addVertex(15.0f,-10.0f, true);
66 shape.addVertex(10.0f,5.0f, false);
67 shape.addVertex(15.0f,10.0f, true);
68 shape.addVertex(6.0f,15.0f, false);
69 shape.addVertex(5.0f,8.0f, false);
70 shape.addVertex(0.0f,10.0f,true);
71 shape.closeLastOutline(true);
72 shape.addEmptyOutline();
73 shape.addVertex(5.0f,-5.0f,true);
74 shape.addVertex(10.0f,-5.0f, false);
75 shape.addVertex(10.0f,0.0f, true);
76 shape.addVertex(5.0f,0.0f, false);
77 shape.closeLastOutline(true);
78 final int[/*2*/] vertIndexCount = Region.countOutlineShape(shape, new int[2]);
79
80 /** Same shape as above but without any off-curve vertices */
81 shape = new OutlineShape();
82 outlineShapes.add(shape);
83 final float offset = 30;
84 shape.addVertex(offset+0.0f,-10.0f, true);
85 shape.addVertex(offset+17.0f,-10.0f, true);
86 shape.addVertex(offset+11.0f,5.0f, true);
87 shape.addVertex(offset+16.0f,10.0f, true);
88 shape.addVertex(offset+7.0f,15.0f, true);
89 shape.addVertex(offset+6.0f,8.0f, true);
90 shape.addVertex(offset+0.0f,10.0f, true);
91 shape.closeLastOutline(true);
92 shape.addEmptyOutline();
93 shape.addVertex(offset+5.0f,0.0f, true);
94 shape.addVertex(offset+5.0f,-5.0f, true);
95 shape.addVertex(offset+10.0f,-5.0f, true);
96 shape.addVertex(offset+10.0f,0.0f, true);
97 shape.closeLastOutline(true);
98 Region.countOutlineShape(shape, vertIndexCount);
99
100 region = GLRegion.create(glp, getRenderModes(), null, vertIndexCount[0], vertIndexCount[1]);
101 region.addOutlineShapes(outlineShapes, null, null);
102 }
103
104 @Override
105 public void init(final GLAutoDrawable drawable) {
106 super.init(drawable);
107
108 final GL2ES2 gl = drawable.getGL().getGL2ES2();
109
110 gl.setSwapInterval(1);
112 gl.glEnable(GL.GL_BLEND);
113 getRenderer().setColorStatic(0.0f, 0.0f, 0.0f, 1.0f);
114
115 createTestOutline(gl.getGLProfile());
116 }
117
118 @Override
119 public void display(final GLAutoDrawable drawable) {
120 final GL2ES2 gl = drawable.getGL().getGL2ES2();
121
122 gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
124
125 final RegionRenderer regionRenderer = getRenderer();
126
127 final PMVMatrix4f pmv = regionRenderer.getMatrix();
128 pmv.loadMvIdentity();
130 pmv.rotateMv(getAngleRad(), 0, 1, 0);
131 if( weight != regionRenderer.getWeight() ) {
132 regionRenderer.setWeight(weight);
133 }
134 regionRenderer.enable(gl, true);
135 region.draw(gl, regionRenderer);
136 regionRenderer.enable(gl, false);
137
138 }
139}
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.
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.
GPURegionGLListener10(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