diff options
author | Sven Gothel <[email protected]> | 2008-07-10 17:02:59 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2008-07-10 17:02:59 +0000 |
commit | 86dfcfbe2554e1b85d659b71130a9b950ab98b42 (patch) | |
tree | 9d15db0e9a79dc6da30353745d4a3acaf33244b3 | |
parent | 724c4809b28e24c10273c3297f1b1c0209fcb16e (diff) |
cubefbo clean
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/branches/JOGL_2_SANDBOX@256 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
-rw-r--r-- | make/build.xml | 2 | ||||
-rwxr-xr-x | src/demos/es1/cubefbo/CubeObject.java | 66 | ||||
-rwxr-xr-x | src/demos/es1/cubefbo/FBCubes.java | 40 | ||||
-rwxr-xr-x | src/demos/es1/cubefbo/FBObject.java | 67 | ||||
-rwxr-xr-x | src/demos/es1/cubefbo/Main.java | 137 |
5 files changed, 132 insertions, 180 deletions
diff --git a/make/build.xml b/make/build.xml index f5d704d..e7a3608 100644 --- a/make/build.xml +++ b/make/build.xml @@ -183,7 +183,7 @@ <src path="${src}" /> <classpath refid="jogl-demos.classpath" /> </javac--> - <javac destdir="${classes}" includes="demos/es1/RedSquare.java demos/es1/angeles/**" source="1.4" target="1.4" debug="true" debuglevel="source,lines" + <javac destdir="${classes}" includes="demos/es1/**" source="1.4" target="1.4" debug="true" debuglevel="source,lines" bootclasspath="../../gluegen/make/lib/cdc_fp.jar"> <src path="${src}" /> <classpath refid="jogl-demos.classpath" /> diff --git a/src/demos/es1/cubefbo/CubeObject.java b/src/demos/es1/cubefbo/CubeObject.java index 8eb9c7f..85efd8d 100755 --- a/src/demos/es1/cubefbo/CubeObject.java +++ b/src/demos/es1/cubefbo/CubeObject.java @@ -34,7 +34,7 @@ package demos.es1.cubefbo; import javax.media.opengl.*; -import com.sun.opengl.util.*; +import javax.media.opengl.util.*; import java.nio.*; class CubeObject { @@ -63,7 +63,7 @@ class CubeObject { } } - private void perspective(GL gl, float fovy, float aspect, float zNear, float zFar) { + private void perspective(GL2ES1 gl, float fovy, float aspect, float zNear, float zFar) { float xmin; float xmax; float ymin; @@ -83,44 +83,44 @@ class CubeObject { 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 }; - public void reshape(GL gl, int x, int y, int width, int height) { + public void reshape(GL2ES1 gl, int x, int y, int width, int height) { float aspect = (height != 0) ? ((float)width / (float)height) : 1.0f; gl.glViewport(0, 0, width, height); gl.glScissor(0, 0, width, height); - gl.glMatrixMode(GL.GL_MODELVIEW); + gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); - 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.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.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.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_FASTEST); + gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_FASTEST); - gl.glShadeModel(GL.GL_SMOOTH); - gl.glDisable(GL.GL_DITHER); + gl.glShadeModel(gl.GL_SMOOTH); + gl.glDisable(gl.GL_DITHER); gl.glClearColor(0.0f, 0.1f, 0.0f, 1.0f); - gl.glEnableClientState(GL.GL_VERTEX_ARRAY); - gl.glEnableClientState(GL.GL_NORMAL_ARRAY); - gl.glEnableClientState(GL.GL_COLOR_ARRAY); + gl.glEnableClientState(gl.GL_VERTEX_ARRAY); + gl.glEnableClientState(gl.GL_NORMAL_ARRAY); + gl.glEnableClientState(gl.GL_COLOR_ARRAY); if (cubeTexCoords != null) { - gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); + gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY); } else { - gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY); + gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY); } - gl.glMatrixMode(GL.GL_PROJECTION); + gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); float fovy = 55.f; @@ -131,14 +131,14 @@ class CubeObject { } perspective(gl, fovy, aspect, 0.1f, 100.f); - gl.glCullFace(GL.GL_BACK); + gl.glCullFace(gl.GL_BACK); } - public void display(GL gl, float xRot, float yRot) { + public void display(GL2ES1 gl, float xRot, float yRot) { // System.out.println("CubeObject .. p1: "+this); - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); - gl.glMatrixMode(GL.GL_MODELVIEW); + gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0.f, 0.f, -30.f); @@ -148,16 +148,16 @@ class CubeObject { gl.glRotatef(yRot, 0, 1, 0); gl.glRotatef(xRot, 1, 0, 0); - gl.glVertexPointer(3, GL.GL_SHORT, 0, cubeVertices); - gl.glColorPointer(4, GL.GL_UNSIGNED_BYTE, 0, cubeColors); - gl.glNormalPointer(GL.GL_BYTE, 0, cubeNormals); + gl.glVertexPointer(3, gl.GL_SHORT, 0, cubeVertices); + gl.glColorPointer(4, gl.GL_UNSIGNED_BYTE, 0, cubeColors); + gl.glNormalPointer(gl.GL_BYTE, 0, cubeNormals); if (cubeTexCoords != null) { - gl.glTexCoordPointer(2, GL.GL_SHORT, 0, cubeTexCoords); - gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE); + gl.glTexCoordPointer(2, gl.GL_SHORT, 0, cubeTexCoords); + gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_REPLACE); } // System.out.println("CubeObject .. p8: "+this); - gl.glDrawElements(GL.GL_TRIANGLES, 6 * 6, GL.GL_UNSIGNED_BYTE, cubeIndices); + gl.glDrawElements(gl.GL_TRIANGLES, 6 * 6, gl.GL_UNSIGNED_BYTE, cubeIndices); // System.out.println("CubeObject .. p9: "+this); // time += 0.01f; diff --git a/src/demos/es1/cubefbo/FBCubes.java b/src/demos/es1/cubefbo/FBCubes.java index 724b798..7bb26b1 100755 --- a/src/demos/es1/cubefbo/FBCubes.java +++ b/src/demos/es1/cubefbo/FBCubes.java @@ -34,10 +34,9 @@ package demos.es1.cubefbo; import javax.media.opengl.*; -import com.sun.opengl.util.*; import java.nio.*; -class FBCubes { +class FBCubes implements GLEventListener { private static final int FBO_SIZE = 128; public FBCubes () { @@ -51,16 +50,27 @@ class FBCubes { fbo2 = new FBObject(FBO_SIZE, FBO_SIZE); } - public void init(GL gl) { + public void init(GLAutoDrawable drawable) { + GL2ES1 gl = drawable.getGL().getGL2ES1(); fbo1.init(gl); fbo2.init(gl); } - public void reshape(GL gl, int x, int y, int width, int height) { + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + GL2ES1 gl = drawable.getGL().getGL2ES1(); cubeOuter.reshape(gl, x, y, width, height); } - public void display(GL gl, float xRot, float yRot) { + float xRot=0f; + float yRot=0f; + + public void rotate(float xRot, float yRot) { + this.xRot = xRot; + this.yRot = yRot; + } + + public void display(GLAutoDrawable drawable) { + GL2ES1 gl = drawable.getGL().getGL2ES1(); fbo1.bind(gl); cubeInner.reshape(gl, 0, 0, FBO_SIZE, FBO_SIZE); @@ -74,12 +84,12 @@ class FBCubes { 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 .. + 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); + gl.glBindTexture(gl.GL_TEXTURE_2D, 0); + gl.glDisable (gl.GL_TEXTURE_2D); rend.unbind(gl); FBObject tmp = tex; tex = rend; @@ -87,18 +97,18 @@ class FBCubes { } // System.out.println("display .. p6"); - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + 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 .. + 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); + gl.glBindTexture(gl.GL_TEXTURE_2D, 0); + gl.glDisable (gl.GL_TEXTURE_2D); } - public void displayChanged(GL gl, boolean modeChanged, boolean deviceChanged) { + public void displayChanged(javax.media.opengl.GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { } float time = 0.0f; diff --git a/src/demos/es1/cubefbo/FBObject.java b/src/demos/es1/cubefbo/FBObject.java index 13d5b01..fcfeef1 100755 --- a/src/demos/es1/cubefbo/FBObject.java +++ b/src/demos/es1/cubefbo/FBObject.java @@ -34,7 +34,6 @@ package demos.es1.cubefbo; import javax.media.opengl.*; -import com.sun.opengl.util.*; import java.nio.*; class FBObject { @@ -56,78 +55,78 @@ class FBObject { gl.glBindTexture(GL.GL_TEXTURE_2D, fbo_tex); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); - gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB8_OES, width, height, 0, + gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB8, width, height, 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, null); - gl.glGenRenderbuffersOES(1, name, 0); + gl.glGenRenderbuffers(1, name, 0); depth_rb = name[0]; System.out.println("depth_rb: "+depth_rb); // Initialize the depth buffer: - gl.glBindRenderbufferOES(GL.GL_RENDERBUFFER_OES, depth_rb); - gl.glRenderbufferStorageOES(GL.GL_RENDERBUFFER_OES, - GL.GL_DEPTH_COMPONENT16_OES, width, height); + gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, depth_rb); + gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, + GL.GL_DEPTH_COMPONENT16, width, height); - // gl.glGenRenderbuffersOES(1, name, 0); + // gl.glGenRenderbuffers(1, name, 0); // stencil_rb = name[0]; stencil_rb = 0; System.out.println("stencil_rb: "+stencil_rb); - gl.glGenFramebuffersOES(1, name, 0); + gl.glGenFramebuffers(1, name, 0); fb = name[0]; System.out.println("fb: "+fb); // bind fbo .. - gl.glBindFramebufferOES(GL.GL_FRAMEBUFFER_OES, fb); + gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fb); // Set up the color buffer for use as a renderable texture: - gl.glFramebufferTexture2DOES(GL.GL_FRAMEBUFFER_OES, - GL.GL_COLOR_ATTACHMENT0_OES, + gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, + GL.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D, fbo_tex, 0); // Set up the depth buffer attachment: - gl.glFramebufferRenderbufferOES(GL.GL_FRAMEBUFFER_OES, - GL.GL_DEPTH_ATTACHMENT_OES, - GL.GL_RENDERBUFFER_OES, depth_rb); + gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, + GL.GL_DEPTH_ATTACHMENT, + GL.GL_RENDERBUFFER, depth_rb); // bind fbo .. - gl.glBindFramebufferOES(GL.GL_FRAMEBUFFER_OES, fb); + gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fb); // Setup the color buffer for use as a renderable texture: gl.glBindTexture(GL.GL_TEXTURE_2D, fbo_tex); - gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB8_OES, width, height, 0, + gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB8, width, height, 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, null); - gl.glFramebufferTexture2DOES(GL.GL_FRAMEBUFFER_OES, - GL.GL_COLOR_ATTACHMENT0_OES, + gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, + GL.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D, fbo_tex, 0); // Initialize the depth buffer: - gl.glBindRenderbufferOES(GL.GL_RENDERBUFFER_OES, depth_rb); + gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, depth_rb); - gl.glRenderbufferStorageOES(GL.GL_RENDERBUFFER_OES, - GL.GL_DEPTH_COMPONENT16_OES, width, height); + gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, + GL.GL_DEPTH_COMPONENT16, width, height); - gl.glFramebufferRenderbufferOES(GL.GL_FRAMEBUFFER_OES, - GL.GL_DEPTH_ATTACHMENT_OES, - GL.GL_RENDERBUFFER_OES, depth_rb); + gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, + GL.GL_DEPTH_ATTACHMENT, + GL.GL_RENDERBUFFER, depth_rb); if(stencil_rb!=0) { // Initialize the stencil buffer: - gl.glBindRenderbufferOES(GL.GL_RENDERBUFFER_OES, stencil_rb); + gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, stencil_rb); - gl.glRenderbufferStorageOES(GL.GL_RENDERBUFFER_OES, - GL.GL_STENCIL_INDEX8_OES, width, height); + gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, + GL.GL_STENCIL_INDEX8, width, height); - gl.glFramebufferRenderbufferOES(GL.GL_FRAMEBUFFER_OES, - GL.GL_STENCIL_ATTACHMENT_OES, - GL.GL_RENDERBUFFER_OES, stencil_rb); + gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, + GL.GL_STENCIL_ATTACHMENT, + GL.GL_RENDERBUFFER, stencil_rb); } // Check the FBO for completeness - int res = gl.glCheckFramebufferStatusOES(fb); - if (res == GL.GL_FRAMEBUFFER_COMPLETE_OES) { + int res = gl.glCheckFramebufferStatus(fb); + if (res == GL.GL_FRAMEBUFFER_COMPLETE) { System.out.println("Framebuffer " + fb + " is complete"); } else { System.out.println("Framebuffer " + fb + " is incomplete: status = 0x" + Integer.toHexString(res)); @@ -135,11 +134,11 @@ class FBObject { } public void bind(GL gl) { - gl.glBindFramebufferOES(GL.GL_FRAMEBUFFER_OES, fb); + gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fb); } public void unbind(GL gl) { - gl.glBindFramebufferOES(GL.GL_FRAMEBUFFER_OES, 0); + gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); } public int getFBName() { diff --git a/src/demos/es1/cubefbo/Main.java b/src/demos/es1/cubefbo/Main.java index 857f183..2e734c4 100755 --- a/src/demos/es1/cubefbo/Main.java +++ b/src/demos/es1/cubefbo/Main.java @@ -1,36 +1,3 @@ -/* - * 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 java.nio.*; @@ -39,20 +6,15 @@ import com.sun.javafx.newt.*; public class Main implements MouseListener { - private boolean quit = false; - private boolean toggleFS = false; - private Window window; - - private boolean dragging; - private int lastDragX; - private int lastDragY; - private float motionIncr; - private float xRot, yRot; + public boolean quit = false; + public GLWindow window = null; public void mouseClicked(MouseEvent e) { switch(e.getClickCount()) { case 1: - toggleFS=true; + if(null!=window) { + window.setFullscreen(!window.isFullscreen()); + } break; default: quit=true; @@ -66,104 +28,85 @@ public class Main implements MouseListener { public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { - dragging = false; } public void mouseMoved(MouseEvent e) { } public void mouseDragged(MouseEvent e) { - if (!dragging) { - dragging = true; - lastDragX = e.getX(); - lastDragY = e.getY(); - } else { - yRot += (e.getX() - lastDragX) * motionIncr; - xRot += (e.getY() - lastDragY) * motionIncr; - lastDragX = e.getX(); - lastDragY = e.getY(); - } } - public void run() { - System.out.println("CubeFBO Main"); + private void run(int type) { + int width = 800; + int height = 480; + System.out.println("cubefbo.Main.run()"); + GLProfile.setProfileGL2ES1(); try { - Display display = NewtFactory.createDisplay(null); // local display - Screen screen = NewtFactory.createScreen(display, 0); // screen 0 - window = NewtFactory.createWindow(screen, 0); // dummy VisualID - - window.addMouseListener(this); - - // Size OpenGL to Video Surface - int width = 800; - int height = 480; - window.setSize(width, height); - window.setFullscreen(true); + Window nWindow = null; + if(0!=(type&USE_AWT)) { + Display nDisplay = NewtFactory.createDisplay(NewtFactory.AWT, null); // local display + Screen nScreen = NewtFactory.createScreen(NewtFactory.AWT, nDisplay, 0); // screen 0 + nWindow = NewtFactory.createWindow(NewtFactory.AWT, nScreen, 0); // dummy VisualID + } // Hook this into EGL - GLDrawableFactory factory = GLDrawableFactory.getFactory(GLDrawableFactory.PROFILE_GLES1, window); GLCapabilities caps = new GLCapabilities(); // For emulation library, use 16 bpp caps.setRedBits(5); caps.setGreenBits(6); caps.setBlueBits(5); caps.setDepthBits(16); - GLDrawable drawable = factory.createGLDrawable(window, caps, null); - window.setVisible(true); - drawable.setRealized(true); - GLContext context = drawable.createContext(null); - context.makeCurrent(); + GLWindow window = GLWindow.create(nWindow, caps); - GL gl = context.getGL(); + window.addMouseListener(this); - motionIncr = 180.f / Math.max(window.getWidth(), window.getHeight()); + window.setSize(width, height); + window.setFullscreen(true); + window.setVisible(true); + + GL gl = window.getGL(); FBCubes cubes = new FBCubes(); - cubes.init(gl); + window.addGLEventListener(cubes); long startTime = System.currentTimeMillis(); long lastTime = startTime, curTime = 0, dt0, dt1; int totalFrames = 0, lastFrames = 0; do { - cubes.reshape(gl, 0, 0, window.getWidth(), window.getHeight()); - cubes.display(gl, xRot, yRot); - drawable.swapBuffers(); + window.display(); + totalFrames++; lastFrames++; curTime = System.currentTimeMillis(); dt0 = curTime-lastTime; if ( (curTime-lastTime) > 5000 ) { dt1 = curTime-startTime; System.out.println(dt1/1000+"s, 5s: "+ (lastFrames*1000)/dt0 + " fps, "+ - "total: "+ (totalFrames*1000)/dt1 + " fps"); + "total: "+ (totalFrames*1000)/dt1 + " fps"); lastTime=curTime; lastFrames=0; } - if(toggleFS) { - window.setFullscreen(!window.isFullscreen()); - toggleFS=false; - } - - window.pumpMessages(); - - // Thread.yield(); - // try{ - // Thread.sleep(10); - // } catch(InterruptedException ie) {} } while (!quit && (curTime - startTime) < 215000); // Shut things down cooperatively - context.release(); - context.destroy(); - drawable.destroy(); - factory.shutdown(); - System.out.println("CubeFBO shut down cleanly."); + window.close(); + 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) { - new Main().run(); + 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); } + } |