JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
PointsDemoES1.java
Go to the documentation of this file.
1/**
2 * Copyright 2012 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 */
28package com.jogamp.opengl.test.junit.jogl.demos.es1;
29
30import java.nio.FloatBuffer;
31
32import com.jogamp.common.nio.Buffers;
33import com.jogamp.opengl.test.junit.jogl.demos.PointsDemo;
34import com.jogamp.opengl.util.GLArrayDataServer;
35import com.jogamp.opengl.util.PMVMatrix;
36import com.jogamp.opengl.util.glsl.fixedfunc.FixedFuncUtil;
37import com.jogamp.opengl.util.glsl.fixedfunc.ShaderSelectionMode;
38
39import com.jogamp.opengl.GL;
40import com.jogamp.opengl.GL2ES1;
41import com.jogamp.opengl.GL2ES2;
42import com.jogamp.opengl.GLAutoDrawable;
43import com.jogamp.opengl.GLPipelineFactory;
44import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
45import com.jogamp.opengl.fixedfunc.GLPointerFunc;
46import com.jogamp.opengl.glu.GLU;
47import com.jogamp.opengl.glu.gl2es1.GLUgl2es1;
48
49public class PointsDemoES1 extends PointsDemo {
50 final static GLU glu = new GLUgl2es1();
51 private boolean debugFFPEmu = false;
52 private boolean verboseFFPEmu = false;
53 private boolean traceFFPEmu = false;
54 private boolean forceFFPEmu = false;
55 private boolean debug = false ;
56 private boolean trace = false ;
57 GLArrayDataServer vertices ;
58 float[] pointSizes ;
59 private int swapInterval = 0;
60 final int edge = 8; // 8*8
61 boolean smooth = false;
62
63 public PointsDemoES1(final int swapInterval) {
64 this.swapInterval = swapInterval;
65 }
66
67 public PointsDemoES1() {
68 this.swapInterval = 1;
69 }
70
71 public void setForceFFPEmu(final boolean forceFFPEmu, final boolean verboseFFPEmu, final boolean debugFFPEmu, final boolean traceFFPEmu) {
72 this.forceFFPEmu = forceFFPEmu;
73 this.verboseFFPEmu = verboseFFPEmu;
74 this.debugFFPEmu = debugFFPEmu;
75 this.traceFFPEmu = traceFFPEmu;
76 }
77
78 public void setSmoothPoints(final boolean v) { smooth = v; }
79
80 public void init(final GLAutoDrawable glad) {
81 GL _gl = glad.getGL();
82
83 if(debugFFPEmu) {
84 // Debug ..
85 _gl = _gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Debug", GL2ES2.class, _gl, null) );
86 debug = false;
87 }
88 if(traceFFPEmu) {
89 // Trace ..
90 _gl = _gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Trace", GL2ES2.class, _gl, new Object[] { System.err } ) );
91 trace = false;
92 }
93 GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(_gl, ShaderSelectionMode.AUTO, null, forceFFPEmu, verboseFFPEmu);
94
95 if(debug) {
96 try {
97 // Debug ..
98 gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Debug", GL2ES1.class, gl, null) );
99 } catch (final Exception e) {e.printStackTrace();}
100 }
101 if(trace) {
102 try {
103 // Trace ..
104 gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Trace", GL2ES1.class, gl, new Object[] { System.err } ) );
105 } catch (final Exception e) {e.printStackTrace();}
106 }
107
108 System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR));
109 System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER));
110 System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION));
111 System.err.println("GL Profile: "+gl.getGLProfile());
112
113 // Allocate Vertex Array
115 pointSizes = new float[edge*edge];
116 for(int i=0; i<edge; i++) {
117 for(int j=0; j<edge; j++) {
118 final float x = -3+j*0.7f;
119 final float y = -3+i*0.7f;
120 final float p = Math.max(0.000001f, (i*edge+j)*0.5f); // no zero point size!
121 // System.err.println("["+j+"/"+i+"]: "+x+"/"+y+": "+p);
122 vertices.putf(x); vertices.putf(y); vertices.putf( 0);
123 pointSizes[(i*edge+j)] = p;
124 }
125 }
126 vertices.seal(gl, true);
127 vertices.enableBuffer(gl, false);
128
129 // OpenGL Render Settings
130 gl.glEnable(GL.GL_DEPTH_TEST);
131 }
132
133 public void setPointParams(final float minSize, final float maxSize, final float distAttenConst, final float distAttenLinear, final float distAttenQuadratic, final float fadeThreshold) {
134 pointMinSize = minSize;
135 pointMaxSize = maxSize;
136 pointFadeThreshold = fadeThreshold;
137 pointDistAtten.put(0, distAttenConst);
138 pointDistAtten.put(1, distAttenLinear);
139 pointDistAtten.put(2, distAttenQuadratic);
140 }
141
142 /** default values */
143 private float pointMinSize = 0.0f;
144 private float pointMaxSize = 4096.0f;
145 private float pointFadeThreshold = 1.0f;
146 private final FloatBuffer pointDistAtten = Buffers.newDirectFloatBuffer(new float[] { 1.0f, 0.0f, 0.0f });
147
148 public void display(final GLAutoDrawable glad) {
149 final GL2ES1 gl = glad.getGL().getGL2ES1();
150 gl.glClearColor(0f, 0f, 0f, 0f);
153 gl.glLoadIdentity();
154 gl.glTranslatef(0, 0, -10);
155
156 gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f );
157
158 vertices.enableBuffer(gl, true);
159
160 gl.glEnable ( GL.GL_BLEND );
161 gl.glBlendFunc ( GL.GL_SRC_ALPHA, GL.GL_ONE );
162 if(smooth) {
164 } else {
166 }
167 gl.glPointParameterf(GL2ES1.GL_POINT_SIZE_MIN, pointMinSize );
168 gl.glPointParameterf(GL2ES1.GL_POINT_SIZE_MAX, pointMaxSize );
169 gl.glPointParameterf(GL.GL_POINT_FADE_THRESHOLD_SIZE, pointFadeThreshold);
171
172 for(int i=edge*edge-1; i>=0; i--) {
173 gl.glPointSize(pointSizes[i]);
174 gl.glDrawArrays(GL.GL_POINTS, i, 1);
175 }
176
177 vertices.enableBuffer(gl, false);
178 }
179
180 public void reshape(final GLAutoDrawable glad, final int x, final int y, final int width, final int height) {
181 // Thread.dumpStack();
182 final GL2ES1 gl = glad.getGL().getGL2ES1();
183
184 gl.setSwapInterval(swapInterval); // in case switching the drawable (impl. may bound attribute there)
185
186 // Set location in front of camera
188 gl.glLoadIdentity();
189 glu.gluPerspective(45.0F, ( (float) width / (float) height ) / 1.0f, 1.0F, 100.0F);
190 //gl.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
191 }
192
193 public void dispose(final GLAutoDrawable glad) {
194 final GL2ES1 gl = glad.getGL().getGL2ES1();
195 vertices.destroy(gl);
196 vertices = null;
197 }
198}
abstract GL setGL(GL gl)
Sets the GL pipeline object for this GLContext.
Factory for pipelining GL instances.
static final GL create(final String pipelineClazzBaseName, final Class<?> reqInterface, final GL downstream, final Object[] additionalArgs)
Creates a pipelined GL instance using the given downstream downstream and optional arguments addition...
Provides access to the OpenGL Utility Library (GLU).
Definition: GLU.java:43
void gluPerspective(float fovy, float aspect, float zNear, float zFar)
Definition: GLU.java:1362
void setForceFFPEmu(final boolean forceFFPEmu, final boolean verboseFFPEmu, final boolean debugFFPEmu, final boolean traceFFPEmu)
void setPointParams(final float minSize, final float maxSize, final float distAttenConst, final float distAttenLinear, final float distAttenQuadratic, final float fadeThreshold)
void dispose(final GLAutoDrawable glad)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void init(final GLAutoDrawable glad)
Called by the drawable immediately after the OpenGL context is initialized.
void reshape(final GLAutoDrawable glad, final int x, final int y, final int width, final int height)
Called by the drawable during the first repaint after the component has been resized.
void display(final GLAutoDrawable glad)
Called by the drawable to initiate OpenGL rendering by the client.
void seal(final GL gl, final boolean seal)
Convenience method calling seal(boolean) and enableBuffer(GL, boolean).
void enableBuffer(final GL gl, final boolean enable)
Enables the buffer if enable is true, and transfers the data if required.
static GLArrayDataServer createFixed(final int index, final int compsPerElement, final int dataType, final boolean normalized, final int stride, final Buffer buffer, final int vboUsage)
Create a VBO, using a predefined fixed function array index and starting with a given Buffer object i...
Tool to pipeline GL2ES2 into a fixed function emulation implementing GL2ES1.
static final GL2ES1 wrapFixedFuncEmul(final GL gl, final ShaderSelectionMode mode, final PMVMatrix pmvMatrix, final boolean force, final boolean verbose)
AUTO
Auto shader selection, based upon FFP states.
static final int GL_POINT_SIZE_MIN
GL_VERSION_1_4, GL_VERSION_ES_1_0, GL_EXT_point_parameters, GL_SGIS_point_parameters,...
Definition: GL2ES1.java:164
void glPointParameterf(int pname, float param)
Entry point to C language function: void {@native glPointParameterf}(GLenum pname,...
void glPointSize(float size)
Entry point to C language function: void {@native glPointSize}(GLfloat size) Part of GL_VERSION_ES...
static final int GL_POINT_DISTANCE_ATTENUATION
GL_VERSION_1_4, GL_VERSION_ES_1_0, GL_ARB_point_parameters Alias for: GL_POINT_DISTANCE_ATTENUATION_A...
Definition: GL2ES1.java:214
void glPointParameterfv(int pname, FloatBuffer params)
Entry point to C language function: void {@native glPointParameterfv}(GLenum pname,...
static final int GL_POINT_SMOOTH
GL_VERSION_ES_1_0, GL_VERSION_1_0 Define "GL_POINT_SMOOTH" with expression '0x0B10',...
Definition: GL2ES1.java:169
static final int GL_POINT_SIZE_MAX
GL_VERSION_1_4, GL_VERSION_ES_1_0, GL_SGIS_point_parameters, GL_EXT_point_parameters,...
Definition: GL2ES1.java:31
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
GL2ES1 getGL2ES1()
Casts this object to the GL2ES1 interface.
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
GLContext getContext()
Returns the GLContext associated which this GL object.
void glDrawArrays(int mode, int first, int count)
Entry point to C language function: void {@native glDrawArrays}(GLenum mode, GLint first,...
static final int GL_STATIC_DRAW
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_STATI...
Definition: GL.java:673
static final int GL_VERSION
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_VERSION" with express...
Definition: GL.java:190
static final int GL_POINT_FADE_THRESHOLD_SIZE
Common in ES1, GL2 and GL3.
Definition: GL.java:1263
static final int GL_FLOAT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FLOAT" with expressio...
Definition: GL.java:786
void glDisable(int cap)
Entry point to C language function: void {@native glDisable}(GLenum cap) Part of GL_ES_VERSION_2_0...
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,...
static final int GL_SRC_ALPHA
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_SRC_ALPHA" with expre...
Definition: GL.java:379
static final int GL_POINTS
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_POINTS" with expressi...
Definition: GL.java:675
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
static final int GL_RENDERER
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_RENDERER" with expres...
Definition: GL.java:662
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
static final int GL_VENDOR
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_VENDOR" with expressi...
Definition: GL.java:607
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
Subset of OpenGL fixed function pipeline's matrix operations.
static final int GL_PROJECTION
Matrix mode projection.
void glTranslatef(float x, float y, float z)
Translate the current matrix.
static final int GL_MODELVIEW
Matrix mode modelview.
void glLoadIdentity()
Load the current matrix with the identity matrix.
void glMatrixMode(int mode)
Sets the current matrix mode.
void glColor4f(float red, float green, float blue, float alpha)