summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <sgothel@jausoft.com>2014-07-10 01:51:47 +0200
committerSven Gothel <sgothel@jausoft.com>2014-07-10 01:51:47 +0200
commit5a00a46bd2c494116b0cd73f98f9fe08bec8528f (patch)
tree5f776c3ac784ddf067d239652490877507e9fcf3
parent548fee0b3d65605ff5cbcbe750564eda1bc611d7 (diff)
Adapt to JOGL commit ec2d94ca26ddab8ec67135ebc5f2d0a43f6a4c25 (Bug 1031: Remove Deprecated Classes and Methods)
-rwxr-xr-xsrc/demos/es1/RedSquare.java129
-rwxr-xr-xsrc/demos/hdr/HDR.java179
-rw-r--r--src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java9
-rw-r--r--src/demos/jgears/JGears.java30
-rwxr-xr-xsrc/demos/misc/GLCapsTableDemo.java68
-rwxr-xr-xsrc/demos/multisample/Multisample.java57
-rw-r--r--src/demos/proceduralTexturePhysics/Water.java237
-rw-r--r--src/demos/testContextSharing/TestContextSharing.java46
-rwxr-xr-xsrc/demos/texture/TextureConvert.java29
9 files changed, 456 insertions, 328 deletions
diff --git a/src/demos/es1/RedSquare.java b/src/demos/es1/RedSquare.java
index 9160ad4..d8a772d 100755
--- a/src/demos/es1/RedSquare.java
+++ b/src/demos/es1/RedSquare.java
@@ -1,18 +1,38 @@
package demos.es1;
-import com.jogamp.common.nio.Buffers;
-import java.nio.*;
-import java.util.*;
-import javax.media.opengl.*;
-import javax.media.opengl.glu.*;
-import javax.media.nativewindow.*;
-
-import com.jogamp.opengl.util.*;
-import com.jogamp.opengl.util.glsl.fixedfunc.*;
+import java.nio.FloatBuffer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.opengl.FPSCounter;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES1;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLPipelineFactory;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.glu.GLU;
-import com.jogamp.newt.*;
-import com.jogamp.newt.event.*;
-import com.jogamp.newt.opengl.*;
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.newt.Display;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.event.KeyListener;
+import com.jogamp.newt.event.MouseEvent;
+import com.jogamp.newt.event.MouseListener;
+import com.jogamp.newt.event.WindowEvent;
+import com.jogamp.newt.event.WindowListener;
+import com.jogamp.newt.event.WindowUpdateEvent;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.glsl.fixedfunc.FixedFuncUtil;
+import com.jogamp.opengl.util.glsl.fixedfunc.ShaderSelectionMode;
public class RedSquare extends Thread implements WindowListener, KeyListener, MouseListener, GLEventListener {
@@ -24,8 +44,8 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo
private GLProfile glp;
private GLU glu;
private boolean quit = false;
- private String glprofile;
- private int type;
+ private final String glprofile;
+ private final int type;
Animator glAnimator=null;
public RedSquare() {
@@ -38,29 +58,38 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo
this.type=type;
}
- public void windowRepaint(WindowUpdateEvent e) {
+ @Override
+ public void windowRepaint(WindowUpdateEvent e) {
}
- public void windowResized(WindowEvent e) {
+ @Override
+ public void windowResized(WindowEvent e) {
}
- public void windowMoved(WindowEvent e) {
+ @Override
+ public void windowMoved(WindowEvent e) {
}
- public void windowDestroyNotify(WindowEvent e) {
+ @Override
+ public void windowDestroyNotify(WindowEvent e) {
System.out.println("WINDOW-DESTROY NOTIFY "+Thread.currentThread()+" QUIT "+e);
quit=true;
if(null!=glAnimator) {
glAnimator.stop();
}
}
- public void windowDestroyed(WindowEvent e) {
+ @Override
+ public void windowDestroyed(WindowEvent e) {
System.out.println("WINDOW-DESTROYED "+Thread.currentThread());
}
- public void windowGainedFocus(WindowEvent e) { }
- public void windowLostFocus(WindowEvent e) { }
+ @Override
+ public void windowGainedFocus(WindowEvent e) { }
+ @Override
+ public void windowLostFocus(WindowEvent e) { }
- public void keyPressed(KeyEvent e) {
+ @Override
+ public void keyPressed(KeyEvent e) {
System.out.println("KEY-PRESSED "+Thread.currentThread()+" UNHANDLED "+e);
}
- public void keyReleased(KeyEvent e) {
+ @Override
+ public void keyReleased(KeyEvent e) {
System.out.println("KEY-RELEASED "+Thread.currentThread()+" UNHANDLED "+e);
if( !e.isPrintableKey() || e.isAutoRepeat() ) {
return;
@@ -79,7 +108,8 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo
}
}
- public void mouseClicked(MouseEvent e) {
+ @Override
+ public void mouseClicked(MouseEvent e) {
System.out.println("MOUSE-CLICKED "+Thread.currentThread()+" UNHANDLED "+e);
switch(e.getClickCount()) {
case 1:
@@ -87,29 +117,37 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo
window.setFullscreen(!window.isFullscreen());
}
break;
- default:
+ default:
quit=true;
break;
}
}
- public void mouseEntered(MouseEvent e) {
+ @Override
+ public void mouseEntered(MouseEvent e) {
}
- public void mouseExited(MouseEvent e) {
+ @Override
+ public void mouseExited(MouseEvent e) {
}
- public void mousePressed(MouseEvent e) {
+ @Override
+ public void mousePressed(MouseEvent e) {
}
- public void mouseReleased(MouseEvent e) {
+ @Override
+ public void mouseReleased(MouseEvent e) {
}
- public void mouseMoved(MouseEvent e) {
+ @Override
+ public void mouseMoved(MouseEvent e) {
}
- public void mouseDragged(MouseEvent e) {
+ @Override
+ public void mouseDragged(MouseEvent e) {
}
- public void mouseWheelMoved(MouseEvent e) {
+ @Override
+ public void mouseWheelMoved(MouseEvent e) {
}
public boolean shouldQuit() { return quit; }
- public void run() {
+ @Override
+ public void run() {
int width = 800;
int height = 480;
glp = GLProfile.get(glprofile);
@@ -197,7 +235,8 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo
private FloatBuffer colors;
private FloatBuffer vertices;
- public void init(GLAutoDrawable drawable) {
+ @Override
+ public void init(GLAutoDrawable drawable) {
GL _gl = drawable.getGL();
if(glDebugEmu) {
@@ -209,7 +248,7 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo
// Trace ..
_gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", GL2ES2.class, _gl, new Object[] { System.err } ) );
}
- } catch (Exception e) {e.printStackTrace();}
+ } catch (Exception e) {e.printStackTrace();}
glDebug = false;
glTrace = false;
}
@@ -223,7 +262,7 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo
try {
// Debug ..
gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", GL2ES1.class, gl, null) );
- } catch (Exception e) {e.printStackTrace();}
+ } catch (Exception e) {e.printStackTrace();}
}
if(glTrace) {
@@ -267,7 +306,8 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo
gl.glEnable(GL.GL_DEPTH_TEST);
}
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ @Override
+ 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);
@@ -277,7 +317,8 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo
//glu.gluLookAt(0, 0, -20, 0, 0, 0, 0, 1, 0);
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+ public void display(GLAutoDrawable drawable) {
GL2ES1 gl = drawable.getGL().getGL2ES1();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
@@ -285,7 +326,7 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo
gl.glMatrixMode(gl.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, -10);
- float ang = ((float) window.getTotalFPSDuration() * 360.0f) / 4000.0f;
+ float ang = (window.getTotalFPSDuration() * 360.0f) / 4000.0f;
gl.glRotatef(ang, 0, 0, 1);
gl.glRotatef(ang, 0, 1, 0);
@@ -294,12 +335,12 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo
gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);
}
- public void dispose(GLAutoDrawable drawable) {
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
GL2ES1 gl = drawable.getGL().getGL2ES1();
System.out.println(Thread.currentThread()+" RedSquare.dispose: "+gl.getContext());
gl.glDisableClientState(gl.GL_VERTEX_ARRAY);
gl.glDisableClientState(gl.GL_COLOR_ARRAY);
- glu.destroy();
glu = null;
colors.clear();
colors = null;
@@ -337,11 +378,11 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo
} else if(args[i].equals("-1thread")) {
oneThread=true;
} else if(args[i].equals("-awt")) {
- type |= USE_AWT;
+ type |= USE_AWT;
} else if(args[i].equals("-noedt")) {
- useEDT = false;
+ useEDT = false;
} else if(args[i].equals("-animator")) {
- useAnimator = true;
+ useAnimator = true;
} else if(args[i].startsWith("-GL")) {
threads.add(new RedSquare(args[i].substring(1), type));
}
diff --git a/src/demos/hdr/HDR.java b/src/demos/hdr/HDR.java
index 47d2589..430fbd0 100755
--- a/src/demos/hdr/HDR.java
+++ b/src/demos/hdr/HDR.java
@@ -1,13 +1,5 @@
package demos.hdr;
-import com.jogamp.opengl.util.Animator;
-import com.jogamp.opengl.util.gl2.GLUT;
-import demos.common.Demo;
-import demos.common.DemoListener;
-import demos.util.DurationTimer;
-import demos.util.ObjReader;
-import demos.util.SystemTime;
-import demos.util.Time;
import gleem.BSphere;
import gleem.BSphereProvider;
import gleem.CameraParameters;
@@ -16,6 +8,7 @@ import gleem.ManipManager;
import gleem.linalg.Mat4f;
import gleem.linalg.Rotf;
import gleem.linalg.Vec3f;
+
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.KeyAdapter;
@@ -26,6 +19,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
+
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
@@ -34,21 +28,31 @@ import javax.media.opengl.GLContext;
import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLException;
-import javax.media.opengl.GLPbuffer;
+import javax.media.opengl.GLOffscreenAutoDrawable;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.AWTGLAutoDrawable;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
import javax.swing.JOptionPane;
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.gl2.GLUT;
+
+import demos.common.Demo;
+import demos.common.DemoListener;
+import demos.util.DurationTimer;
+import demos.util.ObjReader;
+import demos.util.SystemTime;
+import demos.util.Time;
+
/** HDR demo by NVidia Corporation - Simon Green, sgreen@nvidia.com <P>
Ported to Java by Kenneth Russell
-
+
Currently not working due to loss of pbuffer attributes [floating point buffer, etc].
Need to evaluate proper floating point texture solution.
-
+
http://www.opengl.org/wiki/Floating_point_and_mipmapping_and_filtering
*/
@@ -70,19 +74,19 @@ public class HDR extends Demo {
private ObjReader model;
private Pipeline pipeline;
- private GLUT glut = new GLUT();
+ private final GLUT glut = new GLUT();
+
+ private final boolean[] b = new boolean[256];
- private boolean[] b = new boolean[256];
-
private ExaminerViewer viewer;
private boolean doViewAll = true;
- private DurationTimer timer = new DurationTimer();
+ private final DurationTimer timer = new DurationTimer();
private boolean firstRender = true;
private int frameCount;
- private Time time = new SystemTime();
- private float animRate = (float) Math.toRadians(-12.0f); // Radians / sec
+ private final Time time = new SystemTime();
+ private final float animRate = (float) Math.toRadians(-12.0f); // Radians / sec
private String hdrFilename;
private int win_w;
@@ -99,16 +103,16 @@ public class HDR extends Demo {
private int modelno = 4;
private int numModels = 5;
- private boolean hilo = false;
+ private final boolean hilo = false;
private int hdr_tex;
private int hdr_tex2;
private int gamma_tex;
private int vignette_tex;
- private GLPbuffer pbuffer;
- private GLPbuffer blur_pbuffer;
- private GLPbuffer blur2_pbuffer;
- private GLPbuffer tonemap_pbuffer;
+ private GLOffscreenAutoDrawable pbuffer;
+ private GLOffscreenAutoDrawable blur_pbuffer;
+ private GLOffscreenAutoDrawable blur2_pbuffer;
+ private GLOffscreenAutoDrawable tonemap_pbuffer;
// Texture objects for these pbuffers
private int pbuffer_tex;
private int blur_pbuffer_tex;
@@ -129,7 +133,7 @@ public class HDR extends Demo {
private float exposure = 32.0f;
- private float[] identityMatrix = { 1.0f, 0.0f, 0.0f, 0.0f,
+ private final float[] identityMatrix = { 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 };
@@ -141,31 +145,35 @@ public class HDR extends Demo {
canvas.addGLEventListener(demo);
canvas.addKeyListener(new KeyAdapter() {
- public void keyPressed(KeyEvent e) {
+ @Override
+ public void keyPressed(KeyEvent e) {
demo.dispatchKey(e.getKeyCode(), e.getKeyChar());
}
});
final Animator animator = new Animator(canvas);
demo.setDemoListener(new DemoListener() {
- public void shutdownDemo() {
+ @Override
+ public void shutdownDemo() {
runExit(animator);
}
- public void repaint() {}
+ @Override
+ public void repaint() {}
});
demo.setup(args);
Frame frame = new Frame("High Dynamic Range Rendering Demo");
frame.setLayout(new BorderLayout());
canvas.setSize(demo.getPreferredWidth(), demo.getPreferredHeight());
-
+
frame.add(canvas, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
canvas.requestFocus();
frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
+ @Override
+ public void windowClosing(WindowEvent e) {
runExit(animator);
}
});
@@ -259,7 +267,8 @@ public class HDR extends Demo {
// Internals only below this point
//
- public void shutdownDemo() {
+ @Override
+public void shutdownDemo() {
if(null!=drawable) {
ManipManager.getManipManager().unregisterWindow((AWTGLAutoDrawable) drawable);
drawable.removeGLEventListener(this);
@@ -271,13 +280,14 @@ public class HDR extends Demo {
// Listener for main window
//
- private float zNear = 0.1f;
- private float zFar = 10.0f;
+ private final float zNear = 0.1f;
+ private final float zFar = 10.0f;
// private boolean wire = false;
// private boolean toggleWire = false;
- private GLU glu = new GLU();
+ private final GLU glu = new GLU();
- public void init(GLAutoDrawable drawable) {
+ @Override
+public void init(GLAutoDrawable drawable) {
initComplete = false;
// printThreadName("init for Listener");
@@ -317,6 +327,7 @@ public class HDR extends Demo {
caps.setBlueBits(floatBits);
caps.setAlphaBits(floatAlphaBits);
caps.setDepthBits(floatDepthBits);
+ caps.setPBuffer(true);
int[] tmp = new int[1];
if (!GLDrawableFactory.getFactory(GLProfile.getDefault()).canCreateGLPbuffer(null, caps.getGLProfile())) {
unavailableExtension("Can not create pbuffer");
@@ -338,16 +349,20 @@ public class HDR extends Demo {
tonemap_pbuffer = null;
}
- GLContext parentContext = drawable.getContext();
- pbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createGLPbuffer(null, caps, null, pbuffer_w, pbuffer_h, parentContext);
+ final GLContext parentContext = drawable.getContext();
+ pbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createOffscreenAutoDrawable(null, caps, null, pbuffer_w, pbuffer_h);
+ pbuffer.setSharedContext(parentContext);
pbuffer.addGLEventListener(new PbufferListener());
gl.glGenTextures(1, tmp, 0);
pbuffer_tex = tmp[0];
- blur_pbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createGLPbuffer(null, caps, null, blur_w, blur_h, parentContext);
+
+ blur_pbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createOffscreenAutoDrawable(null, caps, null, blur_w, blur_h);
+ blur_pbuffer.setSharedContext(parentContext);
blur_pbuffer.addGLEventListener(new BlurPbufferListener());
gl.glGenTextures(1, tmp, 0);
blur_pbuffer_tex = tmp[0];
- blur2_pbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createGLPbuffer(null, caps, null, blur_w, blur_h, parentContext);
+ blur2_pbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createOffscreenAutoDrawable(null, caps, null, blur_w, blur_h);
+ blur2_pbuffer.setSharedContext(parentContext);
blur2_pbuffer.addGLEventListener(new Blur2PbufferListener());
gl.glGenTextures(1, tmp, 0);
blur2_pbuffer_tex = tmp[0];
@@ -355,11 +370,12 @@ public class HDR extends Demo {
caps.setGreenBits(8);
caps.setBlueBits(8);
caps.setDepthBits(24);
- tonemap_pbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createGLPbuffer(null, caps, null, pbuffer_w, pbuffer_h, parentContext);
+ tonemap_pbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createOffscreenAutoDrawable(null, caps, null, pbuffer_w, pbuffer_h);
+ tonemap_pbuffer.setSharedContext(parentContext);
tonemap_pbuffer.addGLEventListener(new TonemapPbufferListener());
gl.glGenTextures(1, tmp, 0);
tonemap_pbuffer_tex = tmp[0];
-
+
doViewAll = true;
// Register the window with the ManipManager
@@ -372,7 +388,8 @@ public class HDR extends Demo {
viewer.setAutoRedrawMode(false);
viewer.setNoAltKeyMode(true);
viewer.attach((AWTGLAutoDrawable) drawable, new BSphereProvider() {
- public BSphere getBoundingSphere() {
+ @Override
+ public BSphere getBoundingSphere() {
return new BSphere(new Vec3f(0, 0, 0), 1.0f);
}
});
@@ -381,10 +398,12 @@ public class HDR extends Demo {
initComplete = true;
}
- public void dispose(GLAutoDrawable drawable) {
+ @Override
+public void dispose(GLAutoDrawable drawable) {
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+public void display(GLAutoDrawable drawable) {
// printThreadName("display for Listener");
if (!initComplete) {
@@ -454,7 +473,8 @@ public class HDR extends Demo {
Thread.yield();
}
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ @Override
+public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
setOrthoProjection(drawable.getGL().getGL2(), x, y, width, height);
win_w = width;
win_h = height;
@@ -519,7 +539,7 @@ public class HDR extends Demo {
case KeyEvent.VK_O:
modelno = (modelno + 1) % numModels;
break;
-
+
case KeyEvent.VK_V:
doViewAll = true;
break;
@@ -558,7 +578,7 @@ public class HDR extends Demo {
int[] tmp = new int[1];
gl.glGenTextures(1, tmp, 0);
int texid = tmp[0];
-
+
gl.glBindTexture(GL2.GL_TEXTURE_RECTANGLE_ARB, texid);
gl.glTexParameteri(GL2.GL_TEXTURE_RECTANGLE_ARB, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
gl.glTexParameteri(GL2.GL_TEXTURE_RECTANGLE_ARB, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
@@ -597,7 +617,8 @@ public class HDR extends Demo {
//
class PbufferListener implements GLEventListener {
- public void init(GLAutoDrawable drawable) {
+ @Override
+ public void init(GLAutoDrawable drawable) {
// printThreadName("init for PbufferListener");
// drawable.setGL(new DebugGL(drawable.getGL()));
@@ -609,9 +630,9 @@ public class HDR extends Demo {
setPerspectiveProjection(gl, pbuffer_w, pbuffer_h);
@SuppressWarnings("deprecation")
- GLPbuffer pbuffer = (GLPbuffer) drawable;
+ GLOffscreenAutoDrawable pbuffer = (GLOffscreenAutoDrawable) drawable;
int fpmode = 0; // FIXME: pbuffer.getFloatingPointMode();
- int texmode = 0;
+ // int texmode = 0;
switch (fpmode) {
/** FIXME
case GLPbuffer.NV_FLOAT:
@@ -647,7 +668,8 @@ public class HDR extends Demo {
pipeline.initFloatingPointTexture(gl, pbuffer_tex, pbuffer_w, pbuffer_h); */
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+ public void display(GLAutoDrawable drawable) {
// printThreadName("display for PbufferListener");
GL2 gl = drawable.getGL().getGL2();
@@ -659,9 +681,11 @@ public class HDR extends Demo {
}
// Unused routines
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
- public void dispose(GLAutoDrawable drawable) {}
+ @Override
+ public void dispose(GLAutoDrawable drawable) {}
//----------------------------------------------------------------------
// Internals only below this point
@@ -686,7 +710,7 @@ public class HDR extends Demo {
} else {
gl.glDisable(GL2.GL_MULTISAMPLE);
}
-
+
if (!b['e']) {
// draw background
pipeline.enableFragmentProgram(gl, skybox_fprog);
@@ -791,7 +815,8 @@ public class HDR extends Demo {
}
class BlurPbufferListener implements GLEventListener {
- public void init(GLAutoDrawable drawable) {
+ @Override
+ public void init(GLAutoDrawable drawable) {
// printThreadName("init for BlurPbufferListener");
// drawable.setGL(new DebugGL(drawable.getGL()));
@@ -804,7 +829,8 @@ public class HDR extends Demo {
pipeline.initFloatingPointTexture(gl, blur_pbuffer_tex, blur_w, blur_h);
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+ public void display(GLAutoDrawable drawable) {
// printThreadName("display for BlurPbufferListener");
GL2 gl = drawable.getGL().getGL2();
@@ -819,13 +845,16 @@ public class HDR extends Demo {
}
// Unused routines
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
- public void dispose(GLAutoDrawable drawable) {}
+ @Override
+ public void dispose(GLAutoDrawable drawable) {}
}
class Blur2PbufferListener implements GLEventListener {
- public void init(GLAutoDrawable drawable) {
+ @Override
+ public void init(GLAutoDrawable drawable) {
// printThreadName("init for Blur2PbufferListener");
// drawable.setGL(new DebugGL(drawable.getGL()));
@@ -837,7 +866,8 @@ public class HDR extends Demo {
pipeline.initFloatingPointTexture(gl, blur2_pbuffer_tex, blur_w, blur_h);
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+ public void display(GLAutoDrawable drawable) {
// printThreadName("display for Blur2PbufferListener");
GL2 gl = drawable.getGL().getGL2();
@@ -859,7 +889,7 @@ public class HDR extends Demo {
gl.glActiveTexture(GL2.GL_TEXTURE0);
pipeline.bindTexture(gl, blur_pbuffer_tex);
glowPass(gl);
-
+
} else {
throw new RuntimeException("Illegal value of blur2Pass: " + blur2Pass);
}
@@ -868,13 +898,16 @@ public class HDR extends Demo {
}
// Unused routines
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
- public void dispose(GLAutoDrawable drawable) {}
+ @Override
+ public void dispose(GLAutoDrawable drawable) {}
}
class TonemapPbufferListener implements GLEventListener {
- public void init(GLAutoDrawable drawable) {
+ @Override
+ public void init(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
setOrthoProjection(gl, 0, 0, pbuffer_w, pbuffer_h);
@@ -882,7 +915,8 @@ public class HDR extends Demo {
pipeline.initTexture(gl, tonemap_pbuffer_tex, pbuffer_w, pbuffer_h);
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+ public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
toneMappingPass(gl);
@@ -891,9 +925,11 @@ public class HDR extends Demo {
}
// Unused routines
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
- public void dispose(GLAutoDrawable drawable) {}
+ @Override
+ public void dispose(GLAutoDrawable drawable) {}
}
//----------------------------------------------------------------------
@@ -910,7 +946,7 @@ public class HDR extends Demo {
gl.glLoadIdentity();
gl.glViewport(x, y, w, h);
}
-
+
private void setPerspectiveProjection(GL2 gl, int w, int h) {
// FIXME: what about ExaminerViewer?
gl.glMatrixMode(GL2.GL_PROJECTION);
@@ -1057,7 +1093,7 @@ public class HDR extends Demo {
// Cg and blur code initialization
//
- private String shaderRoot = "demos/hdr/shaders/";
+ private final String shaderRoot = "demos/hdr/shaders/";
private void initCg(GL2 gl) {
// NOTE: need to instantiate CgPipeline reflectively to avoid
// compile-time dependence (since Cg support might not be present)
@@ -1208,7 +1244,7 @@ public class HDR extends Demo {
float sum = 0;
for(int i=-n; i<=n; i++) {
- float weight = gaussian(3.0f*i / (float) n, 1.0f);
+ float weight = gaussian(3.0f*i / n, 1.0f);
sum += weight;
}
System.err.println("sum = " + sum);
@@ -1216,8 +1252,8 @@ public class HDR extends Demo {
buf.append("!!ARBfp1.0\n");
buf.append("TEMP H0, H1, H2;\n");
for(int i=-n; i<=n; i+=2) {
- float weight = gaussian(3.0f*i / (float) n, 1.0f) / sum;
- float weight2 = gaussian(3.0f*(i+1) / (float) n, 1.0f) / sum;
+ float weight = gaussian(3.0f*i / n, 1.0f) / sum;
+ float weight2 = gaussian(3.0f*(i+1) / n, 1.0f) / sum;
int x_offset, y_offset, x_offset2, y_offset2;
if (vertical) {
@@ -1283,7 +1319,8 @@ public class HDR extends Demo {
// routines cause a global AWT lock to be grabbed. Run the
// exit routine in another thread.
new Thread(new Runnable() {
- public void run() {
+ @Override
+ public void run() {
animator.stop();
System.exit(0);
}
diff --git a/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java b/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java
index a53c140..890d906 100644
--- a/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java
+++ b/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java
@@ -58,7 +58,8 @@ import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLException;
-import javax.media.opengl.GLPbuffer;
+import javax.media.opengl.GLOffscreenAutoDrawable;
+import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.AWTGLAutoDrawable;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
@@ -133,7 +134,7 @@ public void shutdownDemo() {
super.shutdownDemo();
}
- private GLPbuffer pbuffer;
+ private GLOffscreenAutoDrawable pbuffer;
private GLU glu;
private GLUT glut;
@@ -285,6 +286,7 @@ public void init(GLAutoDrawable drawable) {
// init pbuffer
GLCapabilities caps = new GLCapabilities(gl.getGLProfile());
caps.setDoubleBuffered(false);
+ caps.setPBuffer(true);
if (!GLDrawableFactory.getFactory(gl.getGLProfile()).canCreateGLPbuffer(null, gl.getGLProfile())) {
unavailableExtension("Can not create pbuffer");
@@ -293,7 +295,8 @@ public void init(GLAutoDrawable drawable) {
pbuffer.destroy();
pbuffer = null;
}
- pbuffer = GLDrawableFactory.getFactory(gl.getGLProfile()).createGLPbuffer(null, caps, null, TEX_SIZE, TEX_SIZE, drawable.getContext());
+ pbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createOffscreenAutoDrawable(null, caps, null, TEX_SIZE, TEX_SIZE);
+ pbuffer.setSharedContext(drawable.getContext());
pbuffer.addGLEventListener(new PbufferListener());
doViewAll = true;
diff --git a/src/demos/jgears/JGears.java b/src/demos/jgears/JGears.java
index 7e7d2e2..db466e3 100644
--- a/src/demos/jgears/JGears.java
+++ b/src/demos/jgears/JGears.java
@@ -1,7 +1,6 @@
package demos.jgears;
-import demos.gears.Gears;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
@@ -17,15 +16,19 @@ import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.text.DecimalFormat;
+
import javax.imageio.ImageIO;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLJPanel;
-import com.jogamp.opengl.util.Animator;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
+import com.jogamp.opengl.util.Animator;
+
+import demos.gears.Gears;
+
/**
* JGears.java <BR>
* author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
@@ -39,7 +42,7 @@ public class JGears extends GLJPanel {
private int frameCount;
private float fps;
private static Font fpsFont = new Font("SansSerif", Font.BOLD, 24);
- private DecimalFormat format = new DecimalFormat("####.00");
+ private final DecimalFormat format = new DecimalFormat("####.00");
private BufferedImage javaImage;
private BufferedImage openglImage;
@@ -47,9 +50,9 @@ public class JGears extends GLJPanel {
caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
caps.setAlphaBits(8);
}
-
+
public JGears() {
- super(caps, null, null);
+ super(caps, null);
addGLEventListener(new Gears());
try {
InputStream in = JGears.class.getClassLoader().getResourceAsStream("demos/data/images/java_logo.png");
@@ -65,7 +68,8 @@ public class JGears extends GLJPanel {
}
- public void paintComponent(Graphics g) {
+ @Override
+public void paintComponent(Graphics g) {
super.paintComponent(g);
if (startTime == 0) {
startTime = System.currentTimeMillis();
@@ -73,7 +77,7 @@ public class JGears extends GLJPanel {
if (++frameCount == 30) {
long endTime = System.currentTimeMillis();
- fps = 30.0f / (float) (endTime - startTime) * 1000;
+ fps = 30.0f / (endTime - startTime) * 1000;
frameCount = 0;
startTime = System.currentTimeMillis();
}
@@ -96,7 +100,8 @@ public class JGears extends GLJPanel {
// Helper routine for various demos
public static JPanel createGradientPanel() {
JPanel gradientPanel = new JPanel() {
- public void paintComponent(Graphics g) {
+ @Override
+ public void paintComponent(Graphics g) {
((Graphics2D) g).setPaint(new GradientPaint(0, 0, Color.WHITE,
getWidth(), getHeight(), Color.DARK_GRAY));
g.fillRect(0, 0, getWidth(), getHeight());
@@ -129,7 +134,8 @@ public class JGears extends GLJPanel {
final JCheckBox checkBox = new JCheckBox("Transparent", true);
checkBox.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
+ @Override
+ public void actionPerformed(ActionEvent e) {
drawable.setOpaque(!checkBox.isSelected());
}
});
@@ -138,12 +144,14 @@ public class JGears extends GLJPanel {
frame.setSize(300, 300);
final Animator animator = new Animator(drawable);
frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
+ @Override
+ public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
- public void run() {
+ @Override
+ public void run() {
animator.stop();
System.exit(0);
}
diff --git a/src/demos/misc/GLCapsTableDemo.java b/src/demos/misc/GLCapsTableDemo.java
index b74b003..f59de04 100755
--- a/src/demos/misc/GLCapsTableDemo.java
+++ b/src/demos/misc/GLCapsTableDemo.java
@@ -1,10 +1,6 @@
package demos.misc;
-import javax.swing.border.TitledBorder;
-import javax.swing.table.TableColumn;
-
-import demos.gears.Gears;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GraphicsDevice;
@@ -12,15 +8,15 @@ import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
+
+import javax.media.nativewindow.CapabilitiesImmutable;
import javax.media.opengl.DefaultGLCapabilitiesChooser;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLCapabilitiesChooser;
-import javax.media.opengl.awt.GLCanvas;
-import com.jogamp.opengl.util.FPSAnimator;
-import javax.media.nativewindow.CapabilitiesImmutable;
import javax.media.opengl.GLCapabilitiesImmutable;
+import javax.media.opengl.awt.GLCanvas;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
@@ -28,6 +24,12 @@ import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
+import javax.swing.border.TitledBorder;
+import javax.swing.table.TableColumn;
+
+import com.jogamp.opengl.util.FPSAnimator;
+
+import demos.gears.Gears;
/*******************************************************************************
* @file GLCapsTableDemo.java
@@ -52,24 +54,25 @@ public class GLCapsTableDemo
implements
GLCapabilitiesChooser
{
- private String[] colNames =
+ private final String[] colNames =
{"Pfd", "H/W", "DblBfr", "Stereo", // index, hwaccel, double, stereo
"CBits", "cR", "cG", "cB", "cA", // color bits
"ABits", "aR", "aG", "aB", "aA", // accum bits
"Z", "S", "AA|AAS", "PBuf(Float|RTT|RTTRec)"}; // depth, stencil, n
// samples, pbuffer
- private ArrayList<GLCapabilities> available = new ArrayList<GLCapabilities>();
- private ArrayList<Integer> indices = new ArrayList<Integer>();
+ private final ArrayList<GLCapabilities> available = new ArrayList<GLCapabilities>();
+ private final ArrayList<Integer> indices = new ArrayList<Integer>();
private Object[][] data;
private JTable capsTable;
private int desiredCapIndex; // pfd index
// private int selected = desiredCapIndex;
protected JPanel pane, pane2;
private boolean updateLR;// leftright
- private DefaultGLCapabilitiesChooser choiceExaminer = //
+ private final DefaultGLCapabilitiesChooser choiceExaminer = //
new DefaultGLCapabilitiesChooser()
{
- public int chooseCapabilities(CapabilitiesImmutable _desired,
+ @Override
+ public int chooseCapabilities(CapabilitiesImmutable _desired,
List/*<CapabilitiesImmutable>*/ available,
int windowSystemRecommendedChoice)
{
@@ -102,21 +105,21 @@ public class GLCapsTableDemo
return desiredCapIndex;
}
};
- private GraphicsDevice device = GraphicsEnvironment
+ private final GraphicsDevice device = GraphicsEnvironment
.getLocalGraphicsEnvironment().getDefaultScreenDevice();
private JSplitPane canvasPane;
private GLCanvas canvas;
private GLCanvas canvas2;
- private Gears topRenderer = new Gears(), bottomRenderer = new Gears();
+ private final Gears topRenderer = new Gears(), bottomRenderer = new Gears();
private FPSAnimator animator;
- private Dimension defdim = new Dimension(512, 256);
- private String visTip = "If no gears are visible, it may be that the "
+ private final Dimension defdim = new Dimension(512, 256);
+ private final String visTip = "If no gears are visible, it may be that the "
+ "current desktop color resolution doesn't match "
+ "the GLCapabilities chosen. Check CBits column.";
/**
-
+
*/
public GLCapsTableDemo()
{
@@ -126,17 +129,18 @@ public class GLCapsTableDemo
/**
* (non-Javadoc)
- *
+ *
* @see javax.media.opengl.GLCapabilitiesChooser#chooseCapabilities(javax.media.nativewindow.Capabilities,
* javax.media.nativewindow.Capabilities[], int)
*/
- public int chooseCapabilities(CapabilitiesImmutable desired,
+ @Override
+public int chooseCapabilities(CapabilitiesImmutable desired,
List/*<CapabilitiesImmutable>*/ available,
int windowSystemRecommendedChoice)
{
int row = capsTable.getSelectedRow();
if ( 0> row || row >= indices.size() ) return windowSystemRecommendedChoice;
- int desiredCapIndex = ((Integer) indices.get(row)).intValue();
+ int desiredCapIndex = indices.get(row).intValue();
if ( updateLR )
{
pane.setBorder(BorderFactory
@@ -181,7 +185,7 @@ public class GLCapsTableDemo
// Hack: use multisampled capabilities to pick up more detailed information on Windows
GLCapabilities multisampledCaps = new GLCapabilities(null);
multisampledCaps.setSampleBuffers(true);
- canvas = new GLCanvas(multisampledCaps, choiceExaminer, null, device);
+ canvas = new GLCanvas(multisampledCaps, choiceExaminer, device);
// initially start w/ 2 canvas of default caps
// canvas = new GLCanvas(null, choiceExaminer, null, device);
@@ -190,7 +194,7 @@ public class GLCapsTableDemo
// canvas.setPreferredSize(defdim);
// canvas.setMaximumSize(defdim);
animator = new FPSAnimator(canvas, 30);
- canvas2 = new GLCanvas(null, null, null, device);
+ canvas2 = new GLCanvas(null, null, device);
canvas2.addGLEventListener(bottomRenderer);
canvas2.setSize(defdim);
// canvas2.setPreferredSize(defdim);
@@ -220,7 +224,7 @@ public class GLCapsTableDemo
data[ pfd ][ 1 ] = "" + (cap.getHardwareAccelerated() ? f : f);
data[ pfd ][ 2 ] = "" + (cap.getDoubleBuffered() ? t : f);
data[ pfd ][ 3 ] = "" + (cap.getStereo() ? t : f);
- int r = cap.getRedBits(), //
+ int r = cap.getRedBits(), //
g = cap.getGreenBits(), //
b = cap.getBlueBits(), //
a = cap.getAlphaBits();
@@ -252,7 +256,8 @@ public class GLCapsTableDemo
data[ pfd ][ 17 ] = "FFf";
}
JTable table = new JTable(data, colNames) {
- public boolean isCellEditable(int rowIndex, int colIndex) {
+ @Override
+ public boolean isCellEditable(int rowIndex, int colIndex) {
return false;
}
};
@@ -279,7 +284,8 @@ public class GLCapsTableDemo
final JButton spawn2 = new JButton("Respawn Right");
ActionListener recap = new ActionListener()
{
- public void actionPerformed(final ActionEvent act)
+ @Override
+ public void actionPerformed(final ActionEvent act)
{
animator.stop();
if ( act.getSource() == spawn )
@@ -302,7 +308,8 @@ public class GLCapsTableDemo
}
new Thread()
{
- public void run()
+ @Override
+ public void run()
{
animator.start();
}
@@ -322,8 +329,8 @@ public class GLCapsTableDemo
private GLCanvas newCanvas(boolean mycap, boolean top)
{
GLCanvas surface = null;
- if ( !mycap ) surface = new GLCanvas(null, choiceExaminer, null, device);
- else surface = new GLCanvas(null, this, null, device);
+ if ( !mycap ) surface = new GLCanvas(null, choiceExaminer, device);
+ else surface = new GLCanvas(null, this, device);
if ( top ) surface.addGLEventListener(topRenderer);
else surface.addGLEventListener(bottomRenderer);
surface.setSize(defdim);// otherwise, no show; mixin' light-heavy containers
@@ -335,7 +342,8 @@ public class GLCapsTableDemo
{
new Thread()
{
- public void run()
+ @Override
+ public void run()
{
animator.stop();
}
diff --git a/src/demos/multisample/Multisample.java b/src/demos/multisample/Multisample.java
index 6c2624b..9796d87 100755
--- a/src/demos/multisample/Multisample.java
+++ b/src/demos/multisample/Multisample.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2003 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
@@ -28,23 +28,33 @@
* 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.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
package demos.multisample;
+import java.awt.BorderLayout;
+import java.awt.Frame;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
import java.util.List;
-import java.awt.*;
-import java.awt.event.*;
import javax.media.nativewindow.CapabilitiesImmutable;
-import javax.media.opengl.*;
+import javax.media.opengl.DefaultGLCapabilitiesChooser;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2;
+import javax.media.opengl.GL2ES1;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLCapabilitiesChooser;
+import javax.media.opengl.GLCapabilitiesImmutable;
+import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLCanvas;
public class Multisample {
@@ -86,9 +96,9 @@ public class Multisample {
caps.setSampleBuffers(true);
caps.setNumSamples(4);
- canvas = new GLCanvas(caps, chooser, null, null);
+ canvas = new GLCanvas(caps, chooser, null);
canvas.addGLEventListener(new Listener());
-
+
Frame frame = new Frame("Full-scene antialiasing");
frame.setLayout(new BorderLayout());
canvas.setSize(512, 512);
@@ -99,7 +109,8 @@ public class Multisample {
canvas.requestFocus();
frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
+ @Override
+ public void windowClosing(WindowEvent e) {
runExit();
}
});
@@ -108,7 +119,7 @@ public class Multisample {
caps.setSampleBuffers(false);
canvas = new GLCanvas(caps);
canvas.addGLEventListener(new Listener());
-
+
frame = new Frame("No antialiasing");
frame.setLayout(new BorderLayout());
canvas.setSize(512, 512);
@@ -119,14 +130,16 @@ public class Multisample {
canvas.requestFocus();
frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
+ @Override
+ public void windowClosing(WindowEvent e) {
runExit();
}
});
}
class Listener implements GLEventListener {
- public void init(GLAutoDrawable drawable) {
+ @Override
+ public void init(GLAutoDrawable drawable) {
System.err.println("Info: "+drawable);
GL2 gl = drawable.getGL().getGL2();
@@ -141,10 +154,12 @@ public class Multisample {
gl.glOrtho(-1, 1, -1, 1, -1, 1);
}
- public void dispose(GLAutoDrawable drawable) {
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+ public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
@@ -166,7 +181,8 @@ public class Multisample {
}
// Unused routines
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
}
@@ -177,7 +193,8 @@ public class Multisample {
// routines cause a global AWT lock to be grabbed. Instead run
// the exit routine in another thread.
new Thread(new Runnable() {
- public void run() {
+ @Override
+ public void run() {
System.exit(0);
}
}).start();
diff --git a/src/demos/proceduralTexturePhysics/Water.java b/src/demos/proceduralTexturePhysics/Water.java
index 94ed0ce..dfb72de 100644
--- a/src/demos/proceduralTexturePhysics/Water.java
+++ b/src/demos/proceduralTexturePhysics/Water.java
@@ -33,29 +33,32 @@
package demos.proceduralTexturePhysics;
-import com.jogamp.common.util.IOUtil;
-import com.jogamp.opengl.util.texture.Texture;
-import com.jogamp.opengl.util.texture.TextureData;
-import com.jogamp.opengl.util.texture.TextureIO;
-import demos.util.Cubemap;
import gleem.linalg.Mat4f;
import gleem.linalg.Rotf;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import javax.media.opengl.GLProfile;
+
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
-import javax.media.opengl.GLCapabilitiesImmutable;
import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLException;
-import javax.media.opengl.GLPbuffer;
+import javax.media.opengl.GLOffscreenAutoDrawable;
+import javax.media.opengl.GLProfile;
import javax.media.opengl.glu.GLU;
+import com.jogamp.common.util.IOUtil;
+import com.jogamp.opengl.util.texture.Texture;
+import com.jogamp.opengl.util.texture.TextureData;
+import com.jogamp.opengl.util.texture.TextureIO;
+
+import demos.util.Cubemap;
+
/**
@@ -75,7 +78,7 @@ public class Water {
// used to render the water geometry (with the parent drawable's GL
// object).
- private GLU glu = new GLU();
+ private final GLU glu = new GLU();
// Rendering modes
public static final int CA_FULLSCREEN_REFLECT = 0;
@@ -85,7 +88,7 @@ public class Water {
public static final int CA_TILED_THREE_WINDOWS = 4;
public static final int CA_DO_NOT_RENDER = 5;
- private int[] initialMapDimensions = new int[2];
+ private final int[] initialMapDimensions = new int[2];
private TextureData initialMapData;
private String tmpSpinFilename;
@@ -93,8 +96,8 @@ public class Water {
private String tmpCubeMapFilenamePrefix;
private String tmpCubeMapFilenameSuffix;
- private GLPbuffer pbuffer;
- private Rotf cameraOrientation = new Rotf();
+ private GLOffscreenAutoDrawable pbuffer;
+ private final Rotf cameraOrientation = new Rotf();
// Dynamic texture names
private static final int CA_TEXTURE_FORCE_INTERMEDIATE = 0;
@@ -105,7 +108,7 @@ public class Water {
private static final int CA_TEXTURE_HEIGHT_TARGET = 5;
private static final int CA_TEXTURE_NORMAL_MAP = 6;
private static final int CA_NUM_DYNAMIC_TEXTURES = 7;
-
+
// List names
private static final int CA_FRAGMENT_PROGRAM_EQ_WEIGHT_COMBINE = 0;
private static final int CA_FRAGMENT_PROGRAM_NEIGHBOR_FORCE_CALC_1 = 1;
@@ -123,8 +126,8 @@ public class Water {
private Texture dropletTex;
private Texture cubemap;
- private Texture[] dynamicTextures = new Texture[CA_NUM_DYNAMIC_TEXTURES];
-
+ private final Texture[] dynamicTextures = new Texture[CA_NUM_DYNAMIC_TEXTURES];
+
private int texHeightInput; // current input height texture ID.
private int texHeightOutput; // current output height texture ID.
private int texVelocityInput; // current input velocity texture ID.
@@ -132,13 +135,13 @@ public class Water {
private int texForceStepOne; // intermediate force computation result texture ID.
private int texForceOutput; // current output force texture ID.
- private int[] displayListIDs = new int[CA_NUM_LISTS];
-
+ private final int[] displayListIDs = new int[CA_NUM_LISTS];
+
private int vertexProgramID; // one vertex program is used to choose the texcoord offset
private int flipState; // used to flip target texture configurations.
- private boolean wrap; // CA can either wrap its borders, or clamp (clamp by default)
+ private boolean wrap; // CA can either wrap its borders, or clamp (clamp by default)
private boolean reset = true; // are we resetting this frame? (user hit reset).
private boolean singleStep; // animation step on keypress.
private boolean animate = true; // continuous animation.
@@ -146,7 +149,7 @@ public class Water {
private boolean wireframe; // render in wireframe mode
private boolean applyInteriorBoundaries = true; // enable / disable "boundary" image drawing.
private boolean spinLogo = true; // draw spinning logo.
- private boolean createNormalMap = true; // enable / disable normal map creation.
+ private final boolean createNormalMap = true; // enable / disable normal map creation.
private float perTexelWidth; // width of a texel (percentage of texture)
private float perTexelHeight; // height of a texel
@@ -154,20 +157,20 @@ public class Water {
private float blurDist = 0.5f; // distance over which to blur.
private boolean mustUpdateBlurOffsets; // flag indicating blurDist was set last tick
- private float normalSTScale = 0.8f; // scale of normals in normal map.
+ private final float normalSTScale = 0.8f; // scale of normals in normal map.
private float bumpScale = 0.25f; // scale of bumps in water.
private float dropletFrequency = 0.175f; // frequency at which droplets are drawn in water...
- private int slowDelay = 1; // amount (milliseconds) to delay when running slow.
+ private final int slowDelay = 1; // amount (milliseconds) to delay when running slow.
private int skipInterval; // frames to skip simulation.
private int skipCount; // frame count for skipping rendering
private int angle; // angle in degrees for spinning logo
- private List/*<Droplet>*/ droplets = new ArrayList/*<Droplet>*/(); // array of droplets
+ private final List/*<Droplet>*/ droplets = new ArrayList/*<Droplet>*/(); // array of droplets
- private int renderMode;
+ private int renderMode;
// Constant memory locations
private static final int CV_UV_OFFSET_TO_USE = 0;
@@ -205,24 +208,22 @@ public class Water {
String cubeMapFilenameSuffix,
GLAutoDrawable parentWindow) {
GLCapabilities caps = (GLCapabilities) parentWindow.getChosenGLCapabilities().cloneMutable();
+ caps.setPBuffer(true);
loadInitialTexture(caps.getGLProfile(), initialMapFilename);
tmpSpinFilename = spinFilename;
tmpDropletFilename = dropletFilename;
tmpCubeMapFilenamePrefix = cubeMapFilenamePrefix;
tmpCubeMapFilenameSuffix = cubeMapFilenameSuffix;
-
+
// create the pbuffer. Will use this as an offscreen rendering buffer.
// it allows rendering a texture larger than our window.
caps.setDoubleBuffered(false);
if (!GLDrawableFactory.getFactory(caps.getGLProfile()).canCreateGLPbuffer(null, caps.getGLProfile())) {
throw new GLException("Pbuffers not supported with this graphics card");
}
- pbuffer = GLDrawableFactory.getFactory(caps.getGLProfile()).createGLPbuffer(
- null, caps, null,
- initialMapDimensions[0],
- initialMapDimensions[1],
- parentWindow.getContext());
+ pbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createOffscreenAutoDrawable(null, caps, null, initialMapDimensions[0], initialMapDimensions[1]);
+ pbuffer.setSharedContext(parentWindow.getContext());
pbuffer.addGLEventListener(new Listener());
}
@@ -234,7 +235,7 @@ public class Water {
reset = true;
}
- public void tick() {
+ public void tick() {
pbuffer.display();
}
@@ -246,12 +247,12 @@ public class Water {
// Display the results of the rendering to texture
if (wireframe) {
gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE);
-
+
// chances are the texture will be all dark, so lets not use a texture
gl.glDisable(GL2.GL_TEXTURE_2D);
} else {
gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL);
-
+
gl.glActiveTexture(GL2.GL_TEXTURE0);
gl.glEnable(GL2.GL_TEXTURE_2D);
}
@@ -280,36 +281,36 @@ public class Water {
gl.glColor4f(1, 1, 1, 1);
gl.glBegin(GL2.GL_QUADS);
-
+
gl.glMultiTexCoord2f(GL2.GL_TEXTURE0, 0,0);
gl.glMultiTexCoord4f(GL2.GL_TEXTURE1, matRot.get(0,0), matRot.get(0,1), matRot.get(0,2), 1);
gl.glMultiTexCoord4f(GL2.GL_TEXTURE2, matRot.get(1,0), matRot.get(1,1), matRot.get(1,2), 1);
gl.glMultiTexCoord4f(GL2.GL_TEXTURE3, matRot.get(2,0), matRot.get(2,1), matRot.get(2,2), 1);
gl.glVertex2f(-1,-1);
-
+
gl.glMultiTexCoord2f(GL2.GL_TEXTURE0, 1,0);
gl.glMultiTexCoord4f(GL2.GL_TEXTURE1, matRot.get(0,0), matRot.get(0,1), matRot.get(0,2), -1);
gl.glMultiTexCoord4f(GL2.GL_TEXTURE2, matRot.get(1,0), matRot.get(1,1), matRot.get(1,2), 1);
gl.glMultiTexCoord4f(GL2.GL_TEXTURE3, matRot.get(2,0), matRot.get(2,1), matRot.get(2,2), 1);
gl.glVertex2f( 1,-1);
-
+
gl.glMultiTexCoord2f(GL2.GL_TEXTURE0, 1,1);
gl.glMultiTexCoord4f(GL2.GL_TEXTURE1, matRot.get(0,0), matRot.get(0,1), matRot.get(0,2), -1);
gl.glMultiTexCoord4f(GL2.GL_TEXTURE2, matRot.get(1,0), matRot.get(1,1), matRot.get(1,2), -1);
gl.glMultiTexCoord4f(GL2.GL_TEXTURE3, matRot.get(2,0), matRot.get(2,1), matRot.get(2,2), 1);
gl.glVertex2f( 1, 1);
-
+
gl.glMultiTexCoord2f(GL2.GL_TEXTURE0, 0,1);
gl.glMultiTexCoord4f(GL2.GL_TEXTURE1, matRot.get(0,0), matRot.get(0,1), matRot.get(0,2), 1);
gl.glMultiTexCoord4f(GL2.GL_TEXTURE2, matRot.get(1,0), matRot.get(1,1), matRot.get(1,2), -1);
gl.glMultiTexCoord4f(GL2.GL_TEXTURE3, matRot.get(2,0), matRot.get(2,1), matRot.get(2,2), 1);
gl.glVertex2f(-1, 1);
-
+
gl.glEnd();
-
+
cubemap.disable(gl);
gl.glDisable(GL2.GL_FRAGMENT_PROGRAM_ARB);
-
+
break;
}
@@ -317,7 +318,7 @@ public class Water {
// Draw quad over full display
gl.glActiveTexture(GL2.GL_TEXTURE0);
dynamicTextures[CA_TEXTURE_NORMAL_MAP].bind(gl);
-
+
gl.glCallList(displayListIDs[CA_DRAW_SCREEN_QUAD]);
break;
}
@@ -326,7 +327,7 @@ public class Water {
// Draw quad over full display
gl.glActiveTexture(GL2.GL_TEXTURE0);
gl.glBindTexture(GL2.GL_TEXTURE_2D, texHeightOutput);
-
+
gl.glCallList(displayListIDs[CA_DRAW_SCREEN_QUAD]);
break;
}
@@ -335,7 +336,7 @@ public class Water {
// Draw quad over full display
gl.glActiveTexture(GL2.GL_TEXTURE0);
dynamicTextures[CA_TEXTURE_FORCE_TARGET].bind(gl);
-
+
gl.glCallList(displayListIDs[CA_DRAW_SCREEN_QUAD]);
break;
}
@@ -347,7 +348,7 @@ public class Water {
dynamicTextures[CA_TEXTURE_FORCE_TARGET].bind(gl);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glPushMatrix();
-
+
gl.glTranslatef(-0.5f, -0.5f, 0);
gl.glScalef(0.5f, 0.5f, 1);
gl.glCallList(displayListIDs[CA_DRAW_SCREEN_QUAD]);
@@ -356,7 +357,7 @@ public class Water {
// lower right
gl.glBindTexture(GL2.GL_TEXTURE_2D, texVelocityOutput);
gl.glPushMatrix();
-
+
gl.glTranslatef(0.5f, -0.5f, 0);
gl.glScalef(0.5f, 0.5f, 1);
gl.glCallList(displayListIDs[CA_DRAW_SCREEN_QUAD]);
@@ -366,7 +367,7 @@ public class Water {
dynamicTextures[CA_TEXTURE_NORMAL_MAP].bind(gl);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glPushMatrix();
-
+
gl.glTranslatef(-0.5f, 0.5f, 0);
gl.glScalef(0.5f, 0.5f, 1);
gl.glCallList(displayListIDs[CA_DRAW_SCREEN_QUAD]);
@@ -376,12 +377,12 @@ public class Water {
gl.glBindTexture(GL2.GL_TEXTURE_2D, texHeightOutput);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glPushMatrix();
-
+
gl.glTranslatef(0.5f, 0.5f, 0);
gl.glScalef(0.5f, 0.5f, 1);
gl.glCallList(displayListIDs[CA_DRAW_SCREEN_QUAD]);
gl.glPopMatrix();
-
+
break;
}
}
@@ -396,10 +397,10 @@ public class Water {
public void enableSlowAnimation(boolean enable) { slow = enable; }
public void reset() { reset = true; }
public void setRenderMode(int mode) { renderMode = mode; }
-
+
public void enableWireframe(boolean enable) { wireframe = enable; }
public void enableBorderWrapping(boolean enable) { wrap = enable; }
-
+
public void enableBoundaryApplication(boolean enable) { applyInteriorBoundaries = enable; }
public void enableSpinningLogo(boolean enable) { spinLogo = enable; }
@@ -414,23 +415,23 @@ public class Water {
public float getDropFrequency() { return dropletFrequency; }
public static class Droplet {
- private float rX;
- private float rY;
- private float rScale;
+ private final float rX;
+ private final float rY;
+ private final float rScale;
Droplet(float rX, float rY, float rScale) {
this.rX = rX;
this.rY = rY;
this.rScale = rScale;
}
-
+
float rX() { return rX; }
float rY() { return rY; }
float rScale() { return rScale; }
}
public synchronized void addDroplet(Droplet drop) {
- droplets.add(drop);
+ droplets.add(drop);
}
//----------------------------------------------------------------------
@@ -439,23 +440,26 @@ public class Water {
class Listener implements GLEventListener {
- public void init(GLAutoDrawable drawable) {
+ @Override
+ public void init(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
initOpenGL(gl);
}
- public void dispose(GLAutoDrawable drawable) {
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+ public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
if (mustUpdateBlurOffsets) {
updateBlurVertOffset(gl);
mustUpdateBlurOffsets = false;
}
-
+
// Take a single step in the cellular automaton
// Disable culling
@@ -473,7 +477,7 @@ public class Water {
doSingleTimeStep(gl);
singleStep = false;
}
-
+
// Force rendering to pbuffer to complete
gl.glFlush();
@@ -485,7 +489,8 @@ public class Water {
}
}
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
// Unused routines
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
@@ -522,11 +527,11 @@ public class Water {
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluOrtho2D(-1, 1, -1, 1);
-
+
gl.glClearColor(0, 0, 0, 0);
gl.glDisable(GL2.GL_LIGHTING);
gl.glDisable(GL2.GL_DEPTH_TEST);
-
+
createAndWriteUVOffsets(gl, initialMapDimensions[0], initialMapDimensions[1]);
checkExtension(gl, "GL_ARB_vertex_program");
@@ -542,7 +547,7 @@ public class Water {
vertexProgramID = tmpInt[0];
gl.glBindProgramARB(GL2.GL_VERTEX_PROGRAM_ARB, vertexProgramID);
- String programBuffer =
+ String programBuffer =
"!!ARBvp1.0\n" +
"# Constant memory location declarations (must match those in Java sources)\n" +
"# CV_UV_OFFSET_TO_USE = 0\n" +
@@ -711,8 +716,8 @@ public class Water {
// use CopyTexSubImage for speed (even though we copy all of it) since we pre-allocated the texture
gl.glCopyTexSubImage2D(GL2.GL_TEXTURE_2D, 0, 0, 0, 0, 0, initialMapDimensions[0], initialMapDimensions[1]);
- break;
-
+ break;
+
case 1:
temp = texHeightInput;
texHeightInput = texHeightOutput;
@@ -734,10 +739,10 @@ public class Water {
texVelocityOutput = temp;
break;
}
-
+
// even if wireframe mode, render to texture as solid
gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL);
-
+
/////////////////////////////////////////////////////////////
// Render first 3 components of force from three neighbors
// Offsets selected are 1 center texel for center height
@@ -776,18 +781,18 @@ public class Water {
// Now we need to copy the resulting pixels into the intermediate force field texture
gl.glActiveTexture(GL2.GL_TEXTURE2);
- dynamicTextures[CA_TEXTURE_FORCE_INTERMEDIATE].bind(gl);
+ dynamicTextures[CA_TEXTURE_FORCE_INTERMEDIATE].bind(gl);
// use CopyTexSubImage for speed (even though we copy all of it) since we pre-allocated the texture
gl.glCopyTexSubImage2D(GL2.GL_TEXTURE_2D, 0, 0, 0, 0, 0, initialMapDimensions[0], initialMapDimensions[1]);
////////////////////////////////////////////////////////////////
// Now add in last component of force for the 4th neighbor
- // that we didn't have enough texture lookups to do in the
+ // that we didn't have enough texture lookups to do in the
// first pass
gl.glCallList(displayListIDs[CA_FRAGMENT_PROGRAM_NEIGHBOR_FORCE_CALC_2]);
-
+
// Cannot use additive blending as the force contribution might
// be negative and would have to subtract from the dest.
// We must instead use an additional texture as target and read
@@ -826,7 +831,7 @@ public class Water {
/////////////////////////////////////////////////////////////////
// Apply the force with a scale factor to reduce it's magnitude.
// Add this to the current texture representing the water height.
-
+
gl.glCallList(displayListIDs[CA_FRAGMENT_PROGRAM_APPLY_FORCE]);
// use offsets of zero
@@ -837,7 +842,7 @@ public class Water {
gl.glActiveTexture(GL2.GL_TEXTURE0);
gl.glBindTexture(GL2.GL_TEXTURE_2D, texVelocityInput);
gl.glActiveTexture(GL2.GL_TEXTURE1);
- dynamicTextures[CA_TEXTURE_FORCE_TARGET].bind(gl);
+ dynamicTextures[CA_TEXTURE_FORCE_TARGET].bind(gl);
gl.glActiveTexture(GL2.GL_TEXTURE2);
gl.glDisable(GL2.GL_TEXTURE_2D);
gl.glActiveTexture(GL2.GL_TEXTURE3);
@@ -896,7 +901,7 @@ public class Water {
// Now we need to copy the resulting pixels into the input height texture
gl.glActiveTexture(GL2.GL_TEXTURE0);
gl.glBindTexture(GL2.GL_TEXTURE_2D, texHeightInput);
-
+
// use CopyTexSubImage for speed (even though we copy all of it) since we pre-allocated the texture
gl.glCopyTexSubImage2D(GL2.GL_TEXTURE_2D, 0, 0, 0, 0, 0, initialMapDimensions[0], initialMapDimensions[1]);
@@ -904,7 +909,7 @@ public class Water {
// blur positions to smooth noise & generaly dampen things
// degree of blur is controlled by magnitude of 4 neighbor texel
// offsets with bilinear on
-
+
for (int i = 1; i < 4; i++) {
gl.glActiveTexture(GL2.GL_TEXTURE0 + i);
gl.glBindTexture(GL2.GL_TEXTURE_2D, texHeightInput);
@@ -931,14 +936,14 @@ public class Water {
// use CopyTexSubImage for speed (even though we copy all of it) since we pre-allocated the texture
gl.glCopyTexSubImage2D(GL2.GL_TEXTURE_2D, 0, 0, 0, 0, 0, initialMapDimensions[0], initialMapDimensions[1]);
-
+
///////////////////////////////////////////////////////////////////
// If selected, create a normal map from the height
-
+
if (createNormalMap) {
createNormalMap(gl);
}
-
+
///////////////////////////////////////////////////////////
// Flip the state variable for the next round of rendering
switch (flipState) {
@@ -978,7 +983,7 @@ public class Water {
// set vp offsets to nearest neighbors
gl.glProgramEnvParameter4fARB(GL2.GL_VERTEX_PROGRAM_ARB, CV_UV_OFFSET_TO_USE, 4, 0, 0, 0);
gl.glEnable(GL2.GL_VERTEX_PROGRAM_ARB);
-
+
gl.glCallList(displayListIDs[CA_DRAW_SCREEN_QUAD]);
gl.glDisable(GL2.GL_FRAGMENT_PROGRAM_ARB);
@@ -986,13 +991,13 @@ public class Water {
// Now we need to copy the resulting pixels into the normal map
gl.glActiveTexture(GL2.GL_TEXTURE0);
dynamicTextures[CA_TEXTURE_NORMAL_MAP].bind(gl);
-
+
// use CopyTexSubImage for speed (even though we copy all of it) since we pre-allocated the texture
gl.glCopyTexSubImage2D(GL2.GL_TEXTURE_2D, 0, 0, 0, 0, 0, initialMapDimensions[0], initialMapDimensions[1]);
}
private void drawInteriorBoundaryObjects(GL2 gl) {
-
+
gl.glActiveTexture(GL2.GL_TEXTURE0);
initialMapTex.bind(gl);
initialMapTex.enable(gl);
@@ -1004,7 +1009,7 @@ public class Water {
gl.glActiveTexture(GL2.GL_TEXTURE0 + i);
gl.glDisable(GL2.GL_TEXTURE_2D);
}
-
+
gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL2.GL_BLEND);
@@ -1057,17 +1062,17 @@ public class Water {
texHeightInput = initialMapTex.getTextureObject(gl); // initial height map.
texHeightOutput = dynamicTextures[CA_TEXTURE_HEIGHT_TARGET].getTextureObject(gl); // next height map.
-
+
texVelocityInput = dynamicTextures[CA_TEXTURE_VELOCITY_SOURCE].getTextureObject(gl); // initial velocity.
texVelocityOutput = dynamicTextures[CA_TEXTURE_VELOCITY_TARGET].getTextureObject(gl); // next velocity.
}
private void createAndWriteUVOffsets(GL2 gl, int width, int height) {
// This sets vertex shader constants used to displace the
- // source texture over several additive samples. This is
+ // source texture over several additive samples. This is
// used to accumulate neighboring texel information that we
- // need to run the game - the 8 surrounding texels, and the
- // single source texel which will either spawn or die in the
+ // need to run the game - the 8 surrounding texels, and the
+ // single source texel which will either spawn or die in the
// next generation.
// Label the texels as follows, for a source texel "e" that
// we want to compute for the next generation:
@@ -1078,9 +1083,9 @@ public class Water {
// first the easy one: no offsets for sampling center
// occupied or unoccupied
- // Use index offset value 0.0 to access these in the
+ // Use index offset value 0.0 to access these in the
// vertex shader.
-
+
perTexelWidth = 1.0f / width;
perTexelHeight = 1.0f / height;
@@ -1096,7 +1101,7 @@ public class Water {
float[] type1OffsetY = new float[] { 0.0f, dist * perTexelHeight, dist * perTexelHeight, -dist * perTexelHeight };
// Offset set 2: for use with neighbor force pixel shader 2
- // samples center with 0, and -v texels
+ // samples center with 0, and -v texels
// ie the 'e' and 'b' texels
// This completes a pattern of sampling center texel and it's
// 4 nearest neighbors to run the height-based water simulation
@@ -1105,7 +1110,7 @@ public class Water {
float[] type2OffsetX = new float[] { 0.0f, -dist * perTexelWidth, 0.0f, 0.0f };
float[] type2OffsetY = new float[] { 0.0f, -dist * perTexelHeight, 0.0f, 0.0f };
-
+
// type 3 offsets
updateBlurVertOffset(gl);
@@ -1130,15 +1135,15 @@ public class Water {
}
private void updateBlurVertOffset(GL2 gl) {
- float[] type3OffsetX = new float[] { -perTexelWidth * 0.5f,
- perTexelWidth,
- perTexelWidth * 0.5f,
- -perTexelWidth
+ float[] type3OffsetX = new float[] { -perTexelWidth * 0.5f,
+ perTexelWidth,
+ perTexelWidth * 0.5f,
+ -perTexelWidth
};
float[] type3OffsetY = new float[] { perTexelHeight,
perTexelHeight * 0.5f,
-perTexelHeight,
- -perTexelHeight * 0.5f
+ -perTexelHeight * 0.5f
};
float[] offsets = new float[] { 0, 0, 0, 0 };
@@ -1173,11 +1178,11 @@ public class Water {
// The quad is textured with the initial droplet texture, and
// covers some small portion of the render target
// Draw the droplet
-
+
gl.glTexCoord2f(0, 0); gl.glVertex2f(droplet.rX() - droplet.rScale(), droplet.rY() - droplet.rScale());
gl.glTexCoord2f(1, 0); gl.glVertex2f(droplet.rX() + droplet.rScale(), droplet.rY() - droplet.rScale());
gl.glTexCoord2f(1, 1); gl.glVertex2f(droplet.rX() + droplet.rScale(), droplet.rY() + droplet.rScale());
- gl.glTexCoord2f(0, 1); gl.glVertex2f(droplet.rX() - droplet.rScale(), droplet.rY() + droplet.rScale());
+ gl.glTexCoord2f(0, 1); gl.glVertex2f(droplet.rX() - droplet.rScale(), droplet.rY() + droplet.rScale());
}
gl.glEnd();
@@ -1268,7 +1273,7 @@ public class Water {
//
// This step takes the center point and three neighboring points, and computes
// the texel difference as the "force" acting to pull the center texel.
- //
+ //
// The amount to which the computed force is applied to the texel is controlled
// in a separate shader.
@@ -1287,7 +1292,7 @@ public class Water {
// //s0 = t1 - t0;
// discard = -tex0;
// discard = tex1;
- // spare0 = sum();
+ // spare0 = sum();
// }
// Stage 1
// rgb
@@ -1295,16 +1300,16 @@ public class Water {
// //s1 = t2 - t0;
// discard = -tex0;
// discard = tex2;
- // spare1 = sum();
+ // spare1 = sum();
// }
// Stage 2
// // 'force' for 1st axis
- // rgb
+ // rgb
// {
// //s0 = s0 + s1 = t1 - t0 + t2 - t0;
// discard = spare0;
// discard = spare1;
- // spare0 = sum();
+ // spare0 = sum();
// }
// Stage 3
// // one more point for 2nd axis
@@ -1313,7 +1318,7 @@ public class Water {
// //s1 = t3 - t0;
// discard = -tex0;
// discard = tex3;
- // spare1 = sum();
+ // spare1 = sum();
// }
// Stage 4
// rgb
@@ -1321,20 +1326,20 @@ public class Water {
// //s0 = s0 + s1 = t3 - t0 + t2 - t0 + t1 - t0;
// discard = spare0;
// discard = spare1;
- // spare0 = sum();
+ // spare0 = sum();
// }
// Stage 5
- // // Now add in a force to gently pull the center texel's
+ // // Now add in a force to gently pull the center texel's
// // value to 0.5. The strength of this is controlled by
// // the PCN_EQ_REST_FAC - restoration factor
// // Without this, the simulation will fade to zero or fly
// // away to saturate at 1.0
- // rgb
+ // rgb
// {
- // //s1 = 0.5 - t0;
+ // //s1 = 0.5 - t0;
// discard = -tex0;
// discard = const0;
- // spare1 = sum();
+ // spare1 = sum();
// }
// Stage 6
// {
@@ -1410,10 +1415,10 @@ public class Water {
// 2nd step of force calc for render-to-texture
// water simulation.
//
- // Adds the 4th & final neighbor point to the
+ // Adds the 4th & final neighbor point to the
// force calc..
//
- // Bias and scale the values so 0 force is 0.5,
+ // Bias and scale the values so 0 force is 0.5,
// full negative force is 0.0, and full pos is
// 1.0
//
@@ -1475,14 +1480,14 @@ public class Water {
//
// This is used to apply a "force" texture value to a "velocity" state texture
// for nearest-neighbor height-based water simulations. The output pixel is
- // the new "velocity" value to replace the t0 sample in rendering to a new
+ // the new "velocity" value to replace the t0 sample in rendering to a new
// texture which will replace the texture selected into t0.
//
// A nearly identical shader using a different scaling constant is used to
// apply the "velocity" value to a "height" texture at each texel.
//
// t1 comes in the range [0,1] but needs to hold signed values, so a value of
- // 0.5 in t1 represents zero force. This is biased to a signed value in
+ // 0.5 in t1 represents zero force. This is biased to a signed value in
// computing the new velocity.
//
// tex0 = previous velocity
@@ -1554,18 +1559,18 @@ public class Water {
//
// This is used to apply a "velocity" texture value to a "height" state texture
// for nearest-neighbor height-based water simulations. The output pixel is
- // the new "height" value to replace the t0 sample in rendering to a new
+ // the new "height" value to replace the t0 sample in rendering to a new
// texture which will replace the texture selected into t0.
//
// A nearly identical shader using a different scaling constant is used to
// apply the "force" value to the "velocity" texture at each texel.
//
// t1 comes in the range [0,1] but needs to hold signed values, so a value of
- // 0.5 in t1 represents zero velocity. This is biased to a signed value in
- // computing the new position.
+ // 0.5 in t1 represents zero velocity. This is biased to a signed value in
+ // computing the new position.
//
// tex0 = height field
- // tex1 = velocity
+ // tex1 = velocity
//
// Bias the force/velocity to a signed value so we can subtract from
// the t0 position sample.
@@ -1700,7 +1705,7 @@ public class Water {
// }
// Stage 6
// const0 = (0, 0, 1, 1);
- // rgb
+ // rgb
// {
// discard = spare1 * const0;
// discard = spare0;
diff --git a/src/demos/testContextSharing/TestContextSharing.java b/src/demos/testContextSharing/TestContextSharing.java
index c2b8721..55df5e7 100644
--- a/src/demos/testContextSharing/TestContextSharing.java
+++ b/src/demos/testContextSharing/TestContextSharing.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2003 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
@@ -28,11 +28,11 @@
* 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.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
@@ -41,6 +41,7 @@ package demos.testContextSharing;
import java.awt.BorderLayout;
import java.awt.Frame;
+
import javax.media.opengl.DebugGL2;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
@@ -69,7 +70,8 @@ public class TestContextSharing {
frame1.pack();
frame1.setVisible(true);
- GLCanvas canvas2 = new GLCanvas(null, null, canvas1.getContext(), null);
+ GLCanvas canvas2 = new GLCanvas(null, null, null);
+ canvas2.setSharedContext(canvas1.getContext());
canvas2.addGLEventListener(new Listener());
canvas2.setSize(256, 256);
Frame frame2 = new Frame("Canvas 2");
@@ -88,7 +90,8 @@ public class TestContextSharing {
class Listener implements GLEventListener {
- public void init(GLAutoDrawable drawable) {
+ @Override
+ public void init(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
@@ -106,10 +109,12 @@ public class TestContextSharing {
gl.glEnable(GL2.GL_NORMALIZE);
}
- public void dispose(GLAutoDrawable drawable) {
+ @Override
+ public void dispose(GLAutoDrawable drawable) {
}
- public void display(GLAutoDrawable drawable) {
+ @Override
+ public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
@@ -118,11 +123,12 @@ public class TestContextSharing {
gl.glCallList(gearDisplayList);
}
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+ @Override
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
GL2 gl = drawable.getGL().getGL2();
float h = (float)height / (float)width;
-
+
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
@@ -164,9 +170,9 @@ public class TestContextSharing {
r0 = inner_radius;
r1 = outer_radius - tooth_depth / 2.0f;
r2 = outer_radius + tooth_depth / 2.0f;
-
+
da = 2.0f * (float) Math.PI / teeth / 4.0f;
-
+
gl.glShadeModel(GL2.GL_FLAT);
gl.glNormal3f(0.0f, 0.0f, 1.0f);
@@ -197,7 +203,7 @@ public class TestContextSharing {
gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f);
}
gl.glEnd();
-
+
/* draw back face */
gl.glBegin(GL2.GL_QUAD_STRIP);
for (i = 0; i <= teeth; i++)
@@ -209,7 +215,7 @@ public class TestContextSharing {
gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f);
}
gl.glEnd();
-
+
/* draw back sides of teeth */
gl.glBegin(GL2.GL_QUADS);
for (i = 0; i < teeth; i++)
@@ -221,7 +227,7 @@ public class TestContextSharing {
gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f);
}
gl.glEnd();
-
+
/* draw outward faces of teeth */
gl.glBegin(GL2.GL_QUAD_STRIP);
for (i = 0; i < teeth; i++)
@@ -250,9 +256,9 @@ public class TestContextSharing {
gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), width * 0.5f);
gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), -width * 0.5f);
gl.glEnd();
-
+
gl.glShadeModel(GL2.GL_SMOOTH);
-
+
/* draw inside radius cylinder */
gl.glBegin(GL2.GL_QUAD_STRIP);
for (i = 0; i <= teeth; i++)
diff --git a/src/demos/texture/TextureConvert.java b/src/demos/texture/TextureConvert.java
index 6287acb..a507bce 100755
--- a/src/demos/texture/TextureConvert.java
+++ b/src/demos/texture/TextureConvert.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2005 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
@@ -28,29 +28,31 @@
* 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.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
package demos.texture;
-import com.jogamp.common.util.IOUtil;
-import com.jogamp.opengl.util.texture.Texture;
-import com.jogamp.opengl.util.texture.TextureData;
-import com.jogamp.opengl.util.texture.TextureIO;
import java.io.File;
import java.io.IOException;
+
import javax.media.opengl.GL;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLDrawableFactory;
-import javax.media.opengl.GLPbuffer;
+import javax.media.opengl.GLOffscreenAutoDrawable;
import javax.media.opengl.GLProfile;
+import com.jogamp.common.util.IOUtil;
+import com.jogamp.opengl.util.texture.Texture;
+import com.jogamp.opengl.util.texture.TextureData;
+import com.jogamp.opengl.util.texture.TextureIO;
+
/** Demonstrates how the TextureIO subsystem may be used to convert
@@ -79,7 +81,8 @@ public class TextureConvert {
System.out.println("Pbuffer support not available (required to run this demo)");
System.exit(1);
}
- GLPbuffer pbuffer = GLDrawableFactory.getFactory(glp).createGLPbuffer(null, caps, null, 2, 2, null);
+ GLOffscreenAutoDrawable pbuffer = GLDrawableFactory.getFactory(glp).createOffscreenAutoDrawable(null, caps, null, 2, 2);
+ pbuffer.display(); // force init
pbuffer.getContext().makeCurrent();
GL gl = pbuffer.getGL();