JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
OlympicES1.java
Go to the documentation of this file.
1/**
2 * OlympicGL2
3 */
4
5package com.jogamp.opengl.test.junit.jogl.demos.es1;
6
7import com.jogamp.opengl.GL;
8import com.jogamp.opengl.GL2ES1;
9import com.jogamp.opengl.GL2ES2;
10import com.jogamp.opengl.GLAutoDrawable;
11import com.jogamp.opengl.GLEventListener;
12import com.jogamp.opengl.GLPipelineFactory;
13import com.jogamp.opengl.fixedfunc.GLLightingFunc;
14import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
15import com.jogamp.opengl.glu.GLU;
16import com.jogamp.opengl.glu.gl2es1.GLUgl2es1;
17
18import com.jogamp.opengl.util.ImmModeSink;
19import com.jogamp.opengl.util.glsl.fixedfunc.FixedFuncUtil;
20import com.jogamp.opengl.util.glsl.fixedfunc.ShaderSelectionMode;
21
22import java.lang.Math;
23
24public class OlympicES1 implements GLEventListener
25{
26 private boolean debugFFPEmu = false;
27 private boolean verboseFFPEmu = false;
28 private boolean traceFFPEmu = false;
29 private boolean forceFFPEmu = false;
30 private boolean debug = false ;
31 private boolean trace = false ;
32
33 // private static final double M_PI= Math.PI;
34 private static final double M_2PI = 2.0*Math.PI;
35
36 private static final int
37 // XSIZE= 100,
38 // YSIZE= 75,
39 RINGS= 5,
40 BLUERING= 0,
41 BLACKRING= 1,
42 REDRING= 2,
43 YELLOWRING =3,
44 GREENRING =4,
45 // BACKGROUND =8,
46 BLACK = 0,
47 RED=1,
48 GREEN=2,
49 YELLOW=3,
50 BLUE=4
51 // ,MAGENTA=5,
52 // CYAN=6,
53 // WHITE=7
54 ;
55
56 private byte rgb_colors[][];
57 private int mapped_colors[];
58 private float dests[][];
59 private float offsets[][];
60 private float angs[];
61 private float rotAxis[][];
62 private int iters[];
63 private ImmModeSink theTorus;
64
65 private final float lmodel_ambient[] = {0.0f, 0.0f, 0.0f, 0.0f};
66 private final float lmodel_twoside[] = {0.0f, 0.0f, 0.0f, 0.0f};
67 // private float lmodel_local[] = {0.0f, 0.0f, 0.0f, 0.0f};
68 private final float light0_ambient[] = {0.1f, 0.1f, 0.1f, 1.0f};
69 private final float light0_diffuse[] = {1.0f, 1.0f, 1.0f, 0.0f};
70 private final float light0_position[] = {0.8660254f, 0.5f, 1f, 0f};
71 private final float light0_specular[] = {1.0f, 1.0f, 1.0f, 0.0f};
72 private final float bevel_mat_ambient[] = {0.0f, 0.0f, 0.0f, 1.0f};
73 private final float bevel_mat_shininess[] = {40.0f, 0f, 0f, 0f};
74 private final float bevel_mat_specular[] = {1.0f, 1.0f, 1.0f, 0.0f};
75 private final float bevel_mat_diffuse[] = {1.0f, 0.0f, 0.0f, 0.0f};
76 private final int swapInterval;
77 private GLU glu;
78
79 public OlympicES1() {
80 swapInterval = 1;
81 }
82
83 public OlympicES1(final int swapInterval) {
84 this.swapInterval = swapInterval;
85 }
86
87 public void setForceFFPEmu(final boolean forceFFPEmu, final boolean verboseFFPEmu, final boolean debugFFPEmu, final boolean traceFFPEmu) {
88 this.forceFFPEmu = forceFFPEmu;
89 this.verboseFFPEmu = verboseFFPEmu;
90 this.debugFFPEmu = debugFFPEmu;
91 this.traceFFPEmu = traceFFPEmu;
92 }
93
94 public void init(final GLAutoDrawable drawable)
95 {
96 GL _gl = drawable.getGL();
97
98 if(debugFFPEmu) {
99 // Debug ..
100 _gl = _gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Debug", GL2ES2.class, _gl, null) );
101 debug = false;
102 }
103 if(traceFFPEmu) {
104 // Trace ..
105 _gl = _gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Trace", GL2ES2.class, _gl, new Object[] { System.err } ) );
106 trace = false;
107 }
108 GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(_gl, ShaderSelectionMode.AUTO, null, forceFFPEmu, verboseFFPEmu);
109
110 if(debug) {
111 try {
112 // Debug ..
113 gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Debug", GL2ES1.class, gl, null) );
114 } catch (final Exception e) {e.printStackTrace();}
115 }
116 if(trace) {
117 try {
118 // Trace ..
119 gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("com.jogamp.opengl.Trace", GL2ES1.class, gl, new Object[] { System.err } ) );
120 } catch (final Exception e) {e.printStackTrace();}
121 }
122
123 System.err.println("OlympicES1 init on "+Thread.currentThread());
124 System.err.println("Chosen GLCapabilities: " + drawable.getChosenGLCapabilities());
125 System.err.println("INIT GL IS: " + gl.getClass().getName());
126 System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR));
127 System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER));
128 System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION));
129 System.err.println("GL GLSL: "+gl.hasGLSL()+", has-compiler-func: "+gl.isFunctionAvailable("glCompileShader")+", version "+(gl.hasGLSL() ? gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION) : "none"));
130 System.err.println("GL FBO: basic "+ gl.hasBasicFBOSupport()+", full "+gl.hasFullFBOSupport());
131 System.err.println("GL Profile: "+gl.getGLProfile());
132 System.err.println("GL:" + gl + ", " + gl.getContext().getGLVersion());
133
134 glu = GLU.createGLU(gl);
135 System.err.println("GLU:" + glu.getClass().getName());
136
137 rgb_colors=new byte[RINGS][3];
138 mapped_colors=new int [RINGS];
139 dests=new float [RINGS][3];
140 offsets=new float[RINGS][3];
141 angs=new float[RINGS];
142 rotAxis=new float[RINGS][3];
143 iters=new int[RINGS];
144
145 int i;
146 final float top_y = 1.0f;
147 final float bottom_y = 0.0f;
148 final float top_z = 0.15f;
149 final float bottom_z = 0.69f;
150 final float spacing = 2.5f;
151
152 for (i = 0; i < RINGS; i++) {
153 rgb_colors[i][0] = rgb_colors[i][1] = rgb_colors[i][2] = (byte)0;
154 }
155 rgb_colors[BLUERING][2] = (byte)255;
156 rgb_colors[REDRING][0] = (byte)255;
157 rgb_colors[GREENRING][1] = (byte)255;
158 rgb_colors[YELLOWRING][0] = (byte)255;
159 rgb_colors[YELLOWRING][1] = (byte)255;
160 mapped_colors[BLUERING] = BLUE;
161 mapped_colors[REDRING] = RED;
162 mapped_colors[GREENRING] = GREEN;
163 mapped_colors[YELLOWRING] = YELLOW;
164 mapped_colors[BLACKRING] = BLACK;
165
166 dests[BLUERING][0] = -spacing;
167 dests[BLUERING][1] = top_y;
168 dests[BLUERING][2] = top_z;
169
170 dests[BLACKRING][0] = 0.0f;
171 dests[BLACKRING][1] = top_y;
172 dests[BLACKRING][2] = top_z;
173
174 dests[REDRING][0] = spacing;
175 dests[REDRING][1] = top_y;
176 dests[REDRING][2] = top_z;
177
178 dests[YELLOWRING][0] = -spacing / 2.0f;
179 dests[YELLOWRING][1] = bottom_y;
180 dests[YELLOWRING][2] = bottom_z;
181
182 dests[GREENRING][0] = spacing / 2.0f;
183 dests[GREENRING][1] = bottom_y;
184 dests[GREENRING][2] = bottom_z;
185
186 theTorus = ImmModeSink.createFixed(40,
187 3, GL.GL_FLOAT, // vertex
188 0, GL.GL_FLOAT, // color
189 3, GL.GL_FLOAT, // normal
190 0, GL.GL_FLOAT, // texCoords
192 FillTorus(gl, theTorus, 0.1f, 8, 1.0f, 25);
193
194 gl.glEnable(GL.GL_CULL_FACE);
195 gl.glCullFace(GL.GL_BACK);
196 gl.glEnable(GL.GL_DEPTH_TEST);
197 gl.glClearDepth(1.0);
198
199 gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_AMBIENT, light0_ambient, 0);
200 gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_DIFFUSE, light0_diffuse, 0);
201 gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_SPECULAR, light0_specular, 0);
202 gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_POSITION, light0_position, 0);
203 gl.glEnable(GLLightingFunc.GL_LIGHT0);
204
205 // gl.glLightModelfv(GL2.GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local, 0);
206 gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside, 0);
207 gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT, lmodel_ambient, 0);
208 gl.glEnable(GLLightingFunc.GL_LIGHTING);
209
210 gl.glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
211
212 gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT, bevel_mat_ambient, 0);
213 gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, bevel_mat_shininess, 0);
214 gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SPECULAR, bevel_mat_specular, 0);
215 gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_DIFFUSE, bevel_mat_diffuse, 0);
216
217 // gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL2ES1.GL_DIFFUSE);
218 gl.glEnable(GLLightingFunc.GL_COLOR_MATERIAL);
219 gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
220
221 ReInit();
222 t0 = System.currentTimeMillis();
223 tL = t0;
224 }
225
226
227 @Override
228 public void dispose(final GLAutoDrawable glad) {
229 glu = null;
230 theTorus.destroy(glad.getGL());
231 theTorus = null;
232 }
233
234
235 @Override
236 public void reshape(final GLAutoDrawable glad, final int x, final int y, final int width, final int height) {
237 final GL2ES1 gl = glad.getGL().getGL2ES1();
238 gl.setSwapInterval(swapInterval);
239
241 gl.glLoadIdentity();
242 glu.gluPerspective(45f, (float) width / (float) height, 0.1f, 100.0f);
244 gl.glLoadIdentity();
245 glu.gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
246 }
247
248 @Override
249 public void display(final GLAutoDrawable glad) {
250 final GL2ES1 gl = glad.getGL().getGL2ES1();
251 int i;
252
254
255 gl.glPushMatrix();
256 for (i = 0; i < RINGS; i++) {
257 gl.glColor4ub(rgb_colors[i][0], rgb_colors[i][1], rgb_colors[i][2], (byte)1);
258 gl.glPushMatrix();
259 gl.glTranslatef(dests[i][0] + offsets[i][0],
260 dests[i][1] + offsets[i][1],
261 dests[i][2] + offsets[i][2]);
262 gl.glRotatef(angs[i], rotAxis[i][0], rotAxis[i][1], rotAxis[i][2]);
263 theTorus.draw(gl, true);
264 gl.glPopMatrix();
265 }
266 gl.glPopMatrix();
267 animationCalc();
268 }
269
270 long t0, tL;
271
272 protected void animationCalc()
273 {
274 int i, j;
275
276 final long t1 = System.currentTimeMillis();
277 if( t1 - tL < 50 ) {
278 return;
279 }
280
281 for (i = 0; i < RINGS; i++) {
282 if (iters[i]!=0) {
283 for (j = 0; j < 3; j++) {
284 offsets[i][j] = Clamp(iters[i], offsets[i][j]);
285 }
286 angs[i] = Clamp(iters[i], angs[i]);
287 iters[i]--;
288 }
289 }
290 if (iters[0]==0)
291 {
292 ReInit();
293 }
294
295 tL = t1;
296 }
297
298 protected void ReInit() {
299 int i;
300 float deviation;
301
302 deviation = MyRand() / 2;
303 deviation = deviation * deviation;
304 for (i = 0; i < RINGS; i++) {
305 offsets[i][0] = MyRand();
306 offsets[i][1] = MyRand();
307 offsets[i][2] = MyRand();
308 angs[i] = (float) (260.0 * MyRand());
309 rotAxis[i][0] = MyRand();
310 rotAxis[i][1] = MyRand();
311 rotAxis[i][2] = MyRand();
312 iters[i] = ( int ) (deviation * MyRand() + 60.0);
313 }
314 }
315
316 protected static void FillTorus(final GL gl, final ImmModeSink immModeSink, final float rc, final int numc, final float rt, final int numt)
317 {
318 int i, j, k;
319 double s, t;
320 float x, y, z;
321
322 for (i = 0; i < numc; i++) {
323 immModeSink.glBegin(ImmModeSink.GL_QUAD_STRIP);
324 for (j = 0; j <= numt; j++) {
325 for (k = 1; k >= 0; k--) {
326 s = (i + k) % numc + 0.5;
327 t = j % numt;
328
329 x = (float) Math.cos(t * M_2PI / numt) * (float) Math.cos(s * M_2PI / numc);
330 y = (float) Math.sin(t * M_2PI / numt) * (float) Math.cos(s * M_2PI / numc);
331 z = (float) Math.sin(s * M_2PI / numc);
332 immModeSink.glNormal3f(x, y, z);
333
334 x = (rt + rc * (float) Math.cos(s * M_2PI / numc)) * (float) Math.cos(t * M_2PI / numt);
335 y = (rt + rc * (float) Math.cos(s * M_2PI / numc)) * (float) Math.sin(t * M_2PI / numt);
336 z = rc * (float) Math.sin(s * M_2PI / numc);
337 immModeSink.glVertex3f(x, y, z);
338 }
339 }
340 immModeSink.glEnd(gl, false);
341 }
342 }
343
344 protected float Clamp(final int iters_left, final float t)
345 {
346 if (iters_left < 3) {
347 return 0.0f;
348 }
349 return (iters_left - 2) * t / iters_left;
350 }
351
352 protected float MyRand()
353 {
354 // return 10.0 * (drand48() - 0.5);
355 return (float) ( 10.0 * (Math.random() - 0.5) );
356 }
357
358}
359
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 gluLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
Definition: GLU.java:1366
static final GLU createGLU()
Instantiates a GLU implementation object in respect to the given GL profile of this thread current GL...
Definition: GLU.java:147
void gluPerspective(float fovy, float aspect, float zNear, float zFar)
Definition: GLU.java:1362
static void FillTorus(final GL gl, final ImmModeSink immModeSink, final float rc, final int numc, final float rt, final int numt)
void display(final GLAutoDrawable glad)
Called by the drawable to initiate OpenGL rendering by the client.
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.
float Clamp(final int iters_left, final float t)
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
Definition: OlympicES1.java:94
void dispose(final GLAutoDrawable glad)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void setForceFFPEmu(final boolean forceFFPEmu, final boolean verboseFFPEmu, final boolean debugFFPEmu, final boolean traceFFPEmu)
Definition: OlympicES1.java:87
final void glVertex3f(final float x, final float y, final float z)
final void glNormal3f(final float x, final float y, final float z)
static ImmModeSink createFixed(final int initialElementCount, final int vComps, final int vDataType, final int cComps, final int cDataType, final int nComps, final int nDataType, final int tComps, final int tDataType, final int glBufferUsage)
Uses a GL2ES1, or ES2 fixed function emulation immediate mode sink.
void draw(final GL gl, final boolean disableBufferAfterDraw)
final void glEnd(final GL gl)
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_LIGHT_MODEL_TWO_SIDE
GL_VERSION_ES_1_0, GL_VERSION_1_0 Define "GL_LIGHT_MODEL_TWO_SIDE" with expression '0x0B52',...
Definition: GL2ES1.java:126
static final int GL_LIGHT_MODEL_AMBIENT
GL_VERSION_ES_1_0, GL_VERSION_1_0 Define "GL_LIGHT_MODEL_AMBIENT" with expression '0x0B53',...
Definition: GL2ES1.java:178
void glColor4ub(byte red, byte green, byte blue, byte alpha)
Entry point to C language function: void {@native glColor4ub}(GLubyte red, GLubyte green,...
static final int GL_SHADING_LANGUAGE_VERSION
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_ARB_shading_language_100 Alias for: GL_SHADING_LANGUAGE_VERSION...
Definition: GL2ES2.java:234
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.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
static final int GL_BACK
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_BACK" with expression...
Definition: GL.java:330
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_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
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
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_FRONT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FRONT" with expressio...
Definition: GL.java:597
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
static final int GL_CULL_FACE
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_CULL_FACE" with expre...
Definition: GL.java:720
Subset of OpenGL fixed function pipeline's matrix operations.
static final int GL_PROJECTION
Matrix mode projection.
void glPushMatrix()
Push the current matrix to it's stack, while preserving it's values.
void glPopMatrix()
Pop the current matrix from it's stack.
void glTranslatef(float x, float y, float z)
Translate the current matrix.
void glRotatef(float angle, float x, float y, float z)
Rotate 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.