summaryrefslogtreecommitdiffstats
path: root/src/demos/es1
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2009-06-15 23:12:27 +0000
committerKenneth Russel <[email protected]>2009-06-15 23:12:27 +0000
commit41cd6c47b23975098cd155517790e018670785e7 (patch)
tree247333528ad674d427ba96b1e05810f7961d609e /src/demos/es1
parent935d2596c13371bb745d921dbcb9f05b0c11a010 (diff)
Copied JOGL_2_SANDBOX r350 on to trunk; JOGL_2_SANDBOX branch is now closed
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/trunk@352 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src/demos/es1')
-rwxr-xr-xsrc/demos/es1/Info.java87
-rwxr-xr-xsrc/demos/es1/RedSquare.java254
-rwxr-xr-xsrc/demos/es1/angeles/AngelesES1.java751
-rwxr-xr-xsrc/demos/es1/angeles/AngelesGL.java816
-rwxr-xr-xsrc/demos/es1/angeles/AngelesGLil.java842
-rwxr-xr-xsrc/demos/es1/angeles/CamTrack.java71
-rwxr-xr-xsrc/demos/es1/angeles/Main.java131
-rwxr-xr-xsrc/demos/es1/angeles/SuperShape.java57
-rw-r--r--src/demos/es1/cube/Cube.java347
-rw-r--r--src/demos/es1/cube/CubeImmModeSink.java436
-rwxr-xr-xsrc/demos/es1/cubefbo/FBCubes.java168
-rwxr-xr-xsrc/demos/es1/cubefbo/Main.java110
12 files changed, 4070 insertions, 0 deletions
diff --git a/src/demos/es1/Info.java b/src/demos/es1/Info.java
new file mode 100755
index 0000000..8d83692
--- /dev/null
+++ b/src/demos/es1/Info.java
@@ -0,0 +1,87 @@
+package demos.es1;
+
+import java.nio.*;
+import javax.media.opengl.*;
+import javax.media.opengl.glu.*;
+import javax.media.nativewindow.*;
+
+import com.sun.javafx.newt.*;
+import com.sun.javafx.newt.opengl.*;
+
+public class Info implements GLEventListener {
+
+ private GLWindow window;
+
+ private void run(int type) {
+ int width = 10;
+ int height = 10;
+ System.err.println("Info.run()");
+ try {
+ GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES1());
+ // For emulation library, use 16 bpp
+ caps.setRedBits(5);
+ caps.setGreenBits(6);
+ caps.setBlueBits(5);
+ caps.setDepthBits(16);
+
+ Window nWindow = null;
+ if(0!=(type&USE_AWT)) {
+ Display nDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null); // local display
+ Screen nScreen = NewtFactory.createScreen(NativeWindowFactory.TYPE_AWT, nDisplay, 0); // screen 0
+ nWindow = NewtFactory.createWindow(NativeWindowFactory.TYPE_AWT, nScreen, caps);
+ }
+ window = GLWindow.create(nWindow, caps);
+
+ window.addGLEventListener(this);
+
+ // Size OpenGL to Video Surface
+ window.setSize(width, height);
+ window.setFullscreen(true);
+ window.setVisible(true);
+
+ window.display();
+
+ // Shut things down cooperatively
+ window.destroy();
+ window.getFactory().shutdown();
+ System.out.println("Info shut down cleanly.");
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ GL gl = drawable.getGL();
+
+ System.err.println("GL Profile: "+gl.getGLProfile());
+ System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION));
+ System.err.println("GL_EXTENSIONS: ");
+ System.err.println(" " + gl.glGetString(GL.GL_EXTENSIONS));
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ }
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+ }
+
+ public static int USE_NEWT = 0;
+ public static int USE_AWT = 1 << 0;
+
+ public static void main(String[] args) {
+ int type = USE_NEWT ;
+ for(int i=args.length-1; i>=0; i--) {
+ if(args[i].equals("-awt")) {
+ type |= USE_AWT;
+ }
+ }
+ new Info().run(type);
+ System.exit(0);
+ }
+}
diff --git a/src/demos/es1/RedSquare.java b/src/demos/es1/RedSquare.java
new file mode 100755
index 0000000..3992fc7
--- /dev/null
+++ b/src/demos/es1/RedSquare.java
@@ -0,0 +1,254 @@
+package demos.es1;
+
+import java.nio.*;
+import java.util.*;
+import javax.media.opengl.*;
+import javax.media.opengl.glu.*;
+import javax.media.nativewindow.*;
+
+import com.sun.opengl.util.*;
+import com.sun.opengl.util.glsl.fixedfunc.*;
+
+import com.sun.javafx.newt.*;
+import com.sun.javafx.newt.opengl.*;
+
+public class RedSquare extends Thread implements WindowListener, KeyListener, MouseListener, GLEventListener {
+
+ private GLWindow window;
+ private GLProfile glp;
+ private GLU glu;
+ private boolean quit = false;
+ private String glprofile;
+ private int type;
+
+ public RedSquare(String glprofile, int type) {
+ super();
+ this.glprofile=glprofile;
+ this.type=type;
+ }
+
+ public void windowResized(WindowEvent e) {
+ }
+
+ public void windowMoved(WindowEvent e) {
+ }
+
+ public void windowDestroyNotify(WindowEvent e) {
+ quit=true;
+ }
+ public void windowGainedFocus(WindowEvent e) { }
+ public void windowLostFocus(WindowEvent e) { }
+
+ public void keyPressed(KeyEvent e) {
+ System.out.println(glp+" "+e);
+ if(e.getKeyChar()=='q') {
+ quit = true;
+ }
+ }
+ public void keyReleased(KeyEvent e) {
+ System.out.println(glp+" "+e);
+ }
+ public void keyTyped(KeyEvent e) {
+ System.out.println(glp+" "+e);
+ }
+
+ public void mouseClicked(MouseEvent e) {
+ System.out.println(glp+" mouseevent: "+e);
+ switch(e.getClickCount()) {
+ case 1:
+ window.setFullscreen(!window.isFullscreen());
+ break;
+ default:
+ quit=true;
+ break;
+ }
+ }
+ public void mouseEntered(MouseEvent e) {
+ }
+ public void mouseExited(MouseEvent e) {
+ }
+ public void mousePressed(MouseEvent e) {
+ }
+ public void mouseReleased(MouseEvent e) {
+ }
+ public void mouseMoved(MouseEvent e) {
+ }
+ public void mouseDragged(MouseEvent e) {
+ }
+ public void mouseWheelMoved(MouseEvent e) {
+ }
+
+ public void run() {
+ System.err.println(glp+" RedSquare.run() 0");
+ int width = 800;
+ int height = 480;
+ glp = GLProfile.get(glprofile);
+ try {
+ GLCapabilities caps = new GLCapabilities(glp);
+
+ Window nWindow = null;
+ if(0!=(type&USE_AWT)) {
+ Display nDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null); // local display
+ Screen nScreen = NewtFactory.createScreen(NativeWindowFactory.TYPE_AWT, nDisplay, 0); // screen 0
+ nWindow = NewtFactory.createWindow(NativeWindowFactory.TYPE_AWT, nScreen, caps);
+ }
+ window = GLWindow.create(nWindow, caps);
+
+ window.addWindowListener(this);
+ window.addMouseListener(this);
+ window.addKeyListener(this);
+ window.addGLEventListener(this);
+ // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_CURRENT); // default
+ // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_NONE); // no current ..
+
+ window.enablePerfLog(true);
+ // Size OpenGL to Video Surface
+ window.setSize(width, height);
+ // window.setFullscreen(true);
+ window.setVisible(true);
+ window.enablePerfLog(true);
+
+ do {
+ window.display();
+ } while (!quit && window.getDuration() < 20000) ;
+
+ // Shut things down cooperatively
+ window.destroy();
+ window.getFactory().shutdown();
+ System.out.println(glp+" RedSquare shut down cleanly.");
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ // FIXME: we must add storage of the pointers in the GL state to
+ // the GLImpl classes. The need for this can be seen by making
+ // these variables method local instead of instance members. The
+ // square will disappear after a second or so due to garbage
+ // collection. On desktop OpenGL this implies a stack of
+ // references due to the existence of glPush/PopClientAttrib. On
+ // OpenGL ES 1/2 it can simply be one set of references.
+ private FloatBuffer colors;
+ private FloatBuffer vertices;
+
+ public void init(GLAutoDrawable drawable) {
+ GL2ES1 gl = FixedFuncUtil.getFixedFuncImpl(drawable.getGL());
+
+ System.err.println(glp+" Entering initialization");
+ System.err.println(glp+" GL Profile: "+gl.getGLProfile());
+ System.err.println(glp+" GL:" + gl);
+ System.err.println(glp+" GL_VERSION=" + gl.glGetString(gl.GL_VERSION));
+ System.err.println(glp+" GL_EXTENSIONS:");
+ System.err.println(glp+" " + gl.glGetString(gl.GL_EXTENSIONS));
+
+ glu = GLU.createGLU();
+
+ // Allocate vertex arrays
+ colors = BufferUtil.newFloatBuffer(16);
+ vertices = BufferUtil.newFloatBuffer(12);
+ // Fill them up
+ colors.put( 0, 1); colors.put( 1, 0); colors.put( 2, 0); colors.put( 3, 1);
+ colors.put( 4, 0); colors.put( 5, 0); colors.put( 6, 1); colors.put( 7, 1);
+ colors.put( 8, 1); colors.put( 9, 0); colors.put(10, 0); colors.put(11, 1);
+ colors.put(12, 1); colors.put(13, 0); colors.put(14, 0); colors.put(15, 1);
+ vertices.put(0, -2); vertices.put( 1, 2); vertices.put( 2, 0);
+ vertices.put(3, 2); vertices.put( 4, 2); vertices.put( 5, 0);
+ vertices.put(6, -2); vertices.put( 7, -2); vertices.put( 8, 0);
+ vertices.put(9, 2); vertices.put(10, -2); vertices.put(11, 0);
+
+ gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
+ gl.glEnableClientState(gl.GL_COLOR_ARRAY);
+ gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertices);
+ gl.glColorPointer(4, GL.GL_FLOAT, 0, colors);
+
+ // OpenGL Render Settings
+ gl.glClearColor(0, 0, 0, 1);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+ // Set location in front of camera
+ gl.glMatrixMode(gl.GL_PROJECTION);
+ gl.glLoadIdentity();
+ glu.gluPerspective(45.0f, (float)width / (float)height, 1.0f, 100.0f);
+ //gl.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
+ //glu.gluLookAt(0, 0, -20, 0, 0, 0, 0, 1, 0);
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+
+ // One rotation every four seconds
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ gl.glTranslatef(0, 0, -10);
+ float ang = ((float) window.getDuration() * 360.0f) / 4000.0f;
+ gl.glRotatef(ang, 0, 0, 1);
+ gl.glRotatef(ang, 0, 1, 0);
+
+
+ // Draw a square
+ gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+ System.out.println(glp+" RedSquare.dispose: "+gl.getContext());
+ gl.glDisableClientState(gl.GL_VERTEX_ARRAY);
+ gl.glDisableClientState(gl.GL_COLOR_ARRAY);
+ glu.destroy();
+ glu = null;
+ colors.clear();
+ colors = null;
+ vertices.clear();
+ vertices = null;
+ System.out.println(glp+" RedSquare.dispose: fin");
+ }
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+ }
+
+ public static int USE_NEWT = 0;
+ public static int USE_AWT = 1 << 0;
+
+ public static void main(String[] args) {
+ int type = USE_NEWT ;
+ List threads = new ArrayList();
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-awt")) {
+ type |= USE_AWT;
+ }
+ if(args[i].startsWith("-GL")) {
+ threads.add(new RedSquare(args[i].substring(1), type));
+ }
+ }
+ if(threads.size()==0) {
+ threads.add(new RedSquare(null, type));
+ }
+ Thread firstT = (Thread) threads.remove(0);
+
+ for(Iterator i = threads.iterator(); i.hasNext(); ) {
+ ((Thread)i.next()).start();
+ }
+
+ // always run the first on main ..
+ firstT.run();
+
+ boolean done = false;
+
+ while(!done) {
+ int aliveCount = 0;
+ for(Iterator i = threads.iterator(); i.hasNext(); ) {
+ if ( ((Thread)i.next()).isAlive() ) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException ie) {}
+ aliveCount++;
+ }
+ }
+ done = 0==aliveCount ;
+ }
+ }
+}
diff --git a/src/demos/es1/angeles/AngelesES1.java b/src/demos/es1/angeles/AngelesES1.java
new file mode 100755
index 0000000..c5de891
--- /dev/null
+++ b/src/demos/es1/angeles/AngelesES1.java
@@ -0,0 +1,751 @@
+/* San Angeles Observation OpenGL ES version example
+ * Copyright 2004-2005 Jetro Lauha
+ * All rights reserved.
+ * Web: http://iki.fi/jetro/
+ *
+ * This source is free software; you can redistribute it and/or
+ * modify it under the terms of EITHER:
+ * (1) The GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version. The text of the GNU Lesser
+ * General Public License is included with this source in the
+ * file LICENSE-LGPL.txt.
+ * (2) The BSD-style license that is included with this source in
+ * the file LICENSE-BSD.txt.
+ *
+ * This source is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
+ * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
+ *
+ * $Id$
+ * $Revision$
+ */
+
+package demos.es1.angeles;
+
+import javax.media.opengl.*;
+import javax.media.opengl.glu.*;
+import com.sun.opengl.util.*;
+import java.nio.*;
+
+public class AngelesES1 implements GLEventListener {
+
+ public AngelesES1(boolean enableBlending) {
+ blendingEnabled = enableBlending;
+ quadVertices = BufferUtil.newIntBuffer(12);
+ quadVertices.put(new int[]{
+ -0x10000, -0x10000,
+ 0x10000, -0x10000,
+ -0x10000, 0x10000,
+ 0x10000, -0x10000,
+ 0x10000, 0x10000,
+ -0x10000, 0x10000
+ });
+ quadVertices.flip();
+
+ light0Position=BufferUtil.newIntBuffer(4);
+ light0Diffuse=BufferUtil.newIntBuffer(4);
+ light1Position=BufferUtil.newIntBuffer(4);
+ light1Diffuse=BufferUtil.newIntBuffer(4);
+ light2Position=BufferUtil.newIntBuffer(4);
+ light2Diffuse=BufferUtil.newIntBuffer(4);
+ materialSpecular=BufferUtil.newIntBuffer(4);
+
+ light0Position.put(new int[] { -0x40000, 0x10000, 0x10000, 0 });
+ light0Diffuse.put(new int[] { 0x10000, 0x6666, 0, 0x10000 });
+ light1Position.put(new int[] { 0x10000, -0x20000, -0x10000, 0 });
+ light1Diffuse.put(new int[] { 0x11eb, 0x23d7, 0x5999, 0x10000 });
+ light2Position.put(new int[] { -0x10000, 0, -0x40000, 0 });
+ light2Diffuse.put(new int[] { 0x11eb, 0x2b85, 0x23d7, 0x10000 });
+ materialSpecular.put(new int[] { 0x10000, 0x10000, 0x10000, 0x10000 });
+
+ light0Position.flip();
+ light0Diffuse.flip();
+ light1Position.flip();
+ light1Diffuse.flip();
+ light2Position.flip();
+ light2Diffuse.flip();
+ materialSpecular.flip();
+
+ seedRandom(15);
+
+ width=0;
+ height=0;
+ x=0;
+ y=0;
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ // FIXME: gl.setSwapInterval(1);
+
+ this.gl = drawable.getGL().getGLES1();
+ this.glu = GLU.createGLU();
+ gl.glEnable(gl.GL_NORMALIZE);
+ gl.glEnable(gl.GL_DEPTH_TEST);
+ gl.glDisable(gl.GL_CULL_FACE);
+ gl.glShadeModel(gl.GL_FLAT);
+
+ gl.glEnable(gl.GL_LIGHTING);
+ gl.glEnable(gl.GL_LIGHT0);
+ gl.glEnable(gl.GL_LIGHT1);
+ gl.glEnable(gl.GL_LIGHT2);
+
+ gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
+ gl.glEnableClientState(gl.GL_COLOR_ARRAY);
+
+ for (int a = 0; a < SuperShape.COUNT; ++a)
+ {
+ sSuperShapeObjects[a] = createSuperShape(SuperShape.sParams[a]);
+ }
+ sGroundPlane = createGroundPlane();
+
+ gAppAlive = 1;
+
+ sStartTick = System.currentTimeMillis();
+ frames=0;
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ this.width = width;
+ this.height=height;
+ this.x = x;
+ this.y = y;
+
+ this.gl = drawable.getGL().getGLES1();
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
+ gl.glClearColorx((int)(0.1f * 65536),
+ (int)(0.2f * 65536),
+ (int)(0.3f * 65536), 0x10000);
+
+ gl.glCullFace(GL.GL_FRONT);
+
+ gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_FASTEST);
+
+ //gl.glShadeModel(GL2ES1.GL_SMOOTH);
+ gl.glShadeModel(gl.GL_FLAT);
+ gl.glDisable(gl.GL_DITHER);
+
+ //gl.glMatrixMode(gl.GL_PROJECTION);
+ //gl.glLoadIdentity();
+ //glu.gluPerspective(45.0f, (float)width / (float)height, 0.5f, 150.0f);
+
+ System.out.println("reshape ..");
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ long tick = System.currentTimeMillis();
+
+ if (gAppAlive==0)
+ return;
+
+ this.gl = drawable.getGL().getGLES1();
+
+ // Actual tick value is "blurred" a little bit.
+ sTick = (sTick + tick - sStartTick) >> 1;
+
+ // Terminate application after running through the demonstration once.
+ if (sTick >= RUN_LENGTH)
+ {
+ gAppAlive = 0;
+ return;
+ }
+
+ gl.glClear(gl.GL_DEPTH_BUFFER_BIT | gl.GL_COLOR_BUFFER_BIT);
+
+ gl.glMatrixMode(gl.GL_PROJECTION);
+ gl.glLoadIdentity();
+ glu.gluPerspective(45.0f, (float)width / (float)height, 0.5f, 150.0f);
+
+ // Update the camera position and set the lookat.
+ camTrack();
+
+ // Configure environment.
+ configureLightAndMaterial();
+
+ if(blendingEnabled) {
+ // Draw the reflection by drawing models with negated Z-axis.
+ gl.glPushMatrix();
+ drawModels(-1);
+ gl.glPopMatrix();
+ }
+
+ // Draw the ground plane to the window. (opt. blending)
+ drawGroundPlane();
+
+ // Draw all the models normally.
+ drawModels(1);
+
+ if(blendingEnabled) {
+ // Draw fade quad over whole window (when changing cameras).
+ drawFadeQuad();
+ }
+
+ frames++;
+ tick = System.currentTimeMillis();
+ long dT = tick - sStartTick;
+ // System.out.println(frames+"f, "+dT+"ms "+ (frames*1000)/dT +"fps");
+ }
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+ }
+
+ private boolean blendingEnabled = true;
+ private GLES1 gl;
+ private GLU glu;
+
+ // Total run length is 20 * camera track base unit length (see cams.h).
+ private int RUN_LENGTH = (20 * CamTrack.CAMTRACK_LEN) ;
+ private int RANDOM_UINT_MAX = 65535 ;
+
+ private long sRandomSeed = 0;
+
+void seedRandom(long seed)
+{
+ sRandomSeed = seed;
+}
+
+int randomUInt()
+{
+ sRandomSeed = sRandomSeed * 0x343fd + 0x269ec3;
+ return Math.abs((int) (sRandomSeed >> 16));
+}
+
+
+// Definition of one GL object in this demo.
+public class GLObject {
+ /* Vertex array and color array are enabled for all objects, so their
+ * pointers must always be valid and non-null. Normal array is not
+ * used by the ground plane, so when its pointer is null then normal
+ * array usage is disabled.
+ *
+ * Vertex array is supposed to use gl.GL_FIXED datatype and stride 0
+ * (i.e. tightly packed array). Color array is supposed to have 4
+ * components per color with gl.GL_UNSIGNED_BYTE datatype and stride 0.
+ * Normal array is supposed to use gl.GL_FIXED datatype and stride 0.
+ */
+ IntBuffer vertexArray;
+ ByteBuffer colorArray;
+ IntBuffer normalArray;
+ int vertexComponents;
+ int count;
+ int vbo[];
+
+ public GLObject(int vertices, int vertexComponents,
+ boolean useNormalArray) {
+ this.count = vertices;
+ this.vertexComponents = vertexComponents;
+ this.vertexArray = BufferUtil.newIntBuffer( vertices * vertexComponents );
+ this.colorArray = BufferUtil.newByteBuffer (vertices * 4 );
+ if (useNormalArray)
+ {
+ this.normalArray = BufferUtil.newIntBuffer (vertices * 3 );
+ } else {
+ this.normalArray = null;
+ }
+ }
+
+ void seal()
+ {
+ flip();
+ vbo = new int[3];
+ gl.glGenBuffers(3, vbo, 0);
+
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[0]);
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, vertexArray.capacity() * BufferUtil.SIZEOF_INT, vertexArray, GL.GL_STATIC_DRAW);
+ gl.glVertexPointer(vertexComponents, gl.GL_FIXED, 0, 0);
+
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[1]);
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, colorArray.capacity() * BufferUtil.SIZEOF_BYTE, colorArray, GL.GL_STATIC_DRAW);
+ gl.glColorPointer(4, gl.GL_UNSIGNED_BYTE, 0, 0);
+
+ if (null!=normalArray)
+ {
+ gl.glEnableClientState(gl.GL_NORMAL_ARRAY);
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[2]);
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, normalArray.capacity() * BufferUtil.SIZEOF_INT, normalArray, GL.GL_STATIC_DRAW);
+ gl.glNormalPointer(gl.GL_FIXED, 0, 0);
+ } else {
+ gl.glDisableClientState(gl.GL_NORMAL_ARRAY);
+ }
+ }
+
+ void draw()
+ {
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[0]);
+ gl.glVertexPointer(vertexComponents, gl.GL_FIXED, 0, 0);
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[1]);
+ gl.glColorPointer(4, gl.GL_UNSIGNED_BYTE, 0, 0);
+
+ if (null!=normalArray)
+ {
+ gl.glEnableClientState(gl.GL_NORMAL_ARRAY);
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[2]);
+ gl.glNormalPointer(gl.GL_FIXED, 0, 0);
+ }
+ else
+ gl.glDisableClientState(gl.GL_NORMAL_ARRAY);
+ gl.glDrawArrays(gl.GL_TRIANGLES, 0, count);
+ }
+
+ void rewind() {
+ vertexArray.rewind();
+ colorArray.rewind();
+ if (normalArray != null) {
+ normalArray.rewind();
+ }
+ }
+ void flip() {
+ vertexArray.flip();
+ colorArray.flip();
+ if (normalArray != null) {
+ normalArray.flip();
+ }
+ }
+}
+
+long sStartTick = 0;
+long sTick = 0;
+
+int sCurrentCamTrack = 0;
+long sCurrentCamTrackStartTick = 0;
+long sNextCamTrackStartTick = 0x7fffffff;
+
+GLObject sSuperShapeObjects[] = new GLObject[SuperShape.COUNT];
+GLObject sGroundPlane;
+
+
+public class VECTOR3 {
+ float x, y, z;
+
+ public VECTOR3() {
+ x=0f; y=0f; z=0f;
+ }
+ public VECTOR3(float x, float y, float z) {
+ this.x=x;
+ this.y=y;
+ this.z=z;
+ }
+}
+
+
+
+static void vector3Sub(VECTOR3 dest, VECTOR3 v1, VECTOR3 v2)
+{
+ dest.x = v1.x - v2.x;
+ dest.y = v1.y - v2.y;
+ dest.z = v1.z - v2.z;
+}
+
+
+static void superShapeMap(VECTOR3 point, float r1, float r2, float t, float p)
+{
+ // sphere-mapping of supershape parameters
+ point.x = (float)(Math.cos(t) * Math.cos(p) / r1 / r2);
+ point.y = (float)(Math.sin(t) * Math.cos(p) / r1 / r2);
+ point.z = (float)(Math.sin(p) / r2);
+}
+
+
+float ssFunc(final float t, final float p[])
+{
+ return ssFunc(t, p, 0);
+}
+
+float ssFunc(final float t, final float p[], int pOff)
+{
+ return (float)(Math.pow(Math.pow(Math.abs(Math.cos(p[0+pOff] * t / 4)) / p[1+pOff], p[4+pOff]) +
+ Math.pow(Math.abs(Math.sin(p[0+pOff] * t / 4)) / p[2+pOff], p[5+pOff]), 1 / p[3+pOff]));
+}
+
+
+// Creates and returns a supershape object.
+// Based on Paul Bourke's POV-Ray implementation.
+// http://astronomy.swin.edu.au/~pbourke/povray/supershape/
+GLObject createSuperShape(final float params[])
+{
+ final int resol1 = (int)params[SuperShape.PARAMS - 3];
+ final int resol2 = (int)params[SuperShape.PARAMS - 2];
+ // latitude 0 to pi/2 for no mirrored bottom
+ // (latitudeBegin==0 for -pi/2 to pi/2 originally)
+ final int latitudeBegin = resol2 / 4;
+ final int latitudeEnd = resol2 / 2; // non-inclusive
+ final int longitudeCount = resol1;
+ final int latitudeCount = latitudeEnd - latitudeBegin;
+ final int triangleCount = longitudeCount * latitudeCount * 2;
+ final int vertices = triangleCount * 3;
+ GLObject result;
+ float baseColor[] = new float[3];
+ int a, longitude, latitude;
+ int currentVertex, currentQuad;
+
+ result = new GLObject(vertices, 3, true);
+ if (result == null)
+ return null;
+
+ for (a = 0; a < 3; ++a)
+ baseColor[a] = ((randomUInt() % 155) + 100) / 255.f;
+
+ currentQuad = 0;
+ currentVertex = 0;
+
+ // longitude -pi to pi
+ for (longitude = 0; longitude < longitudeCount; ++longitude)
+ {
+
+ // latitude 0 to pi/2
+ for (latitude = latitudeBegin; latitude < latitudeEnd; ++latitude)
+ {
+ float t1 = (float) ( -Math.PI + longitude * 2 * Math.PI / resol1 );
+ float t2 = (float) ( -Math.PI + (longitude + 1) * 2 * Math.PI / resol1 );
+ float p1 = (float) ( -Math.PI / 2 + latitude * 2 * Math.PI / resol2 );
+ float p2 = (float) ( -Math.PI / 2 + (latitude + 1) * 2 * Math.PI / resol2 );
+ float r0, r1, r2, r3;
+
+ r0 = ssFunc(t1, params);
+ r1 = ssFunc(p1, params, 6);
+ r2 = ssFunc(t2, params);
+ r3 = ssFunc(p2, params, 6);
+
+ if (r0 != 0 && r1 != 0 && r2 != 0 && r3 != 0)
+ {
+ VECTOR3 pa=new VECTOR3(), pb=new VECTOR3(), pc=new VECTOR3(), pd=new VECTOR3();
+ VECTOR3 v1=new VECTOR3(), v2=new VECTOR3(), n=new VECTOR3();
+ float ca;
+ int i;
+ //float lenSq, invLenSq;
+
+ superShapeMap(pa, r0, r1, t1, p1);
+ superShapeMap(pb, r2, r1, t2, p1);
+ superShapeMap(pc, r2, r3, t2, p2);
+ superShapeMap(pd, r0, r3, t1, p2);
+
+ // kludge to set lower edge of the object to fixed level
+ if (latitude == latitudeBegin + 1)
+ pa.z = pb.z = 0;
+
+ vector3Sub(v1, pb, pa);
+ vector3Sub(v2, pd, pa);
+
+ // Calculate normal with cross product.
+ /* i j k i j
+ * v1.x v1.y v1.z | v1.x v1.y
+ * v2.x v2.y v2.z | v2.x v2.y
+ */
+
+ n.x = v1.y * v2.z - v1.z * v2.y;
+ n.y = v1.z * v2.x - v1.x * v2.z;
+ n.z = v1.x * v2.y - v1.y * v2.x;
+
+ /* Pre-normalization of the normals is disabled here because
+ * they will be normalized anyway later due to automatic
+ * normalization (gl.GL_NORMALIZE). It is enabled because the
+ * objects are scaled with glScale.
+ */
+ /*
+ lenSq = n.x * n.x + n.y * n.y + n.z * n.z;
+ invLenSq = (float)(1 / sqrt(lenSq));
+ n.x *= invLenSq;
+ n.y *= invLenSq;
+ n.z *= invLenSq;
+ */
+
+ ca = pa.z + 0.5f;
+
+ for (i = currentVertex * 3;
+ i < (currentVertex + 6) * 3;
+ i += 3)
+ {
+ result.normalArray.put(i , FixedPoint.toFixed(n.x));
+ result.normalArray.put(i + 1, FixedPoint.toFixed(n.y));
+ result.normalArray.put(i + 2, FixedPoint.toFixed(n.z));
+ }
+ for (i = currentVertex * 4;
+ i < (currentVertex + 6) * 4;
+ i += 4)
+ {
+ int j, color[] = new int[3];
+ for (j = 0; j < 3; ++j)
+ {
+ color[j] = (int)(ca * baseColor[j] * 255);
+ if (color[j] > 255) color[j] = 255;
+ }
+ result.colorArray.put(i , (byte)color[0]);
+ result.colorArray.put(i + 1, (byte)color[1]);
+ result.colorArray.put(i + 2, (byte)color[2]);
+ result.colorArray.put(i + 3, (byte)0);
+ }
+ result.vertexArray.put(currentVertex * 3, FixedPoint.toFixed(pa.x));
+ result.vertexArray.put(currentVertex * 3 + 1, FixedPoint.toFixed(pa.y));
+ result.vertexArray.put(currentVertex * 3 + 2, FixedPoint.toFixed(pa.z));
+ ++currentVertex;
+ result.vertexArray.put(currentVertex * 3, FixedPoint.toFixed(pb.x));
+ result.vertexArray.put(currentVertex * 3 + 1, FixedPoint.toFixed(pb.y));
+ result.vertexArray.put(currentVertex * 3 + 2, FixedPoint.toFixed(pb.z));
+ ++currentVertex;
+ result.vertexArray.put(currentVertex * 3, FixedPoint.toFixed(pd.x));
+ result.vertexArray.put(currentVertex * 3 + 1, FixedPoint.toFixed(pd.y));
+ result.vertexArray.put(currentVertex * 3 + 2, FixedPoint.toFixed(pd.z));
+ ++currentVertex;
+ result.vertexArray.put(currentVertex * 3, FixedPoint.toFixed(pb.x));
+ result.vertexArray.put(currentVertex * 3 + 1, FixedPoint.toFixed(pb.y));
+ result.vertexArray.put(currentVertex * 3 + 2, FixedPoint.toFixed(pb.z));
+ ++currentVertex;
+ result.vertexArray.put(currentVertex * 3, FixedPoint.toFixed(pc.x));
+ result.vertexArray.put(currentVertex * 3 + 1, FixedPoint.toFixed(pc.y));
+ result.vertexArray.put(currentVertex * 3 + 2, FixedPoint.toFixed(pc.z));
+ ++currentVertex;
+ result.vertexArray.put(currentVertex * 3, FixedPoint.toFixed(pd.x));
+ result.vertexArray.put(currentVertex * 3 + 1, FixedPoint.toFixed(pd.y));
+ result.vertexArray.put(currentVertex * 3 + 2, FixedPoint.toFixed(pd.z));
+ ++currentVertex;
+ } // r0 && r1 && r2 && r3
+ ++currentQuad;
+ } // latitude
+ } // longitude
+
+ // Set number of vertices in object to the actual amount created.
+ result.count = currentVertex;
+ result.seal();
+ return result;
+}
+
+
+GLObject createGroundPlane()
+{
+ final int scale = 4;
+ final int yBegin = -15, yEnd = 15; // ends are non-inclusive
+ final int xBegin = -15, xEnd = 15;
+ final int triangleCount = (yEnd - yBegin) * (xEnd - xBegin) * 2;
+ final int vertices = triangleCount * 3;
+ GLObject result;
+ int x, y;
+ int currentVertex, currentQuad;
+
+ result = new GLObject(vertices, 2, false);
+ if (result == null)
+ return null;
+
+ currentQuad = 0;
+ currentVertex = 0;
+
+ for (y = yBegin; y < yEnd; ++y)
+ {
+ for (x = xBegin; x < xEnd; ++x)
+ {
+ byte color;
+ int i, a;
+ color = (byte)((randomUInt() & 0x5f) + 81); // 101 1111
+ for (i = currentVertex * 4; i < (currentVertex + 6) * 4; i += 4)
+ {
+ result.colorArray.put(i, color);
+ result.colorArray.put(i + 1, color);
+ result.colorArray.put(i + 2, color);
+ result.colorArray.put(i + 3, (byte)0);
+ }
+
+ // Axis bits for quad triangles:
+ // x: 011100 (0x1c), y: 110001 (0x31) (clockwise)
+ // x: 001110 (0x0e), y: 100011 (0x23) (counter-clockwise)
+ for (a = 0; a < 6; ++a)
+ {
+ final int xm = x + ((0x1c >> a) & 1);
+ final int ym = y + ((0x31 >> a) & 1);
+ final float m = (float)(Math.cos(xm * 2) * Math.sin(ym * 4) * 0.75f);
+ result.vertexArray.put(currentVertex * 2, FixedPoint.toFixed(xm * scale + m));
+ result.vertexArray.put(currentVertex * 2 + 1, FixedPoint.toFixed(ym * scale + m));
+ ++currentVertex;
+ }
+ ++currentQuad;
+ }
+ }
+ result.seal();
+ return result;
+}
+
+
+void drawGroundPlane()
+{
+ gl.glDisable(gl.GL_LIGHTING);
+ gl.glDisable(gl.GL_DEPTH_TEST);
+ if(blendingEnabled) {
+ gl.glEnable(gl.GL_BLEND);
+ gl.glBlendFunc(gl.GL_ZERO, gl.GL_SRC_COLOR);
+ }
+
+ sGroundPlane.draw();
+
+ if(blendingEnabled) {
+ gl.glDisable(gl.GL_BLEND);
+ }
+ gl.glEnable(gl.GL_DEPTH_TEST);
+ gl.glEnable(gl.GL_LIGHTING);
+}
+
+void drawFadeQuad()
+{
+ final int beginFade = (int) (sTick - sCurrentCamTrackStartTick);
+ final int endFade = (int) (sNextCamTrackStartTick - sTick);
+ final int minFade = beginFade < endFade ? beginFade : endFade;
+
+ if (minFade < 1024)
+ {
+ final int fadeColor = minFade << 7;
+ gl.glColor4x(fadeColor, fadeColor, fadeColor, 0);
+
+ gl.glDisable(gl.GL_DEPTH_TEST);
+ gl.glEnable(gl.GL_BLEND);
+ gl.glBlendFunc(gl.GL_ZERO, gl.GL_SRC_COLOR);
+ gl.glDisable(gl.GL_LIGHTING);
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
+ gl.glMatrixMode(gl.GL_PROJECTION);
+ gl.glLoadIdentity();
+
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+ gl.glDisableClientState(gl.GL_COLOR_ARRAY);
+ gl.glDisableClientState(gl.GL_NORMAL_ARRAY);
+ gl.glVertexPointer(2, gl.GL_FIXED, 0, quadVertices);
+ gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6);
+
+ gl.glEnableClientState(gl.GL_COLOR_ARRAY);
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+
+ gl.glEnable(gl.GL_LIGHTING);
+ gl.glDisable(gl.GL_BLEND);
+ gl.glEnable(gl.GL_DEPTH_TEST);
+ }
+}
+
+IntBuffer quadVertices;
+IntBuffer light0Position;
+IntBuffer light0Diffuse;
+IntBuffer light1Position;
+IntBuffer light1Diffuse;
+IntBuffer light2Position;
+IntBuffer light2Diffuse;
+IntBuffer materialSpecular;
+
+void configureLightAndMaterial()
+{
+ gl.glLightxv(gl.GL_LIGHT0, gl.GL_POSITION, light0Position);
+ gl.glLightxv(gl.GL_LIGHT0, gl.GL_DIFFUSE, light0Diffuse);
+ gl.glLightxv(gl.GL_LIGHT1, gl.GL_POSITION, light1Position);
+ gl.glLightxv(gl.GL_LIGHT1, gl.GL_DIFFUSE, light1Diffuse);
+ gl.glLightxv(gl.GL_LIGHT2, gl.GL_POSITION, light2Position);
+ gl.glLightxv(gl.GL_LIGHT2, gl.GL_DIFFUSE, light2Diffuse);
+ gl.glMaterialxv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, materialSpecular);
+
+ gl.glMaterialx(gl.GL_FRONT_AND_BACK, gl.GL_SHININESS, 60 << 16);
+ gl.glEnable(gl.GL_COLOR_MATERIAL);
+}
+
+
+void drawModels(float zScale)
+{
+ final int translationScale = 9;
+ int x, y;
+
+ seedRandom(9);
+
+ gl.glScalex(1 << 16, 1 << 16, FixedPoint.toFixed(zScale));
+
+ for (y = -5; y <= 5; ++y)
+ {
+ for (x = -5; x <= 5; ++x)
+ {
+ int curShape = randomUInt() % SuperShape.COUNT;
+ float buildingScale = SuperShape.sParams[curShape][SuperShape.PARAMS - 1];
+ int fixedScale = FixedPoint.toFixed(buildingScale);
+
+ gl.glPushMatrix();
+ gl.glTranslatex(FixedPoint.toFixed(x * translationScale),
+ FixedPoint.toFixed(y * translationScale),
+ 0);
+ gl.glRotatex(FixedPoint.toFixed((randomUInt() % 360) << 16), 0, 0, 1 << 16);
+ gl.glScalex(fixedScale, fixedScale, fixedScale);
+
+ sSuperShapeObjects[curShape].draw();
+ gl.glPopMatrix();
+ }
+ }
+
+ for (x = -2; x <= 2; ++x)
+ {
+ final int shipScale100 = translationScale * 500;
+ final int offs100 = x * shipScale100 + (int)(sTick % shipScale100);
+ float offs = offs100 * 0.01f;
+ int fixedOffs = FixedPoint.toFixed(offs);
+ gl.glPushMatrix();
+ gl.glTranslatex(fixedOffs, -4 * 65536, 2 << 16);
+ sSuperShapeObjects[SuperShape.COUNT - 1].draw();
+ gl.glPopMatrix();
+ gl.glPushMatrix();
+ gl.glTranslatex(-4 * 65536, fixedOffs, 4 << 16);
+ gl.glRotatex(90 << 16, 0, 0, 1 << 16);
+ sSuperShapeObjects[SuperShape.COUNT - 1].draw();
+ gl.glPopMatrix();
+ }
+}
+
+
+void camTrack()
+{
+ float lerp[]= new float[5];
+ float eX, eY, eZ, cX, cY, cZ;
+ float trackPos;
+ CamTrack cam;
+ long currentCamTick;
+ int a;
+
+ if (sNextCamTrackStartTick <= sTick)
+ {
+ ++sCurrentCamTrack;
+ sCurrentCamTrackStartTick = sNextCamTrackStartTick;
+ }
+ sNextCamTrackStartTick = sCurrentCamTrackStartTick +
+ CamTrack.sCamTracks[sCurrentCamTrack].len * CamTrack.CAMTRACK_LEN;
+
+ cam = CamTrack.sCamTracks[sCurrentCamTrack];
+ currentCamTick = sTick - sCurrentCamTrackStartTick;
+ trackPos = (float)currentCamTick / (CamTrack.CAMTRACK_LEN * cam.len);
+
+ for (a = 0; a < 5; ++a)
+ lerp[a] = (cam.src[a] + cam.dest[a] * trackPos) * 0.01f;
+
+ if (cam.dist>0)
+ {
+ float dist = cam.dist * 0.1f;
+ cX = lerp[0];
+ cY = lerp[1];
+ cZ = lerp[2];
+ eX = cX - (float)Math.cos(lerp[3]) * dist;
+ eY = cY - (float)Math.sin(lerp[3]) * dist;
+ eZ = cZ - lerp[4];
+ }
+ else
+ {
+ eX = lerp[0];
+ eY = lerp[1];
+ eZ = lerp[2];
+ cX = eX + (float)Math.cos(lerp[3]);
+ cY = eY + (float)Math.sin(lerp[3]);
+ cZ = eZ + lerp[4];
+ }
+ glu.gluLookAt(eX, eY, eZ, cX, cY, cZ, 0, 0, 1);
+}
+
+private int gAppAlive = 0;
+private int width, height, x, y, frames;
+
+}
+
diff --git a/src/demos/es1/angeles/AngelesGL.java b/src/demos/es1/angeles/AngelesGL.java
new file mode 100755
index 0000000..bae7b5c
--- /dev/null
+++ b/src/demos/es1/angeles/AngelesGL.java
@@ -0,0 +1,816 @@
+/* San Angeles Observation OpenGL ES version example
+ * Copyright 2004-2005 Jetro Lauha
+ * All rights reserved.
+ * Web: http://iki.fi/jetro/
+ *
+ * This source is free software; you can redistribute it and/or
+ * modify it under the terms of EITHER:
+ * (1) The GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version. The text of the GNU Lesser
+ * General Public License is included with this source in the
+ * file LICENSE-LGPL.txt.
+ * (2) The BSD-style license that is included with this source in
+ * the file LICENSE-BSD.txt.
+ *
+ * This source is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
+ * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
+ *
+ * $Id$
+ * $Revision$
+ */
+
+package demos.es1.angeles;
+
+import javax.media.opengl.*;
+import javax.media.opengl.glu.*;
+import com.sun.opengl.util.*;
+import com.sun.opengl.util.glsl.fixedfunc.*;
+import java.nio.*;
+
+public class AngelesGL implements GLEventListener {
+
+ public AngelesGL(boolean enableBlending) {
+ blendingEnabled = enableBlending;
+ quadVertices = BufferUtil.newFloatBuffer(12);
+ quadVertices.put(new float[]{
+ -1.0f, -1.0f,
+ 1.0f, -1.0f,
+ -1.0f, 1.0f,
+ 1.0f, -1.0f,
+ 1.0f, 1.0f,
+ -1.0f, 1.0f
+ });
+ quadVertices.flip();
+
+ light0Position=BufferUtil.newFloatBuffer(4);
+ light0Diffuse=BufferUtil.newFloatBuffer(4);
+ light1Position=BufferUtil.newFloatBuffer(4);
+ light1Diffuse=BufferUtil.newFloatBuffer(4);
+ light2Position=BufferUtil.newFloatBuffer(4);
+ light2Diffuse=BufferUtil.newFloatBuffer(4);
+ materialSpecular=BufferUtil.newFloatBuffer(4);
+
+ light0Position.put(new float[] { FixedPoint.toFloat(-0x40000), 1.0f, 1.0f, 0.0f });
+ light0Diffuse.put(new float[] { 1.0f, FixedPoint.toFloat(0x6666), 0.0f, 1.0f });
+ light1Position.put(new float[] { 1.0f, FixedPoint.toFloat(-0x20000), -1.0f, 0.0f });
+ light1Diffuse.put(new float[] { FixedPoint.toFloat(0x11eb), FixedPoint.toFloat(0x23d7), FixedPoint.toFloat(0x5999), 1.0f });
+ light2Position.put(new float[] { -1.0f, 0.0f, FixedPoint.toFloat(-0x40000), 0.0f });
+ light2Diffuse.put(new float[] { FixedPoint.toFloat(0x11eb), FixedPoint.toFloat(0x2b85), FixedPoint.toFloat(0x23d7), 1.0f });
+ materialSpecular.put(new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
+
+ light0Position.flip();
+ light0Diffuse.flip();
+ light1Position.flip();
+ light1Diffuse.flip();
+ light2Position.flip();
+ light2Diffuse.flip();
+ materialSpecular.flip();
+
+ seedRandom(15);
+
+ width=0;
+ height=0;
+ x=0;
+ y=0;
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ // FIXME: gl.setSwapInterval(1);
+
+ cComps = drawable.getGL().isGLES1() ? 4: 3;
+
+ this.gl = FixedFuncUtil.getFixedFuncImpl(drawable.getGL());
+ System.err.println("AngelesGL: "+this.gl);
+
+ this.glu = GLU.createGLU();
+
+ gl.glEnable(GL2ES1.GL_NORMALIZE);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ gl.glDisable(GL.GL_CULL_FACE);
+ gl.glCullFace(GL.GL_BACK);
+ gl.glShadeModel(gl.GL_FLAT);
+
+ gl.glEnable(gl.GL_LIGHTING);
+ gl.glEnable(gl.GL_LIGHT0);
+ gl.glEnable(gl.GL_LIGHT1);
+ gl.glEnable(gl.GL_LIGHT2);
+
+ gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
+ gl.glEnableClientState(gl.GL_COLOR_ARRAY);
+
+ for (int a = 0; a < SuperShape.COUNT; ++a)
+ {
+ sSuperShapeObjects[a] = createSuperShape(SuperShape.sParams[a]);
+ }
+ sGroundPlane = createGroundPlane();
+
+ gAppAlive = 1;
+
+ sStartTick = System.currentTimeMillis();
+ frames=0;
+
+ /*
+ gl.glGetError(); // flush error ..
+ if(gl.isGLES2()) {
+ GLES2 gles2 = gl.getGLES2();
+
+ // Debug ..
+ //DebugGLES2 gldbg = new DebugGLES2(gles2);
+ //gles2.getContext().setGL(gldbg);
+ //gles2 = gldbg;
+
+ // Trace ..
+ TraceGLES2 gltrace = new TraceGLES2(gles2, System.err);
+ gles2.getContext().setGL(gltrace);
+ gles2 = gltrace;
+ } */
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ this.width = width;
+ this.height=height;
+ this.x = x;
+ this.y = y;
+
+ this.gl = drawable.getGL().getGL2ES1();
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
+ gl.glClearColor(0.1f, 0.2f, 0.3f, 1.0f);
+
+ // JAU gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_FASTEST);
+
+ //gl.glShadeModel(gl.GL_SMOOTH);
+ gl.glShadeModel(gl.GL_FLAT);
+ gl.glDisable(GL.GL_DITHER);
+
+ //gl.glMatrixMode(gl.GL_PROJECTION);
+ //gl.glLoadIdentity();
+ //glu.gluPerspective(45.0f, (float)width / (float)height, 0.5f, 150.0f);
+
+ //System.out.println("reshape ..");
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ long tick = System.currentTimeMillis();
+
+ if (gAppAlive==0)
+ return;
+
+ this.gl = drawable.getGL().getGL2ES1();
+
+ // Actual tick value is "blurred" a little bit.
+ sTick = (sTick + tick - sStartTick) >> 1;
+
+ // Terminate application after running through the demonstration once.
+ if (sTick >= RUN_LENGTH)
+ {
+ gAppAlive = 0;
+ return;
+ }
+
+ gl.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_COLOR_BUFFER_BIT);
+
+ gl.glMatrixMode(gl.GL_PROJECTION);
+ gl.glLoadIdentity();
+ glu.gluPerspective(45.0f, (float)width / (float)height, 0.5f, 150.0f);
+
+ // Update the camera position and set the lookat.
+ camTrack();
+
+ // Configure environment.
+ configureLightAndMaterial();
+
+ if(blendingEnabled) {
+ gl.glEnable(GL.GL_CULL_FACE);
+ // Draw the reflection by drawing models with negated Z-axis.
+ gl.glPushMatrix();
+ drawModels(-1);
+ gl.glPopMatrix();
+ }
+
+ // Draw the ground plane to the window. (opt. blending)
+ drawGroundPlane();
+
+ if(blendingEnabled) {
+ gl.glDisable(GL.GL_CULL_FACE);
+ }
+
+ // Draw all the models normally.
+ drawModels(1);
+
+ if(blendingEnabled) {
+ // Draw fade quad over whole window (when changing cameras).
+ drawFadeQuad();
+ }
+
+ frames++;
+ tick = System.currentTimeMillis();
+ }
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+ }
+
+ private boolean blendingEnabled = true;
+ private GL2ES1 gl; // temp cache
+ private GLU glu;
+
+ // Total run length is 20 * camera track base unit length (see cams.h).
+ private int RUN_LENGTH = (20 * CamTrack.CAMTRACK_LEN) ;
+ private int RANDOM_UINT_MAX = 65535 ;
+
+ private long sRandomSeed = 0;
+
+void seedRandom(long seed)
+{
+ sRandomSeed = seed;
+}
+
+int randomUInt()
+{
+ sRandomSeed = sRandomSeed * 0x343fd + 0x269ec3;
+ return Math.abs((int) (sRandomSeed >> 16));
+}
+
+private int cComps;
+
+// Definition of one GL object in this demo.
+public class GLSpatial {
+ /* Vertex array and color array are enabled for all objects, so their
+ * pointers must always be valid and non-null. Normal array is not
+ * used by the ground plane, so when its pointer is null then normal
+ * array usage is disabled.
+ *
+ * Vertex array is supposed to use GL.GL_FLOAT datatype and stride 0
+ * (i.e. tightly packed array). Color array is supposed to have 4
+ * components per color with GL.GL_UNSIGNED_BYTE datatype and stride 0.
+ * Normal array is supposed to use GL.GL_FLOAT datatype and stride 0.
+ */
+ private int vboName, count;
+ private int vComps, nComps;
+ private ByteBuffer pBuffer=null;
+ private FloatBuffer vertexArray=null;
+ private FloatBuffer colorArray=null;
+ private FloatBuffer normalArray=null;
+ protected GLArrayDataWrapper vArrayData, cArrayData, nArrayData=null;
+
+ public GLSpatial(int vertices, int vertexComponents,
+ boolean useNormalArray) {
+ count = vertices;
+ vComps= vertexComponents;
+ nComps = useNormalArray ? 3 : 0;
+
+ int bSize = BufferUtil.sizeOfGLType(GL.GL_FLOAT) * count * ( vComps + cComps + nComps) ;
+ pBuffer = BufferUtil.newByteBuffer(bSize);
+
+ int pos = 0;
+ int size= BufferUtil.sizeOfGLType(GL.GL_FLOAT) * count * vComps ;
+ vertexArray = (FloatBuffer) BufferUtil.sliceGLBuffer(pBuffer, pos, size, GL.GL_FLOAT);
+ int vOffset = 0;
+ pos+=size;
+
+ size=BufferUtil.sizeOfGLType(GL.GL_FLOAT) * count * cComps ;
+ colorArray = (FloatBuffer) BufferUtil.sliceGLBuffer(pBuffer, pos, size, GL.GL_FLOAT);
+ int cOffset=pos;
+ pos+=size;
+
+ int nOffset=0;
+ if(useNormalArray) {
+ size=BufferUtil.sizeOfGLType(GL.GL_FLOAT) * count * nComps ;
+ normalArray = (FloatBuffer) BufferUtil.sliceGLBuffer(pBuffer, pos, size, GL.GL_FLOAT);
+ nOffset=pos;
+ pos+=size;
+ }
+ pBuffer.position(pos);
+ pBuffer.flip();
+
+ int[] tmp = new int[1];
+ gl.glGenBuffers(1, tmp, 0);
+ vboName = tmp[0];
+
+ vArrayData = GLArrayDataWrapper.createFixed(gl, gl.GL_VERTEX_ARRAY, vComps, GL.GL_FLOAT, false,
+ 0, pBuffer, vboName, vOffset);
+ cArrayData = GLArrayDataWrapper.createFixed(gl, gl.GL_COLOR_ARRAY, cComps, GL.GL_FLOAT, false,
+ 0, pBuffer, vboName, cOffset);
+ if(useNormalArray) {
+ nArrayData = GLArrayDataWrapper.createFixed(gl, gl.GL_NORMAL_ARRAY, nComps, GL.GL_FLOAT, false,
+ 0, pBuffer, vboName, nOffset);
+ }
+ }
+
+ void setCount(int c) {
+ if(count != c) {
+ throw new RuntimeException("diff count: "+count+" -> "+c);
+ }
+ count = c;
+ }
+
+ private boolean sealed = false;
+
+ void seal()
+ {
+ if(sealed) return;
+ sealed = true;
+
+ vertexArray.position(count);
+ vertexArray.flip();
+ colorArray.position(count);
+ colorArray.flip();
+ if(nComps>0) {
+ normalArray.position(count);
+ normalArray.flip();
+ }
+
+ if(nComps>0) {
+ gl.glEnableClientState(gl.GL_NORMAL_ARRAY);
+ }
+
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName);
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, pBuffer.limit(), pBuffer, GL.GL_STATIC_DRAW);
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+
+ if(nComps>0) {
+ gl.glDisableClientState(gl.GL_NORMAL_ARRAY);
+ }
+ }
+
+ void draw()
+ {
+ seal();
+ if(nComps>0) {
+ gl.glEnableClientState(gl.GL_NORMAL_ARRAY);
+ }
+
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName);
+
+ gl.glVertexPointer(vArrayData);
+ gl.glColorPointer(cArrayData);
+ if(nComps>0) {
+ gl.glNormalPointer(nArrayData);
+ }
+
+
+ gl.glDrawArrays(GL.GL_TRIANGLES, 0, count);
+
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+
+ if(nComps>0) {
+ gl.glDisableClientState(gl.GL_NORMAL_ARRAY);
+ }
+ }
+}
+
+long sStartTick = 0;
+long sTick = 0;
+
+int sCurrentCamTrack = 0;
+long sCurrentCamTrackStartTick = 0;
+long sNextCamTrackStartTick = 0x7fffffff;
+
+GLSpatial sSuperShapeObjects[] = new GLSpatial[SuperShape.COUNT];
+GLSpatial sGroundPlane;
+
+
+public class VECTOR3 {
+ float x, y, z;
+
+ public VECTOR3() {
+ x=0f; y=0f; z=0f;
+ }
+ public VECTOR3(float x, float y, float z) {
+ this.x=x;
+ this.y=y;
+ this.z=z;
+ }
+}
+
+
+
+static void vector3Sub(VECTOR3 dest, VECTOR3 v1, VECTOR3 v2)
+{
+ dest.x = v1.x - v2.x;
+ dest.y = v1.y - v2.y;
+ dest.z = v1.z - v2.z;
+}
+
+
+static void superShapeMap(VECTOR3 point, float r1, float r2, float t, float p)
+{
+ // sphere-mapping of supershape parameters
+ point.x = (float)(Math.cos(t) * Math.cos(p) / r1 / r2);
+ point.y = (float)(Math.sin(t) * Math.cos(p) / r1 / r2);
+ point.z = (float)(Math.sin(p) / r2);
+}
+
+
+float ssFunc(final float t, final float p[])
+{
+ return ssFunc(t, p, 0);
+}
+
+float ssFunc(final float t, final float p[], int pOff)
+{
+ return (float)(Math.pow(Math.pow(Math.abs(Math.cos(p[0+pOff] * t / 4)) / p[1+pOff], p[4+pOff]) +
+ Math.pow(Math.abs(Math.sin(p[0+pOff] * t / 4)) / p[2+pOff], p[5+pOff]), 1 / p[3+pOff]));
+}
+
+
+// Creates and returns a supershape object.
+// Based on Paul Bourke's POV-Ray implementation.
+// http://astronomy.swin.edu.au/~pbourke/povray/supershape/
+GLSpatial createSuperShape(final float params[])
+{
+ final int resol1 = (int)params[SuperShape.PARAMS - 3];
+ final int resol2 = (int)params[SuperShape.PARAMS - 2];
+ // latitude 0 to pi/2 for no mirrored bottom
+ // (latitudeBegin==0 for -pi/2 to pi/2 originally)
+ final int latitudeBegin = resol2 / 4;
+ final int latitudeEnd = resol2 / 2; // non-inclusive
+ final int longitudeCount = resol1;
+ final int latitudeCount = latitudeEnd - latitudeBegin;
+ final int triangleCount = longitudeCount * latitudeCount * 2;
+ final int vertices = triangleCount * 3;
+ GLSpatial result;
+ float baseColor[] = new float[3];
+ int a, longitude, latitude;
+ int currentVertex, currentQuad;
+
+ result = new GLSpatial(vertices, 3, true);
+ if (result == null)
+ return null;
+
+ for (a = 0; a < 3; ++a)
+ baseColor[a] = ((randomUInt() % 155) + 100) / 255.f;
+
+ currentQuad = 0;
+ currentVertex = 0;
+
+ // longitude -pi to pi
+ for (longitude = 0; longitude < longitudeCount; ++longitude)
+ {
+
+ // latitude 0 to pi/2
+ for (latitude = latitudeBegin; latitude < latitudeEnd; ++latitude)
+ {
+ float t1 = (float) ( -Math.PI + longitude * 2 * Math.PI / resol1 );
+ float t2 = (float) ( -Math.PI + (longitude + 1) * 2 * Math.PI / resol1 );
+ float p1 = (float) ( -Math.PI / 2 + latitude * 2 * Math.PI / resol2 );
+ float p2 = (float) ( -Math.PI / 2 + (latitude + 1) * 2 * Math.PI / resol2 );
+ float r0, r1, r2, r3;
+
+ r0 = ssFunc(t1, params);
+ r1 = ssFunc(p1, params, 6);
+ r2 = ssFunc(t2, params);
+ r3 = ssFunc(p2, params, 6);
+
+ if (r0 != 0 && r1 != 0 && r2 != 0 && r3 != 0)
+ {
+ VECTOR3 pa=new VECTOR3(), pb=new VECTOR3(), pc=new VECTOR3(), pd=new VECTOR3();
+ VECTOR3 v1=new VECTOR3(), v2=new VECTOR3(), n=new VECTOR3();
+ float ca;
+ int i;
+ //float lenSq, invLenSq;
+
+ superShapeMap(pa, r0, r1, t1, p1);
+ superShapeMap(pb, r2, r1, t2, p1);
+ superShapeMap(pc, r2, r3, t2, p2);
+ superShapeMap(pd, r0, r3, t1, p2);
+
+ // kludge to set lower edge of the object to fixed level
+ if (latitude == latitudeBegin + 1)
+ pa.z = pb.z = 0;
+
+ vector3Sub(v1, pb, pa);
+ vector3Sub(v2, pd, pa);
+
+ // Calculate normal with cross product.
+ /* i j k i j
+ * v1.x v1.y v1.z | v1.x v1.y
+ * v2.x v2.y v2.z | v2.x v2.y
+ */
+
+ n.x = v1.y * v2.z - v1.z * v2.y;
+ n.y = v1.z * v2.x - v1.x * v2.z;
+ n.z = v1.x * v2.y - v1.y * v2.x;
+
+ /* Pre-normalization of the normals is disabled here because
+ * they will be normalized anyway later due to automatic
+ * normalization (GL2ES1.GL_NORMALIZE). It is enabled because the
+ * objects are scaled with glScale.
+ */
+ /*
+ lenSq = n.x * n.x + n.y * n.y + n.z * n.z;
+ invLenSq = (float)(1 / sqrt(lenSq));
+ n.x *= invLenSq;
+ n.y *= invLenSq;
+ n.z *= invLenSq;
+ */
+
+ ca = pa.z + 0.5f;
+
+ if(result.normalArray!=null) {
+ for (i = currentVertex * 3;
+ i < (currentVertex + 6) * 3;
+ i += 3)
+ {
+ result.normalArray.put(i , (n.x));
+ result.normalArray.put(i + 1, (n.y));
+ result.normalArray.put(i + 2, (n.z));
+ }
+ }
+ for (i = currentVertex * cComps;
+ i < (currentVertex + 6) * cComps;
+ i += cComps)
+ {
+ int j;
+ float color[] = new float[3];
+ for (j = 0; j < 3; ++j)
+ {
+ color[j] = ca * baseColor[j];
+ if (color[j] > 1.0f) color[j] = 1.0f;
+ }
+ result.colorArray.put(i , color[0]);
+ result.colorArray.put(i + 1, color[1]);
+ result.colorArray.put(i + 2, color[2]);
+ if(3<cComps) {
+ result.colorArray.put(i + 3, 0f);
+ }
+ }
+ result.vertexArray.put(currentVertex * 3, (pa.x));
+ result.vertexArray.put(currentVertex * 3 + 1, (pa.y));
+ result.vertexArray.put(currentVertex * 3 + 2, (pa.z));
+ ++currentVertex;
+ result.vertexArray.put(currentVertex * 3, (pb.x));
+ result.vertexArray.put(currentVertex * 3 + 1, (pb.y));
+ result.vertexArray.put(currentVertex * 3 + 2, (pb.z));
+ ++currentVertex;
+ result.vertexArray.put(currentVertex * 3, (pd.x));
+ result.vertexArray.put(currentVertex * 3 + 1, (pd.y));
+ result.vertexArray.put(currentVertex * 3 + 2, (pd.z));
+ ++currentVertex;
+ result.vertexArray.put(currentVertex * 3, (pb.x));
+ result.vertexArray.put(currentVertex * 3 + 1, (pb.y));
+ result.vertexArray.put(currentVertex * 3 + 2, (pb.z));
+ ++currentVertex;
+ result.vertexArray.put(currentVertex * 3, (pc.x));
+ result.vertexArray.put(currentVertex * 3 + 1, (pc.y));
+ result.vertexArray.put(currentVertex * 3 + 2, (pc.z));
+ ++currentVertex;
+ result.vertexArray.put(currentVertex * 3, (pd.x));
+ result.vertexArray.put(currentVertex * 3 + 1, (pd.y));
+ result.vertexArray.put(currentVertex * 3 + 2, (pd.z));
+ ++currentVertex;
+ } // r0 && r1 && r2 && r3
+ ++currentQuad;
+ } // latitude
+ } // longitude
+
+ // Set number of vertices in object to the actual amount created.
+ result.setCount(currentVertex);
+ result.seal();
+ return result;
+}
+
+
+GLSpatial createGroundPlane()
+{
+ final int scale = 4;
+ final int yBegin = -15, yEnd = 15; // ends are non-inclusive
+ final int xBegin = -15, xEnd = 15;
+ final int triangleCount = (yEnd - yBegin) * (xEnd - xBegin) * 2;
+ final int vertices = triangleCount * 3;
+ GLSpatial result;
+ int x, y;
+ int currentVertex, currentQuad;
+ final int vcomps = 2;
+
+ result = new GLSpatial(vertices, vcomps, false);
+ if (result == null)
+ return null;
+
+ currentQuad = 0;
+ currentVertex = 0;
+
+ for (y = yBegin; y < yEnd; ++y)
+ {
+ for (x = xBegin; x < xEnd; ++x)
+ {
+ float color;
+ int i, a;
+ color = ((float)(randomUInt() % 255))/255.0f;
+ for (i = currentVertex * cComps; i < (currentVertex + 6) * cComps; i += cComps)
+ {
+ result.colorArray.put(i, color);
+ result.colorArray.put(i + 1, color);
+ result.colorArray.put(i + 2, color);
+ if(3<cComps) {
+ result.colorArray.put(i + 3, 0);
+ }
+ }
+
+ // Axis bits for quad triangles:
+ // x: 011100 (0x1c), y: 110001 (0x31) (clockwise)
+ // x: 001110 (0x0e), y: 100011 (0x23) (counter-clockwise)
+ for (a = 0; a < 6; ++a)
+ {
+ final int xm = x + ((0x1c >> a) & 1);
+ final int ym = y + ((0x31 >> a) & 1);
+ final float m = (float)(Math.cos(xm * 2) * Math.sin(ym * 4) * 0.75f);
+ result.vertexArray.put(currentVertex * vcomps, (xm * scale + m));
+ result.vertexArray.put(currentVertex * vcomps + 1, (ym * scale + m));
+ if(2<vcomps) {
+ result.vertexArray.put(currentVertex * vcomps + 2, 0f);
+ }
+ ++currentVertex;
+ }
+ ++currentQuad;
+ }
+ }
+ result.seal();
+ return result;
+}
+
+
+void drawGroundPlane()
+{
+ gl.glDisable(gl.GL_LIGHTING);
+ gl.glDisable(GL.GL_DEPTH_TEST);
+ if(blendingEnabled) {
+ gl.glEnable(GL.GL_BLEND);
+ gl.glBlendFunc(GL.GL_ZERO, GL.GL_SRC_COLOR);
+ }
+
+ sGroundPlane.draw();
+
+ if(blendingEnabled) {
+ gl.glDisable(GL.GL_BLEND);
+ }
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ gl.glEnable(gl.GL_LIGHTING);
+}
+
+void drawFadeQuad()
+{
+ final int beginFade = (int) (sTick - sCurrentCamTrackStartTick);
+ final int endFade = (int) (sNextCamTrackStartTick - sTick);
+ final int minFade = beginFade < endFade ? beginFade : endFade;
+
+ if (minFade < 1024)
+ {
+ final float fadeColor = FixedPoint.toFloat(minFade << 7);
+ gl.glColor4f(fadeColor, fadeColor, fadeColor, 0f);
+
+ gl.glDisable(GL.GL_DEPTH_TEST);
+ gl.glEnable(GL.GL_BLEND);
+ gl.glBlendFunc(GL.GL_ZERO, GL.GL_SRC_COLOR);
+ gl.glDisable(gl.GL_LIGHTING);
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
+ gl.glMatrixMode(gl.GL_PROJECTION);
+ gl.glLoadIdentity();
+
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+ gl.glDisableClientState(gl.GL_COLOR_ARRAY);
+ gl.glDisableClientState(gl.GL_NORMAL_ARRAY);
+ gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
+ gl.glVertexPointer(2, GL.GL_FLOAT, 0, quadVertices);
+ gl.glDrawArrays(GL.GL_TRIANGLES, 0, 6);
+ gl.glEnableClientState(gl.GL_COLOR_ARRAY);
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+
+ gl.glEnable(gl.GL_LIGHTING);
+ gl.glDisable(GL.GL_BLEND);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ }
+}
+
+FloatBuffer quadVertices;
+FloatBuffer light0Position;
+FloatBuffer light0Diffuse;
+FloatBuffer light1Position;
+FloatBuffer light1Diffuse;
+FloatBuffer light2Position;
+FloatBuffer light2Diffuse;
+FloatBuffer materialSpecular;
+
+void configureLightAndMaterial()
+{
+ gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, light0Position);
+ gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, light0Diffuse);
+ gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, light1Position);
+ gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, light1Diffuse);
+ gl.glLightfv(gl.GL_LIGHT2, gl.GL_POSITION, light2Position);
+ gl.glLightfv(gl.GL_LIGHT2, gl.GL_DIFFUSE, light2Diffuse);
+ gl.glMaterialfv(GL.GL_FRONT_AND_BACK, gl.GL_SPECULAR, materialSpecular);
+
+ gl.glMaterialf(GL.GL_FRONT_AND_BACK, gl.GL_SHININESS, 60.0f);
+ gl.glEnable(gl.GL_COLOR_MATERIAL);
+}
+
+
+void drawModels(float zScale)
+{
+ final int translationScale = 9;
+ int x, y;
+
+ seedRandom(9);
+
+ gl.glScalef(1.0f, 1.0f, zScale);
+
+ for (y = -5; y <= 5; ++y)
+ {
+ for (x = -5; x <= 5; ++x)
+ {
+ int curShape = randomUInt() % SuperShape.COUNT;
+ float buildingScale = SuperShape.sParams[curShape][SuperShape.PARAMS - 1];
+
+ gl.glPushMatrix();
+ gl.glTranslatef((float)(x * translationScale),
+ (float)(y * translationScale),
+ 0f);
+ gl.glRotatef((float)(randomUInt() % 360), 0f, 0f, 1f);
+ gl.glScalef(buildingScale, buildingScale, buildingScale);
+
+ sSuperShapeObjects[curShape].draw();
+ gl.glPopMatrix();
+ }
+ }
+
+ for (x = -2; x <= 2; ++x)
+ {
+ final int shipScale100 = translationScale * 500;
+ final int offs100 = x * shipScale100 + (int)(sTick % shipScale100);
+ float offs = offs100 * 0.01f;
+ gl.glPushMatrix();
+ gl.glTranslatef(offs, -4.0f, 2.0f);
+ sSuperShapeObjects[SuperShape.COUNT - 1].draw();
+ gl.glPopMatrix();
+ gl.glPushMatrix();
+ gl.glTranslatef(-4.0f, offs, 4.0f);
+ gl.glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
+ sSuperShapeObjects[SuperShape.COUNT - 1].draw();
+ gl.glPopMatrix();
+ }
+}
+
+
+void camTrack()
+{
+ float lerp[]= new float[5];
+ float eX, eY, eZ, cX, cY, cZ;
+ float trackPos;
+ CamTrack cam;
+ long currentCamTick;
+ int a;
+
+ if (sNextCamTrackStartTick <= sTick)
+ {
+ ++sCurrentCamTrack;
+ sCurrentCamTrackStartTick = sNextCamTrackStartTick;
+ }
+ sNextCamTrackStartTick = sCurrentCamTrackStartTick +
+ CamTrack.sCamTracks[sCurrentCamTrack].len * CamTrack.CAMTRACK_LEN;
+
+ cam = CamTrack.sCamTracks[sCurrentCamTrack];
+ currentCamTick = sTick - sCurrentCamTrackStartTick;
+ trackPos = (float)currentCamTick / (CamTrack.CAMTRACK_LEN * cam.len);
+
+ for (a = 0; a < 5; ++a)
+ lerp[a] = (cam.src[a] + cam.dest[a] * trackPos) * 0.01f;
+
+ if (cam.dist>0)
+ {
+ float dist = cam.dist * 0.1f;
+ cX = lerp[0];
+ cY = lerp[1];
+ cZ = lerp[2];
+ eX = cX - (float)Math.cos(lerp[3]) * dist;
+ eY = cY - (float)Math.sin(lerp[3]) * dist;
+ eZ = cZ - lerp[4];
+ }
+ else
+ {
+ eX = lerp[0];
+ eY = lerp[1];
+ eZ = lerp[2];
+ cX = eX + (float)Math.cos(lerp[3]);
+ cY = eY + (float)Math.sin(lerp[3]);
+ cZ = eZ + lerp[4];
+ }
+ glu.gluLookAt(eX, eY, eZ, cX, cY, cZ, 0, 0, 1);
+}
+
+private int gAppAlive = 0;
+private int width, height, x, y, frames;
+}
+
diff --git a/src/demos/es1/angeles/AngelesGLil.java b/src/demos/es1/angeles/AngelesGLil.java
new file mode 100755
index 0000000..aaae01e
--- /dev/null
+++ b/src/demos/es1/angeles/AngelesGLil.java
@@ -0,0 +1,842 @@
+/* San Angeles Observation OpenGL ES version example
+ * Copyright 2004-2005 Jetro Lauha
+ * All rights reserved.
+ * Web: http://iki.fi/jetro/
+ *
+ * This source is free software; you can redistribute it and/or
+ * modify it under the terms of EITHER:
+ * (1) The GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version. The text of the GNU Lesser
+ * General Public License is included with this source in the
+ * file LICENSE-LGPL.txt.
+ * (2) The BSD-style license that is included with this source in
+ * the file LICENSE-BSD.txt.
+ *
+ * This source is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
+ * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
+ *
+ * $Id$
+ * $Revision$
+ */
+
+package demos.es1.angeles;
+
+import javax.media.opengl.*;
+import javax.media.opengl.glu.*;
+import com.sun.opengl.util.*;
+import com.sun.opengl.util.glsl.fixedfunc.*;
+import java.nio.*;
+
+public class AngelesGLil implements GLEventListener {
+
+ public AngelesGLil(boolean enableBlending) {
+ blendingEnabled = enableBlending;
+ quadVertices = BufferUtil.newFloatBuffer(12);
+ quadVertices.put(new float[]{
+ -1.0f, -1.0f,
+ 1.0f, -1.0f,
+ -1.0f, 1.0f,
+ 1.0f, -1.0f,
+ 1.0f, 1.0f,
+ -1.0f, 1.0f
+ });
+ quadVertices.flip();
+
+ light0Position=BufferUtil.newFloatBuffer(4);
+ light0Diffuse=BufferUtil.newFloatBuffer(4);
+ light1Position=BufferUtil.newFloatBuffer(4);
+ light1Diffuse=BufferUtil.newFloatBuffer(4);
+ light2Position=BufferUtil.newFloatBuffer(4);
+ light2Diffuse=BufferUtil.newFloatBuffer(4);
+ materialSpecular=BufferUtil.newFloatBuffer(4);
+
+ light0Position.put(new float[] { FixedPoint.toFloat(-0x40000), 1.0f, 1.0f, 0.0f });
+ light0Diffuse.put(new float[] { 1.0f, FixedPoint.toFloat(0x6666), 0.0f, 1.0f });
+ light1Position.put(new float[] { 1.0f, FixedPoint.toFloat(-0x20000), -1.0f, 0.0f });
+ light1Diffuse.put(new float[] { FixedPoint.toFloat(0x11eb), FixedPoint.toFloat(0x23d7), FixedPoint.toFloat(0x5999), 1.0f });
+ light2Position.put(new float[] { -1.0f, 0.0f, FixedPoint.toFloat(-0x40000), 0.0f });
+ light2Diffuse.put(new float[] { FixedPoint.toFloat(0x11eb), FixedPoint.toFloat(0x2b85), FixedPoint.toFloat(0x23d7), 1.0f });
+ materialSpecular.put(new float[] { 1.0f, 1.0f, 1.0f, 1.0f });
+
+ light0Position.flip();
+ light0Diffuse.flip();
+ light1Position.flip();
+ light1Diffuse.flip();
+ light2Position.flip();
+ light2Diffuse.flip();
+ materialSpecular.flip();
+
+ seedRandom(15);
+
+ width=0;
+ height=0;
+ x=0;
+ y=0;
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ // FIXME: gl.setSwapInterval(1);
+
+ cComps = drawable.getGL().isGLES1() ? 4: 3;
+
+ this.gl = FixedFuncUtil.getFixedFuncImpl(drawable.getGL());
+ System.err.println("AngelesGL: "+this.gl);
+
+ this.glu = GLU.createGLU();
+
+ gl.glEnable(GL2ES1.GL_NORMALIZE);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ gl.glDisable(GL.GL_CULL_FACE);
+ gl.glCullFace(GL.GL_BACK);
+ gl.glShadeModel(gl.GL_FLAT);
+
+ gl.glEnable(gl.GL_LIGHTING);
+ gl.glEnable(gl.GL_LIGHT0);
+ gl.glEnable(gl.GL_LIGHT1);
+ gl.glEnable(gl.GL_LIGHT2);
+
+ gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
+ gl.glEnableClientState(gl.GL_COLOR_ARRAY);
+
+ for (int a = 0; a < SuperShape.COUNT; ++a)
+ {
+ sSuperShapeObjects[a] = createSuperShape(SuperShape.sParams[a]);
+ }
+ sGroundPlane = createGroundPlane();
+
+ gAppAlive = 1;
+
+ sStartTick = System.currentTimeMillis();
+ frames=0;
+
+ /*
+ gl.glGetError(); // flush error ..
+ if(gl.isGLES2()) {
+ GLES2 gles2 = gl.getGLES2();
+
+ // Debug ..
+ //DebugGLES2 gldbg = new DebugGLES2(gles2);
+ //gles2.getContext().setGL(gldbg);
+ //gles2 = gldbg;
+
+ // Trace ..
+ TraceGLES2 gltrace = new TraceGLES2(gles2, System.err);
+ gles2.getContext().setGL(gltrace);
+ gles2 = gltrace;
+ } else if(gl.isGL2()) {
+ GL2 gl2 = gl.getGL2();
+
+ // Debug ..
+ //DebugGL2 gldbg = new DebugGL2(gl2);
+ //gl2.getContext().setGL(gldbg);
+ //gl2 = gldbg;
+
+ // Trace ..
+ TraceGL2 gltrace = new TraceGL2(gl2, System.err);
+ gl2.getContext().setGL(gltrace);
+ gl2 = gltrace;
+ } */
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ this.width = width;
+ this.height=height;
+ this.x = x;
+ this.y = y;
+
+ this.gl = drawable.getGL().getGL2ES1();
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
+ gl.glClearColor(0.1f, 0.2f, 0.3f, 1.0f);
+
+ // JAU gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_FASTEST);
+
+ //gl.glShadeModel(gl.GL_SMOOTH);
+ gl.glShadeModel(gl.GL_FLAT);
+ gl.glDisable(GL.GL_DITHER);
+
+ //gl.glMatrixMode(gl.GL_PROJECTION);
+ //gl.glLoadIdentity();
+ //glu.gluPerspective(45.0f, (float)width / (float)height, 0.5f, 150.0f);
+
+ //System.out.println("reshape ..");
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ long tick = System.currentTimeMillis();
+
+ if (gAppAlive==0)
+ return;
+
+ this.gl = drawable.getGL().getGL2ES1();
+
+ // Actual tick value is "blurred" a little bit.
+ sTick = (sTick + tick - sStartTick) >> 1;
+
+ // Terminate application after running through the demonstration once.
+ if (sTick >= RUN_LENGTH)
+ {
+ gAppAlive = 0;
+ return;
+ }
+
+ gl.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_COLOR_BUFFER_BIT);
+
+ gl.glMatrixMode(gl.GL_PROJECTION);
+ gl.glLoadIdentity();
+ glu.gluPerspective(45.0f, (float)width / (float)height, 0.5f, 150.0f);
+
+ // Update the camera position and set the lookat.
+ camTrack();
+
+ // Configure environment.
+ configureLightAndMaterial();
+
+ if(blendingEnabled) {
+ gl.glEnable(GL.GL_CULL_FACE);
+ // Draw the reflection by drawing models with negated Z-axis.
+ gl.glPushMatrix();
+ drawModels(-1);
+ gl.glPopMatrix();
+ }
+
+ // Draw the ground plane to the window. (opt. blending)
+ drawGroundPlane();
+
+ if(blendingEnabled) {
+ gl.glDisable(GL.GL_CULL_FACE);
+ }
+
+ // Draw all the models normally.
+ drawModels(1);
+
+ if(blendingEnabled) {
+ // Draw fade quad over whole window (when changing cameras).
+ drawFadeQuad();
+ }
+
+ frames++;
+ tick = System.currentTimeMillis();
+ }
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+ }
+
+ private boolean blendingEnabled = true;
+ private GL2ES1 gl; // temp cache
+ private GLU glu;
+
+ // Total run length is 20 * camera track base unit length (see cams.h).
+ private int RUN_LENGTH = (20 * CamTrack.CAMTRACK_LEN) ;
+ private int RANDOM_UINT_MAX = 65535 ;
+
+ private long sRandomSeed = 0;
+
+void seedRandom(long seed)
+{
+ sRandomSeed = seed;
+}
+
+int randomUInt()
+{
+ sRandomSeed = sRandomSeed * 0x343fd + 0x269ec3;
+ return Math.abs((int) (sRandomSeed >> 16));
+}
+
+private int cComps;
+
+// Definition of one GL object in this demo.
+public class GLSpatial {
+ /* Vertex array and color array are enabled for all objects, so their
+ * pointers must always be valid and non-null. Normal array is not
+ * used by the ground plane, so when its pointer is null then normal
+ * array usage is disabled.
+ *
+ * Vertex array is supposed to use GL.GL_FLOAT datatype and stride 0
+ * (i.e. tightly packed array). Color array is supposed to have 4
+ * components per color with GL.GL_UNSIGNED_BYTE datatype and stride 0.
+ * Normal array is supposed to use GL.GL_FLOAT datatype and stride 0.
+ */
+ protected int vboName, count;
+ protected int vComps, nComps;
+ protected ByteBuffer pBuffer;
+ protected FloatBuffer interlArray;
+ protected GLArrayDataWrapper vArrayData, cArrayData, nArrayData=null;
+
+ public GLSpatial(int vertices, int vertexComponents,
+ boolean useNormalArray) {
+ count = vertices;
+ vComps= vertexComponents;
+ nComps = useNormalArray ? 3 : 0;
+
+ int bStride = BufferUtil.sizeOfGLType(GL.GL_FLOAT) * ( vComps + cComps + nComps );
+ int bSize = count * bStride;
+
+ pBuffer = BufferUtil.newByteBuffer(bSize);
+ interlArray = pBuffer.asFloatBuffer();
+
+ int vOffset = 0;
+ int cOffset = BufferUtil.sizeOfGLType(GL.GL_FLOAT) * (vComps);
+ int nOffset = BufferUtil.sizeOfGLType(GL.GL_FLOAT) * (vComps + cComps);
+
+ int[] tmp = new int[1];
+ gl.glGenBuffers(1, tmp, 0);
+ vboName = tmp[0];
+
+ pBuffer.position(bSize);
+ pBuffer.flip();
+
+ // just for documentation reasons ..
+ interlArray.position(count*(vComps+cComps+nComps));
+ interlArray.flip();
+
+ vArrayData = GLArrayDataWrapper.createFixed(gl, gl.GL_VERTEX_ARRAY, vComps, GL.GL_FLOAT, false,
+ bStride, pBuffer, vboName, vOffset);
+ cArrayData = GLArrayDataWrapper.createFixed(gl, gl.GL_COLOR_ARRAY, cComps, GL.GL_FLOAT, false,
+ bStride, pBuffer, vboName, cOffset);
+ if(useNormalArray) {
+ nArrayData = GLArrayDataWrapper.createFixed(gl, gl.GL_NORMAL_ARRAY, nComps, GL.GL_FLOAT, false,
+ bStride, pBuffer, vboName, nOffset);
+ }
+ }
+
+ private boolean sealed = false;
+
+ void seal()
+ {
+ if(sealed) return;
+ sealed = true;
+
+ if(nComps>0) {
+ gl.glEnableClientState(gl.GL_NORMAL_ARRAY);
+ }
+
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName);
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, pBuffer.limit(), pBuffer, GL.GL_STATIC_DRAW);
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+
+ if(nComps>0) {
+ gl.glDisableClientState(gl.GL_NORMAL_ARRAY);
+ }
+ }
+
+ void draw()
+ {
+ seal();
+ if(nComps>0) {
+ gl.glEnableClientState(gl.GL_NORMAL_ARRAY);
+ }
+
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName);
+
+ gl.glVertexPointer(vArrayData);
+ gl.glColorPointer(cArrayData);
+ if(nComps>0) {
+ gl.glNormalPointer(nArrayData);
+ }
+
+
+ gl.glDrawArrays(GL.GL_TRIANGLES, 0, count);
+
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+
+ if(nComps>0) {
+ gl.glDisableClientState(gl.GL_NORMAL_ARRAY);
+ }
+ }
+}
+
+long sStartTick = 0;
+long sTick = 0;
+
+int sCurrentCamTrack = 0;
+long sCurrentCamTrackStartTick = 0;
+long sNextCamTrackStartTick = 0x7fffffff;
+
+GLSpatial sSuperShapeObjects[] = new GLSpatial[SuperShape.COUNT];
+GLSpatial sGroundPlane;
+
+
+public class VECTOR3 {
+ float x, y, z;
+
+ public VECTOR3() {
+ x=0f; y=0f; z=0f;
+ }
+ public VECTOR3(float x, float y, float z) {
+ this.x=x;
+ this.y=y;
+ this.z=z;
+ }
+}
+
+
+
+static void vector3Sub(VECTOR3 dest, VECTOR3 v1, VECTOR3 v2)
+{
+ dest.x = v1.x - v2.x;
+ dest.y = v1.y - v2.y;
+ dest.z = v1.z - v2.z;
+}
+
+
+static void superShapeMap(VECTOR3 point, float r1, float r2, float t, float p)
+{
+ // sphere-mapping of supershape parameters
+ point.x = (float)(Math.cos(t) * Math.cos(p) / r1 / r2);
+ point.y = (float)(Math.sin(t) * Math.cos(p) / r1 / r2);
+ point.z = (float)(Math.sin(p) / r2);
+}
+
+
+float ssFunc(final float t, final float p[])
+{
+ return ssFunc(t, p, 0);
+}
+
+float ssFunc(final float t, final float p[], int pOff)
+{
+ return (float)(Math.pow(Math.pow(Math.abs(Math.cos(p[0+pOff] * t / 4)) / p[1+pOff], p[4+pOff]) +
+ Math.pow(Math.abs(Math.sin(p[0+pOff] * t / 4)) / p[2+pOff], p[5+pOff]), 1 / p[3+pOff]));
+}
+
+
+// Creates and returns a supershape object.
+// Based on Paul Bourke's POV-Ray implementation.
+// http://astronomy.swin.edu.au/~pbourke/povray/supershape/
+GLSpatial createSuperShape(final float params[])
+{
+ final int resol1 = (int)params[SuperShape.PARAMS - 3];
+ final int resol2 = (int)params[SuperShape.PARAMS - 2];
+ // latitude 0 to pi/2 for no mirrored bottom
+ // (latitudeBegin==0 for -pi/2 to pi/2 originally)
+ final int latitudeBegin = resol2 / 4;
+ final int latitudeEnd = resol2 / 2; // non-inclusive
+ final int longitudeCount = resol1;
+ final int latitudeCount = latitudeEnd - latitudeBegin;
+ final int triangleCount = longitudeCount * latitudeCount * 2;
+ final int vertices = triangleCount * 3;
+ GLSpatial result;
+ float baseColor[] = new float[3];
+ float color[] = new float[3];
+ int a, longitude, latitude;
+ int currentIndex, currentQuad;
+
+ result = new GLSpatial(vertices, 3, true);
+ if (result == null)
+ return null;
+
+ for (a = 0; a < 3; ++a)
+ baseColor[a] = ((randomUInt() % 155) + 100) / 255.f;
+
+ currentQuad = 0;
+ currentIndex = 0;
+
+ // longitude -pi to pi
+ for (longitude = 0; longitude < longitudeCount; ++longitude)
+ {
+
+ // latitude 0 to pi/2
+ for (latitude = latitudeBegin; latitude < latitudeEnd; ++latitude)
+ {
+ float t1 = (float) ( -Math.PI + longitude * 2 * Math.PI / resol1 );
+ float t2 = (float) ( -Math.PI + (longitude + 1) * 2 * Math.PI / resol1 );
+ float p1 = (float) ( -Math.PI / 2 + latitude * 2 * Math.PI / resol2 );
+ float p2 = (float) ( -Math.PI / 2 + (latitude + 1) * 2 * Math.PI / resol2 );
+ float r0, r1, r2, r3;
+
+ r0 = ssFunc(t1, params);
+ r1 = ssFunc(p1, params, 6);
+ r2 = ssFunc(t2, params);
+ r3 = ssFunc(p2, params, 6);
+
+ if (r0 != 0 && r1 != 0 && r2 != 0 && r3 != 0)
+ {
+ VECTOR3 pa=new VECTOR3(), pb=new VECTOR3(), pc=new VECTOR3(), pd=new VECTOR3();
+ VECTOR3 v1=new VECTOR3(), v2=new VECTOR3(), n=new VECTOR3();
+ float ca;
+ int i;
+ //float lenSq, invLenSq;
+
+ superShapeMap(pa, r0, r1, t1, p1);
+ superShapeMap(pb, r2, r1, t2, p1);
+ superShapeMap(pc, r2, r3, t2, p2);
+ superShapeMap(pd, r0, r3, t1, p2);
+
+ // kludge to set lower edge of the object to fixed level
+ if (latitude == latitudeBegin + 1)
+ pa.z = pb.z = 0;
+
+ vector3Sub(v1, pb, pa);
+ vector3Sub(v2, pd, pa);
+
+ // Calculate normal with cross product.
+ /* i j k i j
+ * v1.x v1.y v1.z | v1.x v1.y
+ * v2.x v2.y v2.z | v2.x v2.y
+ */
+
+ n.x = v1.y * v2.z - v1.z * v2.y;
+ n.y = v1.z * v2.x - v1.x * v2.z;
+ n.z = v1.x * v2.y - v1.y * v2.x;
+
+ /* Pre-normalization of the normals is disabled here because
+ * they will be normalized anyway later due to automatic
+ * normalization (GL2ES1.GL_NORMALIZE). It is enabled because the
+ * objects are scaled with glScale.
+ */
+ /*
+ lenSq = n.x * n.x + n.y * n.y + n.z * n.z;
+ invLenSq = (float)(1 / sqrt(lenSq));
+ n.x *= invLenSq;
+ n.y *= invLenSq;
+ n.z *= invLenSq;
+ */
+
+ ca = pa.z + 0.5f;
+
+ for (int j = 0; j < 3; ++j)
+ {
+ color[j] = ca * baseColor[j];
+ if (color[j] > 1.0f) color[j] = 1.0f;
+ }
+
+ result.interlArray.put(currentIndex++, (pa.x));
+ result.interlArray.put(currentIndex++, (pa.y));
+ result.interlArray.put(currentIndex++, (pa.z));
+ result.interlArray.put(currentIndex++, color[0]);
+ result.interlArray.put(currentIndex++, color[1]);
+ result.interlArray.put(currentIndex++, color[2]);
+ if(3<cComps) {
+ result.interlArray.put(currentIndex++, 0f);
+ }
+ if(result.nComps>0) {
+ result.interlArray.put(currentIndex++, (n.x));
+ result.interlArray.put(currentIndex++, (n.y));
+ result.interlArray.put(currentIndex++, (n.z));
+ }
+
+ result.interlArray.put(currentIndex++, (pb.x));
+ result.interlArray.put(currentIndex++, (pb.y));
+ result.interlArray.put(currentIndex++, (pb.z));
+ result.interlArray.put(currentIndex++, color[0]);
+ result.interlArray.put(currentIndex++, color[1]);
+ result.interlArray.put(currentIndex++, color[2]);
+ if(3<cComps) {
+ result.interlArray.put(currentIndex++, 0f);
+ }
+ if(result.nComps>0) {
+ result.interlArray.put(currentIndex++, (n.x));
+ result.interlArray.put(currentIndex++, (n.y));
+ result.interlArray.put(currentIndex++, (n.z));
+ }
+
+ result.interlArray.put(currentIndex++, (pd.x));
+ result.interlArray.put(currentIndex++, (pd.y));
+ result.interlArray.put(currentIndex++, (pd.z));
+ result.interlArray.put(currentIndex++, color[0]);
+ result.interlArray.put(currentIndex++, color[1]);
+ result.interlArray.put(currentIndex++, color[2]);
+ if(3<cComps) {
+ result.interlArray.put(currentIndex++, 0f);
+ }
+ if(result.nComps>0) {
+ result.interlArray.put(currentIndex++, (n.x));
+ result.interlArray.put(currentIndex++, (n.y));
+ result.interlArray.put(currentIndex++, (n.z));
+ }
+
+ result.interlArray.put(currentIndex++, (pb.x));
+ result.interlArray.put(currentIndex++, (pb.y));
+ result.interlArray.put(currentIndex++, (pb.z));
+ result.interlArray.put(currentIndex++, color[0]);
+ result.interlArray.put(currentIndex++, color[1]);
+ result.interlArray.put(currentIndex++, color[2]);
+ if(3<cComps) {
+ result.interlArray.put(currentIndex++, 0f);
+ }
+ if(result.nComps>0) {
+ result.interlArray.put(currentIndex++, (n.x));
+ result.interlArray.put(currentIndex++, (n.y));
+ result.interlArray.put(currentIndex++, (n.z));
+ }
+
+ result.interlArray.put(currentIndex++, (pc.x));
+ result.interlArray.put(currentIndex++, (pc.y));
+ result.interlArray.put(currentIndex++, (pc.z));
+ result.interlArray.put(currentIndex++, color[0]);
+ result.interlArray.put(currentIndex++, color[1]);
+ result.interlArray.put(currentIndex++, color[2]);
+ if(3<cComps) {
+ result.interlArray.put(currentIndex++, 0f);
+ }
+ if(result.nComps>0) {
+ result.interlArray.put(currentIndex++, (n.x));
+ result.interlArray.put(currentIndex++, (n.y));
+ result.interlArray.put(currentIndex++, (n.z));
+ }
+
+ result.interlArray.put(currentIndex++, (pd.x));
+ result.interlArray.put(currentIndex++, (pd.y));
+ result.interlArray.put(currentIndex++, (pd.z));
+ result.interlArray.put(currentIndex++, color[0]);
+ result.interlArray.put(currentIndex++, color[1]);
+ result.interlArray.put(currentIndex++, color[2]);
+ if(3<cComps) {
+ result.interlArray.put(currentIndex++, 0f);
+ }
+ if(result.nComps>0) {
+ result.interlArray.put(currentIndex++, (n.x));
+ result.interlArray.put(currentIndex++, (n.y));
+ result.interlArray.put(currentIndex++, (n.z));
+ }
+
+ } // r0 && r1 && r2 && r3
+ ++currentQuad;
+ } // latitude
+ } // longitude
+
+ result.seal();
+ return result;
+}
+
+
+GLSpatial createGroundPlane()
+{
+ final int scale = 4;
+ final int yBegin = -15, yEnd = 15; // ends are non-inclusive
+ final int xBegin = -15, xEnd = 15;
+ final int triangleCount = (yEnd - yBegin) * (xEnd - xBegin) * 2;
+ final int vertices = triangleCount * 3;
+ GLSpatial result;
+ int x, y;
+ int currentIndex, currentQuad;
+ final int vcomps = 2;
+
+ result = new GLSpatial(vertices, vcomps, false);
+ if (result == null)
+ return null;
+
+ currentQuad = 0;
+ currentIndex = 0;
+
+ for (y = yBegin; y < yEnd; ++y)
+ {
+ for (x = xBegin; x < xEnd; ++x)
+ {
+ float color;
+ int i, a;
+ color = ((float)(randomUInt() % 255))/255.0f;
+
+ // Axis bits for quad triangles:
+ // x: 011100 (0x1c), y: 110001 (0x31) (clockwise)
+ // x: 001110 (0x0e), y: 100011 (0x23) (counter-clockwise)
+ for (a = 0; a < 6; ++a)
+ {
+ final int xm = x + ((0x1c >> a) & 1);
+ final int ym = y + ((0x31 >> a) & 1);
+ final float m = (float)(Math.cos(xm * 2) * Math.sin(ym * 4) * 0.75f);
+ result.interlArray.put(currentIndex++, (xm * scale + m));
+ result.interlArray.put(currentIndex++, (ym * scale + m));
+ if(2<vcomps) {
+ result.interlArray.put(currentIndex++, 0f);
+ }
+ result.interlArray.put(currentIndex++, color);
+ result.interlArray.put(currentIndex++, color);
+ result.interlArray.put(currentIndex++, color);
+ if(3<cComps) {
+ result.interlArray.put(currentIndex++, 0);
+ }
+ }
+ ++currentQuad;
+ }
+ }
+ result.seal();
+ return result;
+}
+
+
+void drawGroundPlane()
+{
+ gl.glDisable(gl.GL_LIGHTING);
+ gl.glDisable(GL.GL_DEPTH_TEST);
+ if(blendingEnabled) {
+ gl.glEnable(GL.GL_BLEND);
+ gl.glBlendFunc(GL.GL_ZERO, GL.GL_SRC_COLOR);
+ }
+
+ sGroundPlane.draw();
+
+ if(blendingEnabled) {
+ gl.glDisable(GL.GL_BLEND);
+ }
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ gl.glEnable(gl.GL_LIGHTING);
+}
+
+void drawFadeQuad()
+{
+ final int beginFade = (int) (sTick - sCurrentCamTrackStartTick);
+ final int endFade = (int) (sNextCamTrackStartTick - sTick);
+ final int minFade = beginFade < endFade ? beginFade : endFade;
+
+ if (minFade < 1024)
+ {
+ final float fadeColor = FixedPoint.toFloat(minFade << 7);
+ gl.glColor4f(fadeColor, fadeColor, fadeColor, 0f);
+
+ gl.glDisable(GL.GL_DEPTH_TEST);
+ gl.glEnable(GL.GL_BLEND);
+ gl.glBlendFunc(GL.GL_ZERO, GL.GL_SRC_COLOR);
+ gl.glDisable(gl.GL_LIGHTING);
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
+ gl.glMatrixMode(gl.GL_PROJECTION);
+ gl.glLoadIdentity();
+
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+ gl.glDisableClientState(gl.GL_COLOR_ARRAY);
+ gl.glDisableClientState(gl.GL_NORMAL_ARRAY);
+ gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
+ gl.glVertexPointer(2, GL.GL_FLOAT, 0, quadVertices);
+ gl.glDrawArrays(GL.GL_TRIANGLES, 0, 6);
+ gl.glEnableClientState(gl.GL_COLOR_ARRAY);
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+
+ gl.glEnable(gl.GL_LIGHTING);
+ gl.glDisable(GL.GL_BLEND);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ }
+}
+
+FloatBuffer quadVertices;
+FloatBuffer light0Position;
+FloatBuffer light0Diffuse;
+FloatBuffer light1Position;
+FloatBuffer light1Diffuse;
+FloatBuffer light2Position;
+FloatBuffer light2Diffuse;
+FloatBuffer materialSpecular;
+
+void configureLightAndMaterial()
+{
+ gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, light0Position);
+ gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, light0Diffuse);
+ gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, light1Position);
+ gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, light1Diffuse);
+ gl.glLightfv(gl.GL_LIGHT2, gl.GL_POSITION, light2Position);
+ gl.glLightfv(gl.GL_LIGHT2, gl.GL_DIFFUSE, light2Diffuse);
+ gl.glMaterialfv(GL.GL_FRONT_AND_BACK, gl.GL_SPECULAR, materialSpecular);
+
+ gl.glMaterialf(GL.GL_FRONT_AND_BACK, gl.GL_SHININESS, 60.0f);
+ gl.glEnable(gl.GL_COLOR_MATERIAL);
+}
+
+
+void drawModels(float zScale)
+{
+ final int translationScale = 9;
+ int x, y;
+
+ seedRandom(9);
+
+ gl.glScalef(1.0f, 1.0f, zScale);
+
+ for (y = -5; y <= 5; ++y)
+ {
+ for (x = -5; x <= 5; ++x)
+ {
+ int curShape = randomUInt() % SuperShape.COUNT;
+ float buildingScale = SuperShape.sParams[curShape][SuperShape.PARAMS - 1];
+
+ gl.glPushMatrix();
+ gl.glTranslatef((float)(x * translationScale),
+ (float)(y * translationScale),
+ 0f);
+ gl.glRotatef((float)(randomUInt() % 360), 0f, 0f, 1f);
+ gl.glScalef(buildingScale, buildingScale, buildingScale);
+
+ sSuperShapeObjects[curShape].draw();
+ gl.glPopMatrix();
+ }
+ }
+
+ for (x = -2; x <= 2; ++x)
+ {
+ final int shipScale100 = translationScale * 500;
+ final int offs100 = x * shipScale100 + (int)(sTick % shipScale100);
+ float offs = offs100 * 0.01f;
+ gl.glPushMatrix();
+ gl.glTranslatef(offs, -4.0f, 2.0f);
+ sSuperShapeObjects[SuperShape.COUNT - 1].draw();
+ gl.glPopMatrix();
+ gl.glPushMatrix();
+ gl.glTranslatef(-4.0f, offs, 4.0f);
+ gl.glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
+ sSuperShapeObjects[SuperShape.COUNT - 1].draw();
+ gl.glPopMatrix();
+ }
+}
+
+
+void camTrack()
+{
+ float lerp[]= new float[5];
+ float eX, eY, eZ, cX, cY, cZ;
+ float trackPos;
+ CamTrack cam;
+ long currentCamTick;
+ int a;
+
+ if (sNextCamTrackStartTick <= sTick)
+ {
+ ++sCurrentCamTrack;
+ sCurrentCamTrackStartTick = sNextCamTrackStartTick;
+ }
+ sNextCamTrackStartTick = sCurrentCamTrackStartTick +
+ CamTrack.sCamTracks[sCurrentCamTrack].len * CamTrack.CAMTRACK_LEN;
+
+ cam = CamTrack.sCamTracks[sCurrentCamTrack];
+ currentCamTick = sTick - sCurrentCamTrackStartTick;
+ trackPos = (float)currentCamTick / (CamTrack.CAMTRACK_LEN * cam.len);
+
+ for (a = 0; a < 5; ++a)
+ lerp[a] = (cam.src[a] + cam.dest[a] * trackPos) * 0.01f;
+
+ if (cam.dist>0)
+ {
+ float dist = cam.dist * 0.1f;
+ cX = lerp[0];
+ cY = lerp[1];
+ cZ = lerp[2];
+ eX = cX - (float)Math.cos(lerp[3]) * dist;
+ eY = cY - (float)Math.sin(lerp[3]) * dist;
+ eZ = cZ - lerp[4];
+ }
+ else
+ {
+ eX = lerp[0];
+ eY = lerp[1];
+ eZ = lerp[2];
+ cX = eX + (float)Math.cos(lerp[3]);
+ cY = eY + (float)Math.sin(lerp[3]);
+ cZ = eZ + lerp[4];
+ }
+ glu.gluLookAt(eX, eY, eZ, cX, cY, cZ, 0, 0, 1);
+}
+
+private int gAppAlive = 0;
+private int width, height, x, y, frames;
+}
+
diff --git a/src/demos/es1/angeles/CamTrack.java b/src/demos/es1/angeles/CamTrack.java
new file mode 100755
index 0000000..df1678c
--- /dev/null
+++ b/src/demos/es1/angeles/CamTrack.java
@@ -0,0 +1,71 @@
+/* San Angeles Observation OpenGL ES version example
+ * Copyright 2004-2005 Jetro Lauha
+ * All rights reserved.
+ * Web: http://iki.fi/jetro/
+ *
+ * This source is free software; you can redistribute it and/or
+ * modify it under the terms of EITHER:
+ * (1) The GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version. The text of the GNU Lesser
+ * General Public License is included with this source in the
+ * file LICENSE-LGPL.txt.
+ * (2) The BSD-style license that is included with this source in
+ * the file LICENSE-BSD.txt.
+ *
+ * This source is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
+ * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
+ *
+ * $Id$
+ * $Revision$
+ */
+
+package demos.es1.angeles;
+
+// Camera track definition for one camera trucking shot.
+public class CamTrack
+{
+ /* Length in milliseconds of one camera track base unit.
+ * The value originates from the music synchronization.
+ */
+ static final int CAMTRACK_LEN = 5442;
+
+ /* Five parameters of src[5] and dest[5]:
+ * eyeX, eyeY, eyeZ, viewAngle, viewHeightOffs
+ */
+ short src[], dest[];
+ int dist; // if >0, cam rotates around eye xy on dist * 0.1
+ int len; // length multiplier
+
+ public CamTrack() {
+ src = new short[5];
+ dest = new short[5];
+ }
+ public CamTrack(short s[], short d[], int dx, int l) {
+ src=s;
+ dest=d;
+ dist=dx;
+ len=l;
+ }
+
+static CamTrack sCamTracks[] =
+ { new CamTrack( new short[]{ 4500, 2700, 100, 70, -30 }, new short[]{ 50, 50, -90, -100, 0 }, 20, 1 ),
+ new CamTrack( new short[]{ -1448, 4294, 25, 363, 0 }, new short[]{ -136, 202, 125, -98, 100 }, 0, 1 ),
+ new CamTrack( new short[]{ 1437, 4930, 200, -275, -20 }, new short[]{ 1684, 0, 0, 9, 0 }, 0, 1 ),
+ new CamTrack( new short[]{ 1800, 3609, 200, 0, 675 }, new short[]{ 0, 0, 0, 300, 0 }, 0, 1 ),
+ new CamTrack( new short[]{ 923, 996, 50, 2336, -80 }, new short[]{ 0, -20, -50, 0, 170 }, 0, 1 ),
+ new CamTrack( new short[]{ -1663, -43, 600, 2170, 0 }, new short[]{ 20, 0, -600, 0, 100 }, 0, 1 ),
+ new CamTrack( new short[]{ 1049, -1420, 175, 2111, -17 }, new short[]{ 0, 0, 0, -334, 0 }, 0, 2 ),
+ new CamTrack( new short[]{ 0, 0, 50, 300, 25 }, new short[]{ 0, 0, 0, 300, 0 }, 70, 2 ),
+ new CamTrack( new short[]{ -473, -953, 3500, -353, -350 }, new short[]{ 0, 0, -2800, 0, 0 }, 0, 2 ),
+ new CamTrack( new short[]{ 191, 1938, 35, 1139, -17 }, new short[]{ 1205, -2909, 0, 0, 0 }, 0, 2 ),
+ new CamTrack( new short[]{ -1449, -2700, 150, 0, 0 }, new short[]{ 0, 2000, 0, 0, 0 }, 0, 2 ),
+ new CamTrack( new short[]{ 5273, 4992, 650, 373, -50 }, new short[]{ -4598, -3072, 0, 0, 0 }, 0, 2 ),
+ new CamTrack( new short[]{ 3223, -3282, 1075, -393, -25 }, new short[]{ 1649, -1649, 0, 0, 0 }, 0, 2 ) };
+
+static final int CAMTRACK_COUNT = 13;
+
+}
+
diff --git a/src/demos/es1/angeles/Main.java b/src/demos/es1/angeles/Main.java
new file mode 100755
index 0000000..3b8400b
--- /dev/null
+++ b/src/demos/es1/angeles/Main.java
@@ -0,0 +1,131 @@
+package demos.es1.angeles;
+
+import java.nio.*;
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+import com.sun.javafx.newt.*;
+import com.sun.javafx.newt.opengl.*;
+
+public class Main implements WindowListener, MouseListener {
+
+ public boolean quit = false;
+ public GLWindow window = null;
+
+ public void windowResized(WindowEvent e) { }
+ public void windowMoved(WindowEvent e) { }
+ public void windowGainedFocus(WindowEvent e) { }
+ public void windowLostFocus(WindowEvent e) { }
+ public void windowDestroyNotify(WindowEvent e) {
+ quit = true;
+ }
+
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() > 1) {
+ quit=true;
+ }
+ }
+ public void mouseEntered(MouseEvent e) {
+ }
+ public void mouseExited(MouseEvent e) {
+ }
+ public void mousePressed(MouseEvent e) {
+ }
+ public void mouseReleased(MouseEvent e) {
+ }
+ public void mouseMoved(MouseEvent e) {
+ }
+ public void mouseDragged(MouseEvent e) {
+ }
+ public void mouseWheelMoved(MouseEvent e) {
+ }
+
+ private void run(int type) {
+ int width = 800;
+ int height = 480;
+ System.out.println("angeles.Main.run()");
+ //GLProfile.setProfileGL2ES1();
+ try {
+ // Hook this into EGL
+ GLCapabilities caps = new GLCapabilities(null);
+ // For emulation library, use 16 bpp
+ caps.setRedBits(5);
+ caps.setGreenBits(6);
+ caps.setBlueBits(5);
+ /*
+ caps.setRedBits(8);
+ caps.setGreenBits(8);
+ caps.setBlueBits(8);
+ caps.setAlphaBits(8);
+ */
+ caps.setDepthBits(16);
+
+ Window nWindow = null;
+ if(0!=(type&USE_AWT)) {
+ Display nDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null); // local display
+ Screen nScreen = NewtFactory.createScreen(NativeWindowFactory.TYPE_AWT, nDisplay, 0); // screen 0
+ nWindow = NewtFactory.createWindow(NativeWindowFactory.TYPE_AWT, nScreen, caps);
+ }
+ window = GLWindow.create(nWindow, caps);
+
+ window.addWindowListener(this);
+ window.addMouseListener(this);
+
+ window.enablePerfLog(true);
+ window.setSize(width, height);
+ window.setFullscreen(true);
+ window.setVisible(true);
+
+ GL gl = window.getGL();
+ if(gl.isGLES1() && 0==(type&USE_ANGELESF)) {
+ System.out.println("Using: AngelesES1 .. ");
+ AngelesES1 angel = new AngelesES1( 0 == (type&USE_NOBLEND) );
+ window.addGLEventListener(angel);
+ } else {
+ if(0!=(type&USE_INTERLEAVE)) {
+ System.out.println("Using: AngelesGLil .. ");
+ AngelesGLil angel = new AngelesGLil( 0 == (type&USE_NOBLEND) );
+ window.addGLEventListener(angel);
+ } else {
+ System.out.println("Using: AngelesGL .. ");
+ AngelesGL angel = new AngelesGL( 0 == (type&USE_NOBLEND) );
+ window.addGLEventListener(angel);
+ }
+ }
+
+ while (!quit && window.getDuration() < 215000) {
+ window.display();
+ }
+
+ // Shut things down cooperatively
+ window.destroy();
+ window.getFactory().shutdown();
+ System.out.println("angeles.Main shut down cleanly.");
+ } catch (GLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static int USE_NEWT = 0;
+ public static int USE_AWT = 1 << 0;
+ public static int USE_ANGELESF = 1 << 1;
+ public static int USE_NOBLEND = 1 << 2;
+ public static int USE_INTERLEAVE= 1 << 3;
+
+ public static void main(String[] args) {
+ int type = USE_NEWT ;
+ for(int i=args.length-1; i>=0; i--) {
+ if(args[i].equals("-awt")) {
+ type |= USE_AWT;
+ } else if(args[i].equals("-angelesf")) {
+ type |= USE_ANGELESF;
+ } else if(args[i].equals("-noblend")) {
+ type |= USE_NOBLEND;
+ } else if(args[i].equals("-interleave")) {
+ type |= USE_INTERLEAVE;
+ }
+ }
+ new Main().run(type);
+ System.exit(0);
+ }
+
+}
diff --git a/src/demos/es1/angeles/SuperShape.java b/src/demos/es1/angeles/SuperShape.java
new file mode 100755
index 0000000..5f419d6
--- /dev/null
+++ b/src/demos/es1/angeles/SuperShape.java
@@ -0,0 +1,57 @@
+/* San Angeles Observation OpenGL ES version example
+ * Copyright 2004-2005 Jetro Lauha
+ * All rights reserved.
+ * Web: http://iki.fi/jetro/
+ *
+ * This source is free software; you can redistribute it and/or
+ * modify it under the terms of EITHER:
+ * (1) The GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version. The text of the GNU Lesser
+ * General Public License is included with this source in the
+ * file LICENSE-LGPL.txt.
+ * (2) The BSD-style license that is included with this source in
+ * the file LICENSE-BSD.txt.
+ *
+ * This source is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
+ * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
+ *
+ * $Id$
+ * $Revision$
+ */
+
+package demos.es1.angeles;
+
+public class SuperShape {
+
+public static final int PARAMS = 15 ;
+
+public static final float sParams[][/*SUPERSHAPE_PARAMS*/] =
+{
+ // m a b n1 n2 n3 m a b n1 n2 n3 res1 res2 scale (org.res1,res2)
+ new float[]{ 10, 1, 2, 90, 1, -45, 8, 1, 1, -1, 1, -0.4f, 20, 30, 2 }, // 40, 60
+ new float[]{ 10, 1, 2, 90, 1, -45, 4, 1, 1, 10, 1, -0.4f, 20, 20, 4 }, // 40, 40
+ new float[]{ 10, 1, 2, 60, 1, -10, 4, 1, 1, -1, -2, -0.4f, 41, 41, 1 }, // 82, 82
+ new float[]{ 6, 1, 1, 60, 1, -70, 8, 1, 1, 0.4f, 3, 0.25f, 20, 20, 1 }, // 40, 40
+ new float[]{ 4, 1, 1, 30, 1, 20, 12, 1, 1, 0.4f, 3, 0.25f, 10, 30, 1 }, // 20, 60
+ new float[]{ 8, 1, 1, 30, 1, -4, 8, 2, 1, -1, 5, 0.5f, 25, 26, 1 }, // 60, 60
+ new float[]{ 13, 1, 1, 30, 1, -4, 13, 1, 1, 1, 5, 1, 30, 30, 6 }, // 60, 60
+ new float[]{ 10, 1, 1.1f, -0.5f, 0.1f, 70, 60, 1, 1, -90, 0, -0.25f, 20, 60, 8 }, // 60, 180
+ new float[]{ 7, 1, 1, 20, -0.3f, -3.5f, 6, 1, 1, -1, 4.5f, 0.5f, 10, 20, 4 }, // 60, 80
+ new float[]{ 4, 1, 1, 10, 10, 10, 4, 1, 1, 10, 10, 10, 10, 20, 1 }, // 20, 40
+ new float[]{ 4, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 10, 10, 2 }, // 10, 10
+ new float[]{ 1, 1, 1, 38, -0.25f, 19, 4, 1, 1, 10, 10, 10, 10, 15, 2 }, // 20, 40
+ new float[]{ 2, 1, 1, 0.7f, 0.3f, 0.2f, 3, 1, 1, 100, 100, 100, 10, 25, 2 }, // 20, 50
+ new float[]{ 6, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 30, 30, 2 }, // 60, 60
+ new float[]{ 3, 1, 1, 1, 1, 1, 6, 1, 1, 2, 1, 1, 10, 20, 2 }, // 20, 40
+ new float[]{ 6, 1, 1, 6, 5.5f, 100, 6, 1, 1, 25, 10, 10, 30, 20, 2 }, // 60, 40
+ new float[]{ 3, 1, 1, 0.5f, 1.7f, 1.7f, 2, 1, 1, 10, 10, 10, 20, 20, 2 }, // 40, 40
+ new float[]{ 5, 1, 1, 0.1f, 1.7f, 1.7f, 1, 1, 1, 0.3f, 0.5f, 0.5f, 20, 20, 4 }, // 40, 40
+ new float[]{ 2, 1, 1, 6, 5.5f, 100, 6, 1, 1, 4, 10, 10, 10, 22, 1 }, // 40, 40
+ new float[]{ 6, 1, 1, -1, 70, 0.1f, 9, 1, 0.5f, -98, 0.05f, -45, 20, 30, 4 }, // 60, 91
+ new float[]{ 6, 1, 1, -1, 90, -0.1f, 7, 1, 1, 90, 1.3f, 34, 13, 16, 1 }, // 32, 60
+};
+ public static final int COUNT = 21;
+}
diff --git a/src/demos/es1/cube/Cube.java b/src/demos/es1/cube/Cube.java
new file mode 100644
index 0000000..8917697
--- /dev/null
+++ b/src/demos/es1/cube/Cube.java
@@ -0,0 +1,347 @@
+/*
+ *
+ * Copyright (c) 2007, Sun Microsystems, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Sun Microsystems nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package demos.es1.cube;
+
+import java.nio.*;
+import javax.media.opengl.*;
+import javax.media.opengl.glu.*;
+import javax.media.nativewindow.*;
+
+import com.sun.opengl.util.*;
+import com.sun.opengl.util.glsl.fixedfunc.*;
+
+import com.sun.javafx.newt.*;
+import com.sun.javafx.newt.opengl.*;
+
+public class Cube implements GLEventListener {
+ boolean quit = false;
+
+ public Cube () {
+ this(false, false);
+ }
+
+ public Cube (boolean useTexCoords, boolean innerCube) {
+ this.innerCube = innerCube;
+
+ // Initialize data Buffers
+ this.cubeVertices = BufferUtil.newShortBuffer(s_cubeVertices.length);
+ cubeVertices.put(s_cubeVertices);
+ cubeVertices.flip();
+
+ this.cubeColors = BufferUtil.newFloatBuffer(s_cubeColors.length);
+ cubeColors.put(s_cubeColors);
+ cubeColors.flip();
+
+ this.cubeNormals = BufferUtil.newByteBuffer(s_cubeNormals.length);
+ cubeNormals.put(s_cubeNormals);
+ cubeNormals.flip();
+
+ this.cubeIndices = BufferUtil.newByteBuffer(s_cubeIndices.length);
+ cubeIndices.put(s_cubeIndices);
+ cubeIndices.flip();
+
+ if (useTexCoords) {
+ this.cubeTexCoords = BufferUtil.newShortBuffer(s_cubeTexCoords.length);
+ cubeTexCoords.put(s_cubeTexCoords);
+ cubeTexCoords.flip();
+ }
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ GL2ES1 gl = FixedFuncUtil.getFixedFuncImpl(drawable.getGL());
+
+ glu = GLU.createGLU();
+
+ gl.glGenBuffers(4, vboNames, 0);
+
+ if(!innerCube) {
+ System.err.println("Entering initialization");
+ System.err.println("GL Profile: "+gl.getGLProfile());
+ System.err.println("GL:" + gl);
+ System.err.println("GL_VERSION=" + gl.glGetString(gl.GL_VERSION));
+ System.err.println("GL_EXTENSIONS:");
+ System.err.println(" " + gl.glGetString(gl.GL_EXTENSIONS));
+ System.err.println("GLF:" + gl);
+ }
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ float aspect = (height != 0) ? ((float)width / (float)height) : 1.0f;
+
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+
+ gl.glViewport(0, 0, width, height);
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
+ // JAU gl.glScissor(0, 0, width, height);
+ if(innerCube) {
+ // Clear background to white
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 0.4f);
+ } else {
+ // Clear background to blue
+ gl.glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
+ }
+
+ if(!innerCube) {
+ gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, light_position, 0);
+ gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, light_ambient, 0);
+ gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, light_diffuse, 0);
+ gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, zero_vec4, 0);
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, material_spec, 0);
+
+ gl.glEnable(gl.GL_LIGHTING);
+ gl.glEnable(gl.GL_LIGHT0);
+ gl.glEnable(gl.GL_COLOR_MATERIAL);
+ } else {
+ gl.glDisable(gl.GL_LIGHTING);
+ gl.glDisable(gl.GL_LIGHT0);
+ }
+ gl.glEnable(gl.GL_CULL_FACE);
+ gl.glEnable(gl.GL_NORMALIZE);
+
+ gl.glShadeModel(gl.GL_SMOOTH);
+ gl.glDisable(GL.GL_DITHER);
+
+ gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboNames[0]);
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, cubeVertices.limit() * BufferUtil.SIZEOF_SHORT, cubeVertices, GL.GL_STATIC_DRAW);
+ gl.glVertexPointer(3, gl.GL_SHORT, 0, 0);
+
+ gl.glEnableClientState(gl.GL_NORMAL_ARRAY);
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboNames[1]);
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, cubeNormals.limit() * BufferUtil.SIZEOF_BYTE, cubeNormals, GL.GL_STATIC_DRAW);
+ gl.glNormalPointer(gl.GL_BYTE, 0, 0);
+
+ gl.glEnableClientState(gl.GL_COLOR_ARRAY);
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboNames[2]);
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, cubeColors.limit() * BufferUtil.SIZEOF_FLOAT, cubeColors, GL.GL_STATIC_DRAW);
+ gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
+
+ if (cubeTexCoords != null) {
+ gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY);
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboNames[3]);
+ gl.glBufferData(GL.GL_ARRAY_BUFFER, cubeTexCoords.limit() * BufferUtil.SIZEOF_SHORT, cubeTexCoords, GL.GL_STATIC_DRAW);
+ gl.glTexCoordPointer(2, gl.GL_SHORT, 0, 0);
+ /* issues an GL_INVALID_ENUM
+ gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_INCR);
+ } */
+ } else {
+ gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY);
+ }
+ gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
+
+ gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_FASTEST);
+
+ gl.glMatrixMode(gl.GL_PROJECTION);
+ gl.glLoadIdentity();
+
+ if(!innerCube) {
+ glu.gluPerspective(90.0f, aspect, 1.0f, 100.0f);
+ } else {
+ gl.glOrthof(-20.0f, 20.0f, -20.0f, 20.0f, 1.0f, 40.0f);
+ }
+ // weird effect ..: gl.glCullFace(gl.GL_FRONT);
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ quit=true;
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+
+ gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
+ gl.glTranslatef(0.f, 0.f, -30.f);
+ gl.glRotatef((float)(time * 29.77f), 1.0f, 2.0f, 0.0f);
+ gl.glRotatef((float)(time * 22.311f), -0.1f, 0.0f, -5.0f);
+
+ gl.glDrawElements(gl.GL_TRIANGLES, 6 * 6, gl.GL_UNSIGNED_BYTE, cubeIndices);
+
+ time += 0.01f;
+ }
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+ }
+
+ static final float[] light_position = { -50.f, 50.f, 50.f, 0.f };
+ static final float[] light_ambient = { 0.125f, 0.125f, 0.125f, 1.f };
+ static final float[] light_diffuse = { 1.0f, 1.0f, 1.0f, 1.f };
+ static final float[] material_spec = { 1.0f, 1.0f, 1.0f, 0.f };
+ static final float[] zero_vec4 = { 0.0f, 0.0f, 0.0f, 0.f };
+
+ int[] vboNames = new int[4];
+ boolean innerCube;
+ boolean initialized = false;
+ float time = 0.0f;
+ ShortBuffer cubeVertices;
+ ShortBuffer cubeTexCoords;
+ FloatBuffer cubeColors;
+ ByteBuffer cubeNormals;
+ ByteBuffer cubeIndices;
+ private GLU glu;
+
+ private static final short[] s_cubeVertices =
+ {
+ -10, 10, 10, 10, -10, 10, 10, 10, 10, -10, -10, 10,
+
+ -10, 10, -10, 10, -10, -10, 10, 10, -10, -10, -10, -10,
+
+ -10, -10, 10, 10, -10, -10, 10, -10, 10, -10, -10, -10,
+
+ -10, 10, 10, 10, 10, -10, 10, 10, 10, -10, 10, -10,
+
+ 10, -10, 10, 10, 10, -10, 10, 10, 10, 10, -10, -10,
+
+ -10, -10, 10, -10, 10, -10, -10, 10, 10, -10, -10, -10
+ };
+ private static final short[] s_cubeTexCoords =
+ {
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+ };
+
+ private static final float[] s_cubeColors =
+ {
+ 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f,
+ 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f,
+
+ 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f,
+ 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f,
+
+ 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f,
+ 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f,
+
+ 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f,
+ 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f,
+
+ 255f/255f, 110f/255f, 10f/255f, 255f/255f, 255f/255f, 110f/255f, 10f/255f, 255f/255f,
+ 255f/255f, 110f/255f, 10f/255f, 255f/255f, 255f/255f, 110f/255f, 10f/255f, 255f/255f,
+
+ 255f/255f, 70f/255f, 60f/255f, 255f/255f, 255f/255f, 70f/255f, 60f/255f, 255f/255f,
+ 255f/255f, 70f/255f, 60f/255f, 255f/255f, 255f/255f, 70f/255f, 60f/255f, 255
+ };
+ private static final byte[] s_cubeIndices =
+ {
+ 0, 3, 1, 2, 0, 1, /* front */
+ 6, 5, 4, 5, 7, 4, /* back */
+ 8, 11, 9, 10, 8, 9, /* top */
+ 15, 12, 13, 12, 14, 13, /* bottom */
+ 16, 19, 17, 18, 16, 17, /* right */
+ 23, 20, 21, 20, 22, 21 /* left */
+ };
+ private static final byte[] s_cubeNormals =
+ {
+ 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127,
+
+ 0, 0, -128, 0, 0, -128, 0, 0, -128, 0, 0, -128,
+
+ 0, -128, 0, 0, -128, 0, 0, -128, 0, 0, -128, 0,
+
+ 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0,
+
+ 127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0,
+
+ -128, 0, 0, -128, 0, 0, -128, 0, 0, -128, 0, 0
+ };
+
+ private void run(int type) {
+ int width = 800;
+ int height = 480;
+ System.err.println("Cube.run()");
+ try {
+ GLCapabilities caps = new GLCapabilities(null);
+ // For emulation library, use 16 bpp
+ caps.setRedBits(5);
+ caps.setGreenBits(6);
+ caps.setBlueBits(5);
+ caps.setDepthBits(16);
+
+ Window nWindow = null;
+ if(0!=(type&USE_AWT)) {
+ Display nDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null); // local display
+ Screen nScreen = NewtFactory.createScreen(NativeWindowFactory.TYPE_AWT, nDisplay, 0); // screen 0
+ nWindow = NewtFactory.createWindow(NativeWindowFactory.TYPE_AWT, nScreen, caps);
+ }
+
+ GLWindow window = GLWindow.create(nWindow, caps);
+
+ window.addGLEventListener(this);
+
+ window.enablePerfLog(true);
+ // Size OpenGL to Video Surface
+ window.setSize(width, height);
+ window.setFullscreen(true);
+ window.setVisible(true);
+
+ while (!quit && window.getDuration() < 31000) {
+ window.display();
+ }
+
+ // Shut things down cooperatively
+ window.destroy();
+ window.getFactory().shutdown();
+ System.out.println("Cube shut down cleanly.");
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ public static int USE_NEWT = 0;
+ public static int USE_AWT = 1 << 0;
+
+ public static void main(String[] args) {
+ int type = USE_NEWT ;
+ for(int i=args.length-1; i>=0; i--) {
+ if(args[i].equals("-awt")) {
+ type |= USE_AWT;
+ }
+ }
+ new Cube().run(type);
+ System.exit(0);
+ }
+}
+
diff --git a/src/demos/es1/cube/CubeImmModeSink.java b/src/demos/es1/cube/CubeImmModeSink.java
new file mode 100644
index 0000000..b072535
--- /dev/null
+++ b/src/demos/es1/cube/CubeImmModeSink.java
@@ -0,0 +1,436 @@
+/*
+ *
+ * Copyright (c) 2007, Sun Microsystems, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Sun Microsystems nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package demos.es1.cube;
+
+import javax.media.opengl.*;
+import javax.media.opengl.glu.*;
+import javax.media.nativewindow.*;
+import com.sun.opengl.util.*;
+import com.sun.opengl.util.glsl.fixedfunc.*;
+import java.nio.*;
+
+import com.sun.javafx.newt.*;
+import com.sun.javafx.newt.opengl.*;
+
+public class CubeImmModeSink implements GLEventListener {
+ boolean quit = false;
+
+ public CubeImmModeSink () {
+ this(false, false);
+ }
+
+ private static boolean VBO_CACHE = true;
+
+ ByteBuffer cubeIndices=null;
+ ImmModeSink vboCubeF = null;
+ public void drawCube(GL2ES1 gl, float extent) {
+ if(cubeIndices==null) {
+ cubeIndices = BufferUtil.newByteBuffer(s_cubeIndices);
+ }
+
+ if(vboCubeF==null) {
+ ImmModeSink vbo = ImmModeSink.createFixed(gl, GL.GL_STATIC_DRAW, 36,
+ 3, GL.GL_SHORT, // vertex
+ 4, GL.GL_FLOAT, // color
+ 3, GL.GL_BYTE, // normal
+ 0, GL.GL_FLOAT); // texture
+
+ vbo.glBegin(GL.GL_TRIANGLES);
+
+ vbo.glVertexv(BufferUtil.newShortBuffer(s_cubeVertices));
+ vbo.glColorv(BufferUtil.newFloatBuffer(s_cubeColors));
+ vbo.glNormalv(BufferUtil.newByteBuffer(s_cubeNormals));
+
+ if(VBO_CACHE) {
+ vbo.glEnd(gl, false);
+ } else {
+ vbo.glEnd(gl, cubeIndices);
+ }
+ System.err.println("VBO Cube");
+ System.err.println(vbo);
+ if(VBO_CACHE) {
+ vboCubeF = vbo;
+ }
+ }
+ if(null!=vboCubeF) {
+ vboCubeF.draw(gl, cubeIndices, true);
+ }
+ }
+
+ private GLUquadric sphere=null;
+ private ImmModeSink vboSphere=null;
+ public void drawSphere(GL2ES1 gl, float radius, int slices, int stacks) {
+ if(sphere==null) {
+ sphere = glu.gluNewQuadric();
+ sphere.enableImmModeSink(true);
+ sphere.setImmMode((VBO_CACHE)?false:true);
+ }
+ ImmModeSink vbo = vboSphere;
+ if (vbo == null) {
+ glu.gluSphere(sphere, radius, 8, 8);
+ if(VBO_CACHE) {
+ vboSphere = sphere.replaceImmModeSink();
+ vbo = vboSphere;
+ }
+ System.err.println("VBO Sphere");
+ System.err.println(vbo);
+ }
+
+ if(VBO_CACHE && null!=vbo) {
+ vbo.draw(gl, true);
+ }
+ }
+
+
+ private GLUquadric cylinder=null;
+ private ImmModeSink vboCylinder=null;
+ public void drawCylinder(GL2ES1 gl, float radius, float halfHeight, int upAxis) {
+ if(cylinder==null) {
+ cylinder = glu.gluNewQuadric();
+ cylinder.enableImmModeSink(true);
+ cylinder.setImmMode((VBO_CACHE)?false:true);
+ }
+
+ gl.glPushMatrix();
+ switch (upAxis) {
+ case 0:
+ gl.glRotatef(-90f, 0.0f, 1.0f, 0.0f);
+ gl.glTranslatef(0.0f, 0.0f, -halfHeight);
+ break;
+ case 1:
+ gl.glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
+ gl.glTranslatef(0.0f, 0.0f, -halfHeight);
+ break;
+ case 2:
+ gl.glTranslatef(0.0f, 0.0f, -halfHeight);
+ break;
+ default: {
+ assert (false);
+ }
+ }
+
+ ImmModeSink vbo = vboCylinder;
+ if (vbo == null) {
+ glu.gluQuadricDrawStyle(cylinder, glu.GLU_FILL);
+ glu.gluQuadricNormals(cylinder, glu.GLU_SMOOTH);
+ glu.gluCylinder(cylinder, radius, radius, 2f * halfHeight, 15, 10);
+ if(VBO_CACHE) {
+ vboCylinder = cylinder.replaceImmModeSink();
+ vbo = vboCylinder;
+ }
+ System.err.println("VBO Cylinder");
+ System.err.println(vbo);
+ }
+
+ if(VBO_CACHE && null!=vbo) {
+ vbo.draw(gl, true);
+ }
+
+ gl.glPopMatrix();
+ }
+
+
+
+ public CubeImmModeSink (boolean useTexCoords, boolean innerCube) {
+ this.innerCube = innerCube;
+ this.useTexCoords = useTexCoords;
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ GL2ES1 gl = FixedFuncUtil.getFixedFuncImpl(drawable.getGL());
+
+ glu = GLU.createGLU();
+
+ if(!innerCube) {
+ System.err.println("Entering initialization");
+ System.err.println("GL Profile: "+gl.getGLProfile());
+ System.err.println("GL:" + gl);
+ System.err.println("GL_VERSION=" + gl.glGetString(gl.GL_VERSION));
+ System.err.println("GL_EXTENSIONS:");
+ System.err.println(" " + gl.glGetString(gl.GL_EXTENSIONS));
+ System.err.println("GLF:" + gl);
+ }
+
+ gl.glGetError(); // flush error ..
+
+ // Debug ..
+ // DebugGL2 gl2dbg = new DebugGL2(gl.getGL2());
+ // gl.getContext().setGL(gl2dbg);
+
+ // Trace ..
+ // TraceGL2 gl2trace = new TraceGL2(gl.getGL2(), System.err);
+ // gl.getContext().setGL(gl2trace);
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ float aspect = (height != 0) ? ((float)width / (float)height) : 1.0f;
+
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+
+ gl.glViewport(0, 0, width, height);
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
+ gl.glScissor(0, 0, width, height);
+ if(innerCube) {
+ // Clear background to white
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 0.6f);
+ } else {
+ // Clear background to blue
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ }
+
+ gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, light_position, 0);
+ gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, light_ambient, 0);
+ gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, light_diffuse, 0);
+ gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, zero_vec4, 0);
+ gl.glMaterialfv(GL.GL_FRONT_AND_BACK, gl.GL_SPECULAR, material_spec, 0);
+ gl.glEnable(gl.GL_NORMALIZE);
+
+ gl.glEnable(gl.GL_LIGHTING);
+ gl.glEnable(gl.GL_LIGHT0);
+ gl.glEnable(gl.GL_COLOR_MATERIAL);
+ gl.glEnable(GL.GL_CULL_FACE);
+
+ gl.glShadeModel(gl.GL_SMOOTH);
+ gl.glDisable(gl.GL_DITHER);
+
+ gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_FASTEST);
+
+ gl.glMatrixMode(gl.GL_PROJECTION);
+ gl.glLoadIdentity();
+
+ if(!innerCube) {
+ glu.gluPerspective(90.0f, aspect, 1.0f, 100.0f);
+ } else {
+ gl.glOrthof(-20.0f, 20.0f, -20.0f, 20.0f, 1.0f, 40.0f);
+ }
+ // weird effect ..: gl.glCullFace(gl.GL_FRONT);
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ quit=true;
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+
+ gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
+ gl.glTranslatef(0.f, 0.0f, -30.f);
+ gl.glRotatef((float)(time * 29.77f), 1.0f, 2.0f, 0.0f);
+ gl.glRotatef((float)(time * 22.311f), -0.1f, 0.0f, -5.0f);
+
+ gl.glColor4f(0f, 0f, 0f, 1f);
+
+ if(true) {
+ //gl.glColor4f(1f, 0f, 0f, 1f); // RED inside the color4f's
+ drawCube(gl, 10.0f);
+ }
+
+ if(true) {
+ gl.glDisable(gl.GL_LIGHTING);
+ gl.glColor4f(0f, 1f, 0f, 1f);
+ gl.glPushMatrix();
+ gl.glTranslatef(15.0f, 0.0f, 0.0f);
+ drawSphere(gl, 5.0f, 10, 10);
+ gl.glPopMatrix();
+ gl.glEnable(gl.GL_LIGHTING);
+ }
+
+ if(true) {
+ gl.glColor4f(0f, 0f, 1f, 1f);
+ gl.glPushMatrix();
+ gl.glMultMatrixf(identity4x4f, 0);
+ drawCylinder(gl, 4.0f, 10.0f, 1);
+ gl.glPopMatrix();
+ }
+
+ frameNum++;
+ time += 0.01f;
+ }
+ int frameNum=0;
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+ }
+
+ static final float[] light_position = { -50.f, 50.f, 50.f, 0.f };
+ static final float[] light_ambient = { 0.125f, 0.125f, 0.125f, 1.f };
+ static final float[] light_diffuse = { 1.0f, 1.0f, 1.0f, 1.f };
+ static final float[] material_spec = { 1.0f, 1.0f, 1.0f, 0.f };
+ static final float[] zero_vec4 = { 0.0f, 0.0f, 0.0f, 0.f };
+ static final float[] identity4x4f = { 1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f };
+ private static final short[] s_cubeVertices =
+ {
+ -10, 10, 10, 10, -10, 10, 10, 10, 10, -10, -10, 10,
+
+ -10, 10, -10, 10, -10, -10, 10, 10, -10, -10, -10, -10,
+
+ -10, -10, 10, 10, -10, -10, 10, -10, 10, -10, -10, -10,
+
+ -10, 10, 10, 10, 10, -10, 10, 10, 10, -10, 10, -10,
+
+ 10, -10, 10, 10, 10, -10, 10, 10, 10, 10, -10, -10,
+
+ -10, -10, 10, -10, 10, -10, -10, 10, 10, -10, -10, -10
+ };
+ private static final short[] s_cubeTexCoords =
+ {
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+ };
+
+ private static final float[] s_cubeColors =
+ {
+ 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f,
+ 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f,
+
+ 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f,
+ 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f,
+
+ 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f,
+ 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f,
+
+ 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f,
+ 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f,
+
+ 255f/255f, 110f/255f, 10f/255f, 255f/255f, 255f/255f, 110f/255f, 10f/255f, 255f/255f,
+ 255f/255f, 110f/255f, 10f/255f, 255f/255f, 255f/255f, 110f/255f, 10f/255f, 255f/255f,
+
+ 255f/255f, 70f/255f, 60f/255f, 255f/255f, 255f/255f, 70f/255f, 60f/255f, 255f/255f,
+ 255f/255f, 70f/255f, 60f/255f, 255f/255f, 255f/255f, 70f/255f, 60f/255f, 255
+ };
+ private static final byte[] s_cubeIndices =
+ {
+ 0, 3, 1, 2, 0, 1, /* front */
+ 6, 5, 4, 5, 7, 4, /* back */
+ 8, 11, 9, 10, 8, 9, /* top */
+ 15, 12, 13, 12, 14, 13, /* bottom */
+ 16, 19, 17, 18, 16, 17, /* right */
+ 23, 20, 21, 20, 22, 21 /* left */
+ };
+ private static final byte[] s_cubeNormals =
+ {
+ 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127,
+
+ 0, 0, -128, 0, 0, -128, 0, 0, -128, 0, 0, -128,
+
+ 0, -128, 0, 0, -128, 0, 0, -128, 0, 0, -128, 0,
+
+ 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0,
+
+ 127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0,
+
+ -128, 0, 0, -128, 0, 0, -128, 0, 0, -128, 0, 0
+ };
+
+
+ boolean innerCube;
+ boolean useTexCoords;
+ boolean initialized = false;
+ float time = 0.0f;
+ private GLU glu;
+
+ private void run(int type) {
+ int width = 800;
+ int height = 480;
+ System.err.println("CubeImmModeSink.run()");
+ try {
+ GLCapabilities caps = new GLCapabilities(null);
+ // For emulation library, use 16 bpp
+ caps.setRedBits(5);
+ caps.setGreenBits(6);
+ caps.setBlueBits(5);
+ caps.setDepthBits(16);
+
+ Window nWindow = null;
+ if(0!=(type&USE_AWT)) {
+ Display nDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null); // local display
+ Screen nScreen = NewtFactory.createScreen(NativeWindowFactory.TYPE_AWT, nDisplay, 0); // screen 0
+ nWindow = NewtFactory.createWindow(NativeWindowFactory.TYPE_AWT, nScreen, caps);
+ }
+ GLWindow window = GLWindow.create(nWindow, caps);
+
+ window.addGLEventListener(this);
+
+ window.enablePerfLog(true);
+ // Size OpenGL to Video Surface
+ window.setSize(width, height);
+ window.setFullscreen(true);
+ window.setVisible(true);
+
+ long curTime;
+ long startTime = System.currentTimeMillis();
+ while (!quit && ((curTime = System.currentTimeMillis()) - startTime) < 31000) {
+ window.display();
+ }
+
+ // Shut things down cooperatively
+ window.destroy();
+ window.getFactory().shutdown();
+ System.out.println("CubeImmModeSink shut down cleanly.");
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ public static int USE_NEWT = 0;
+ public static int USE_AWT = 1 << 0;
+
+ public static void main(String[] args) {
+ int type = USE_NEWT ;
+ for(int i=args.length-1; i>=0; i--) {
+ if(args[i].equals("-awt")) {
+ type |= USE_AWT;
+ }
+ }
+ new CubeImmModeSink().run(type);
+ System.exit(0);
+ }
+}
+
diff --git a/src/demos/es1/cubefbo/FBCubes.java b/src/demos/es1/cubefbo/FBCubes.java
new file mode 100755
index 0000000..ad4e120
--- /dev/null
+++ b/src/demos/es1/cubefbo/FBCubes.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package demos.es1.cubefbo;
+
+import demos.es1.cube.Cube;
+import java.nio.*;
+import javax.media.opengl.*;
+import com.sun.opengl.util.FBObject;
+import com.sun.opengl.util.glsl.fixedfunc.*;
+
+class FBCubes implements GLEventListener {
+ private static final int FBO_SIZE = 256;
+
+ public FBCubes () {
+ cubeOuter = new Cube(true, false);
+
+ fbo1 = new FBObject(FBO_SIZE, FBO_SIZE, FBObject.ATTR_DEPTH);
+ cubeInner = new Cube(false, true);
+
+ // JAU cubeMiddle = new Cube(true, false);
+ // JAU fbo2 = new FBObject(FBO_SIZE, FBO_SIZE);
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ GL2ES1 gl = FixedFuncUtil.getFixedFuncImpl(drawable.getGL());
+ System.out.println(gl);
+
+ gl.glGetError(); // flush error ..
+ /*
+ if(gl.isGLES2()) {
+ GLES2 gles2 = gl.getGLES2();
+
+ // Debug ..
+ //DebugGLES2 gldbg = new DebugGLES2(gles2);
+ //gles2.getContext().setGL(gldbg);
+ //gles2 = gldbg;
+
+ // Trace ..
+ //TraceGLES2 gltrace = new TraceGLES2(gles2, System.err);
+ gles2.getContext().setGL(gltrace);
+ gl = gltrace;
+ }*/
+
+ fbo1.init(gl);
+ //fbo1.init(gl, GL.GL_RGB, GL.GL_RGB, GL.GL_UNSIGNED_BYTE); // faster
+ //fbo1.init(gl, GL.GL_RGBA, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE); // GLES2 default
+ //fbo1.init(gl, GL.GL_RGBA, GL.GL_RGBA, GL.GL_UNSIGNED_SHORT_5_5_5_1); // useless (1bit alpha)
+ //fbo1.init(gl, GL.GL_RGBA8, GL2.GL_BGRA, GL2.GL_UNSIGNED_INT_8_8_8_8_REV); // GL2 default
+ cubeInner.init(drawable);
+
+ cubeOuter.init(drawable);
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ cubeOuter.reshape(drawable, x, y, width, height);
+ }
+
+ float xRot=0f;
+ float yRot=0f;
+
+ public void rotate(float xRot, float yRot) {
+ this.xRot = xRot;
+ this.yRot = yRot;
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+ fbo1.destroy(gl);
+ fbo1=null;
+ cubeInner.dispose(drawable);
+ cubeInner=null;
+ cubeOuter.dispose(drawable);
+ cubeOuter=null;
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL2ES1 gl = drawable.getGL().getGL2ES1();
+
+ fbo1.bind(gl);
+ cubeInner.reshape(drawable, 0, 0, FBO_SIZE, FBO_SIZE);
+ cubeInner.display(drawable);
+ gl.glFinish();
+ fbo1.unbind(gl);
+
+ gl.glActiveTexture(GL.GL_TEXTURE0);
+ gl.glEnable (gl.GL_TEXTURE_2D);
+ cubeOuter.reshape(drawable, 0, 0, drawable.getWidth(), drawable.getHeight());
+ fbo1.use(gl);
+ cubeOuter.display(drawable);
+ fbo1.unbind(gl);
+
+ gl.glDisable (gl.GL_TEXTURE_2D);
+
+ // JAUFBObject tex = fbo1;
+ // JAU FBObject rend = fbo2;
+
+ /* JAU
+ int MAX_ITER = 1;
+
+ for (int i = 0; i < MAX_ITER; i++) {
+ rend.bind(gl);
+ gl.glEnable (gl.GL_TEXTURE_2D);
+ gl.glBindTexture(gl.GL_TEXTURE_2D, tex.getTextureName()); // to use it ..
+ cubeMiddle.reshape(gl, 0, 0, FBO_SIZE, FBO_SIZE);
+ cubeMiddle.display(gl, xRot, yRot);
+ gl.glBindTexture(gl.GL_TEXTURE_2D, 0);
+ gl.glDisable (gl.GL_TEXTURE_2D);
+ rend.unbind(gl);
+ FBObject tmp = tex;
+ tex = rend;
+ rend = tmp;
+ }
+
+ // System.out.println("display .. p6");
+ gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
+ gl.glClearColor(0, 0, 0, 1);
+
+ gl.glEnable (gl.GL_TEXTURE_2D);
+ gl.glBindTexture(gl.GL_TEXTURE_2D, tex.getTextureName()); // to use it ..
+ cubeOuter.display(gl, xRot, yRot);
+ // System.out.println("display .. p7");
+ gl.glBindTexture(gl.GL_TEXTURE_2D, 0);
+ gl.glDisable (gl.GL_TEXTURE_2D);
+ */
+ }
+
+ public void displayChanged(javax.media.opengl.GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+ }
+
+ float time = 0.0f;
+ Cube cubeInner=null;
+ // JAU Cube cubeMiddle=null;
+ Cube cubeOuter=null;
+ FBObject fbo1;
+ // JAU FBObject fbo2;
+}
+
diff --git a/src/demos/es1/cubefbo/Main.java b/src/demos/es1/cubefbo/Main.java
new file mode 100755
index 0000000..51a03c7
--- /dev/null
+++ b/src/demos/es1/cubefbo/Main.java
@@ -0,0 +1,110 @@
+package demos.es1.cubefbo;
+
+import java.nio.*;
+import javax.media.opengl.*;
+import javax.media.nativewindow.*;
+import com.sun.javafx.newt.*;
+import com.sun.javafx.newt.opengl.*;
+
+public class Main implements WindowListener, MouseListener {
+
+ public boolean quit = false;
+ public GLWindow window = null;
+
+ public void windowResized(WindowEvent e) { }
+ public void windowMoved(WindowEvent e) { }
+ public void windowGainedFocus(WindowEvent e) { }
+ public void windowLostFocus(WindowEvent e) { }
+ public void windowDestroyNotify(WindowEvent e) {
+ quit = true;
+ }
+
+ public void mouseClicked(MouseEvent e) {
+ System.out.println("mouseevent: "+e);
+ switch(e.getClickCount()) {
+ case 1:
+ if(null!=window) {
+ window.setFullscreen(!window.isFullscreen());
+ }
+ break;
+ default:
+ quit=true;
+ break;
+ }
+ }
+ public void mouseEntered(MouseEvent e) {
+ }
+ public void mouseExited(MouseEvent e) {
+ }
+ public void mousePressed(MouseEvent e) {
+ }
+ public void mouseReleased(MouseEvent e) {
+ }
+ public void mouseMoved(MouseEvent e) {
+ }
+ public void mouseDragged(MouseEvent e) {
+ }
+ public void mouseWheelMoved(MouseEvent e) {
+ }
+
+ private void run(int type) {
+ int width = 800;
+ int height = 480;
+ System.out.println("cubefbo.Main.run()");
+ try {
+ // Hook this into EGL
+ GLCapabilities caps = new GLCapabilities(null);
+ // For emulation library, use 16 bpp
+ caps.setRedBits(5);
+ caps.setGreenBits(6);
+ caps.setBlueBits(5);
+ caps.setDepthBits(16);
+
+ Window nWindow = null;
+ if(0!=(type&USE_AWT)) {
+ Display nDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null); // local display
+ Screen nScreen = NewtFactory.createScreen(NativeWindowFactory.TYPE_AWT, nDisplay, 0); // screen 0
+ nWindow = NewtFactory.createWindow(NativeWindowFactory.TYPE_AWT, nScreen, caps);
+ }
+ window = GLWindow.create(nWindow, caps);
+
+ window.addWindowListener(this);
+ window.addMouseListener(this);
+
+ window.enablePerfLog(true);
+ window.setSize(width, height);
+ window.setFullscreen(true);
+ window.setVisible(true);
+
+ GL gl = window.getGL();
+ FBCubes cubes = new FBCubes();
+ window.addGLEventListener(cubes);
+
+ while ( !quit && window.getDuration() < 31000) {
+ window.display();
+ }
+
+ // Shut things down cooperatively
+ window.destroy();
+ window.getFactory().shutdown();
+ System.out.println("cubefbo.Main shut down cleanly.");
+ } catch (GLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static int USE_NEWT = 0;
+ public static int USE_AWT = 1 << 0;
+
+ public static void main(String[] args) {
+ int type = USE_NEWT ;
+ for(int i=args.length-1; i>=0; i--) {
+ if(args[i].equals("-awt")) {
+ type |= USE_AWT;
+ }
+ }
+ new Main().run(type);
+ System.exit(0);
+ }
+
+}