5package com.jogamp.opengl.test.junit.jogl.demos.es1;
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;
18import com.jogamp.opengl.util.ImmModeSink;
19import com.jogamp.opengl.util.glsl.fixedfunc.FixedFuncUtil;
20import com.jogamp.opengl.util.glsl.fixedfunc.ShaderSelectionMode;
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 ;
34 private static final double M_2PI = 2.0*Math.PI;
36 private static final int
56 private byte rgb_colors[][];
57 private int mapped_colors[];
58 private float dests[][];
59 private float offsets[][];
61 private float rotAxis[][];
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};
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;
84 this.swapInterval = swapInterval;
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;
114 }
catch (
final Exception e) {e.printStackTrace();}
120 }
catch (
final Exception e) {e.printStackTrace();}
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());
135 System.err.println(
"GLU:" + glu.getClass().getName());
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];
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;
152 for (i = 0; i < RINGS; i++) {
153 rgb_colors[i][0] = rgb_colors[i][1] = rgb_colors[i][2] = (byte)0;
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;
166 dests[BLUERING][0] = -spacing;
167 dests[BLUERING][1] = top_y;
168 dests[BLUERING][2] = top_z;
170 dests[BLACKRING][0] = 0.0f;
171 dests[BLACKRING][1] = top_y;
172 dests[BLACKRING][2] = top_z;
174 dests[REDRING][0] = spacing;
175 dests[REDRING][1] = top_y;
176 dests[REDRING][2] = top_z;
178 dests[YELLOWRING][0] = -spacing / 2.0f;
179 dests[YELLOWRING][1] = bottom_y;
180 dests[YELLOWRING][2] = bottom_z;
182 dests[GREENRING][0] = spacing / 2.0f;
183 dests[GREENRING][1] = bottom_y;
184 dests[GREENRING][2] = bottom_z;
192 FillTorus(gl, theTorus, 0.1f, 8, 1.0f, 25);
197 gl.glClearDepth(1.0);
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);
208 gl.glEnable(GLLightingFunc.GL_LIGHTING);
210 gl.glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
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);
218 gl.glEnable(GLLightingFunc.GL_COLOR_MATERIAL);
219 gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
222 t0 = System.currentTimeMillis();
242 glu.
gluPerspective(45f, (
float) width / (
float) height, 0.1f, 100.0f);
245 glu.
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
256 for (i = 0; i < RINGS; i++) {
257 gl.
glColor4ub(rgb_colors[i][0], rgb_colors[i][1], rgb_colors[i][2], (
byte)1);
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);
276 final long t1 = System.currentTimeMillis();
281 for (i = 0; i < RINGS; i++) {
283 for (j = 0; j < 3; j++) {
284 offsets[i][j] = Clamp(iters[i], offsets[i][j]);
286 angs[i] = Clamp(iters[i], angs[i]);
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);
316 protected static void FillTorus(
final GL gl,
final ImmModeSink immModeSink,
final float rc,
final int numc,
final float rt,
final int numt)
322 for (i = 0; i < numc; i++) {
324 for (j = 0; j <= numt; j++) {
325 for (k = 1; k >= 0; k--) {
326 s = (i + k) % numc + 0.5;
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);
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);
340 immModeSink.
glEnd(gl,
false);
344 protected float Clamp(
final int iters_left,
final float t)
346 if (iters_left < 3) {
349 return (iters_left - 2) * t / iters_left;
355 return (
float) ( 10.0 * (Math.random() - 0.5) );
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).
void gluLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
static final GLU createGLU()
Instantiates a GLU implementation object in respect to the given GL profile of this thread current GL...
void gluPerspective(float fovy, float aspect, float zNear, float zFar)
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.
void dispose(final GLAutoDrawable glad)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
OlympicES1(final int swapInterval)
void setForceFFPEmu(final boolean forceFFPEmu, final boolean verboseFFPEmu, final boolean debugFFPEmu, final boolean traceFFPEmu)
final void glVertex3f(final float x, final float y, final float z)
static final int GL_QUAD_STRIP
final void glNormal3f(final float x, final float y, final float z)
void destroy(final GL gl)
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',...
static final int GL_LIGHT_MODEL_AMBIENT
GL_VERSION_ES_1_0, GL_VERSION_1_0 Define "GL_LIGHT_MODEL_AMBIENT" with expression '0x0B53',...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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.