diff options
28 files changed, 1696 insertions, 527 deletions
diff --git a/make/build.xml b/make/build.xml index 2f330f0..95afeee 100644 --- a/make/build.xml +++ b/make/build.xml @@ -31,15 +31,7 @@ </fail> </target> - <target name="setup.cg.excludes" unless="jogl.cg"> - <property name="jogl.cg.excludes" value="demos/cg/**,demos/hdr/**" /> - </target> - - <target name="skip.cg.excludes" if="jogl.cg"> - <property name="jogl.cg.excludes" value="" /> - </target> - - <target name="init" depends="java.class.path.validate,setup.cg.excludes,skip.cg.excludes"> + <target name="init" depends="java.class.path.validate"> <property name="jogl.jar" value="../../jogl/build/jogl.jar" /> <property name="classes" value="../build/classes" /> <property name="src" value="../src" /> @@ -58,7 +50,7 @@ <pathelement path="${classpath}" /> <pathelement location="${jogl.jar}" /> </path> - <javac destdir="${classes}" excludes="${jogl.cg.excludes}" source="1.4" debug="true" debuglevel="source,lines"> + <javac destdir="${classes}" excludes="demos/cg/**" source="1.4" debug="true" debuglevel="source,lines"> <src path="${src}" /> <classpath refid="jogl.classpath" /> </javac> @@ -67,14 +59,6 @@ <exclude name="gleem/**" /> <exclude name="demos/util/**" /> </fileset> - <fileset dir="${src}"> - <include name="demos/cg/**/*.cg" /> - </fileset> - <fileset dir="${src}"> - <include name="demos/hdr/shaders/**/*.cg" /> - <include name="demos/hdr/shaders/**/*.arbvp1" /> - <include name="demos/hdr/shaders/**/*.arbfp1" /> - </fileset> </jar> <jar destfile="${jogl.demos.util.jar}"> <fileset dir="${classes}"> diff --git a/src/demos/cg/runtime_ogl/cgGL_vertex_example.java b/src/demos/cg/runtime_ogl/cgGL_vertex_example.java index f1f41dd..ec2cb9a 100644 --- a/src/demos/cg/runtime_ogl/cgGL_vertex_example.java +++ b/src/demos/cg/runtime_ogl/cgGL_vertex_example.java @@ -31,14 +31,11 @@ * */ -package demos.cg.runtime_ogl; - import net.java.games.cg.*; import net.java.games.jogl.*; import java.awt.*; import java.awt.event.*; -import java.io.*; /** * cgGL_vertex_example: simple demo of Nvidia CgGL API. Based upon C version @@ -190,14 +187,9 @@ public class cgGL_vertex_example implements GLEventListener CheckCgError(); /* Test adding source text to context */ - try { - Program = CgGL.cgCreateProgramFromStream( - Context, CgGL.CG_SOURCE, - getClass().getClassLoader().getResourceAsStream("demos/cg/runtime_ogl/cgGL_vertex_example.cg"), - profile, null, null); - } catch (IOException e) { - throw new RuntimeException("Error loading Cg vertex program", e); - } + Program = CgGL.cgCreateProgramFromFile( + Context, CgGL.CG_SOURCE, "cgGL_vertex_example.cg", + profile, null, null); CheckCgError(); System.err.println( diff --git a/src/demos/cg/runtime_ogl_vertex_fragment/runtime_ogl_vertex_fragment.java b/src/demos/cg/runtime_ogl_vertex_fragment/runtime_ogl_vertex_fragment.java index 0c389e1..3ceabc0 100644 --- a/src/demos/cg/runtime_ogl_vertex_fragment/runtime_ogl_vertex_fragment.java +++ b/src/demos/cg/runtime_ogl_vertex_fragment/runtime_ogl_vertex_fragment.java @@ -31,8 +31,6 @@ * */ -package demos.cg.runtime_ogl_vertex_fragment; - import net.java.games.cg.*; import net.java.games.jogl.*; import net.java.games.jogl.util.*; @@ -69,6 +67,9 @@ public class runtime_ogl_vertex_fragment implements GLEventListener GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); canvas.addGLEventListener(new runtime_ogl_vertex_fragment()); + // Use debug pipeline + canvas.setGL(new DebugGL(canvas.getGL())); + frame.add(canvas); frame.setSize(512, 512); final Animator animator = new Animator(canvas); @@ -93,9 +94,6 @@ public class runtime_ogl_vertex_fragment implements GLEventListener public void init(GLDrawable drawable) { - // Use debug pipeline - // drawable.setGL(new DebugGL(drawable.getGL())); - GL gl = drawable.getGL(); // Basic Cg setup; register a callback function for any errors @@ -237,13 +235,8 @@ public class runtime_ogl_vertex_fragment implements GLEventListener // Load and compile the vertex program from demo_vert.cg; hold on to the // handle to it that is returned. - try { - vertexProgram = CgGL.cgCreateProgramFromStream(context, CgGL.CG_SOURCE, - getClass().getClassLoader().getResourceAsStream("demos/cg/runtime_ogl_vertex_fragment/demo_vert.cg"), - vertexProfile, null, null); - } catch (IOException e) { - throw new RuntimeException("Error loading Cg vertex program", e); - } + vertexProgram = CgGL.cgCreateProgramFromFile(context, CgGL.CG_SOURCE, "demo_vert.cg", + vertexProfile, null, null); if (!CgGL.cgIsProgramCompiled(vertexProgram)) CgGL.cgCompileProgram(vertexProgram); @@ -252,13 +245,8 @@ public class runtime_ogl_vertex_fragment implements GLEventListener CgGL.cgGLLoadProgram(vertexProgram); // And similarly set things up for the fragment program. - try { - fragmentProgram = CgGL.cgCreateProgramFromStream(context, CgGL.CG_SOURCE, - getClass().getClassLoader().getResourceAsStream("demos/cg/runtime_ogl_vertex_fragment/demo_frag.cg"), - fragmentProfile, null, null); - } catch (IOException e) { - throw new RuntimeException("Error loading Cg fragment program", e); - } + fragmentProgram = CgGL.cgCreateProgramFromFile(context, CgGL.CG_SOURCE, "demo_frag.cg", + fragmentProfile, null, null); if (!CgGL.cgIsProgramCompiled(fragmentProgram)) { CgGL.cgCompileProgram(fragmentProgram); } diff --git a/src/demos/fullscreen/GearsFullscreen.java b/src/demos/fullscreen/GearsFullscreen.java new file mode 100755 index 0000000..d8971fb --- /dev/null +++ b/src/demos/fullscreen/GearsFullscreen.java @@ -0,0 +1,426 @@ +package demos.fullscreen; + +import java.awt.*; +import java.awt.event.*; + +import net.java.games.jogl.*; +import demos.util.*; + +/** + * GearsFullscreen.java <BR> + * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P> + * + * This version is equal to Brian Paul's version 1.2 1999/10/21 <P> + * + * Illustrates simple usage of GLCanvas in full-screen mode. On + * Windows this demo should be run with the system property + * -Dsun.java2d.noddraw=true specified to prevent Java2D from using + * DirectDraw, which is incompatible with OpenGL at the driver level. + */ + +public class GearsFullscreen { + private GraphicsDevice dev; + private DisplayMode origMode; + private boolean fullScreen; + private Frame frame; + private Animator animator; + private int initWidth = 300; + private int initHeight = 300; + + public static void main(String[] args) { + new GearsFullscreen().run(args); + } + + public void run(String[] args) { + dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + origMode = dev.getDisplayMode(); + DisplayMode newMode = null; + + if (dev.isFullScreenSupported()) { + newMode = ScreenResSelector.showSelectionDialog(); + if (newMode != null) { + initWidth = newMode.getWidth(); + initHeight = newMode.getHeight(); + } + } else { + System.err.println("NOTE: full-screen mode not supported; running in window instead"); + } + + frame = new Frame("Gear Demo"); + if (newMode != null) { + frame.setUndecorated(true); + } + GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); + + canvas.addGLEventListener(new GearRenderer()); + frame.add(canvas); + frame.setSize(initWidth, initHeight); + animator = new Animator(canvas); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + runExit(); + } + }); + frame.setVisible(true); + + if (dev.isFullScreenSupported() && (newMode != null)) { + dev.setFullScreenWindow(frame); + if (dev.isDisplayChangeSupported()) { + dev.setDisplayMode(newMode); + fullScreen = true; + } else { + // Not much point in having a full-screen window in this case + dev.setFullScreenWindow(null); + final Frame f2 = frame; + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + f2.setVisible(false); + f2.setUndecorated(false); + f2.setVisible(true); + f2.setSize(initWidth, initHeight); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + System.err.println("NOTE: was not able to change display mode; full-screen disabled"); + } + } + + animator.start(); + } + + class GearRenderer implements GLEventListener, MouseListener, MouseMotionListener { + private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f; + private int gear1, gear2, gear3; + private float angle = 0.0f; + + private int prevMouseX, prevMouseY; + private boolean mouseRButtonDown = false; + + public void init(GLDrawable drawable) { + // Use debug pipeline + // drawable.setGL(new DebugGL(drawable.getGL())); + + GL gl = drawable.getGL(); + + // FIXME: workaround for Windows full-screen bug when + // sun.java2d.noddraw=true and similar bug on Mac OS X + if (fullScreen) { + final GLDrawable tmpDrawable = drawable; + EventQueue.invokeLater(new Runnable() { + public void run() { + frame.setBounds(0, 0, initWidth, initHeight); + tmpDrawable.setSize(initWidth, initHeight); + frame.toFront(); + } + }); + } + + System.err.println("INIT GL IS: " + gl.getClass().getName()); + + gl.setSwapInterval(1); + + float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f }; + float red[] = { 0.8f, 0.1f, 0.0f, 1.0f }; + float green[] = { 0.0f, 0.8f, 0.2f, 1.0f }; + float blue[] = { 0.2f, 0.2f, 1.0f, 1.0f }; + + gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos); + gl.glEnable(GL.GL_CULL_FACE); + gl.glEnable(GL.GL_LIGHTING); + gl.glEnable(GL.GL_LIGHT0); + gl.glEnable(GL.GL_DEPTH_TEST); + + /* make the gears */ + gear1 = gl.glGenLists(1); + gl.glNewList(gear1, GL.GL_COMPILE); + gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, red); + gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f); + gl.glEndList(); + + gear2 = gl.glGenLists(1); + gl.glNewList(gear2, GL.GL_COMPILE); + gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, green); + gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f); + gl.glEndList(); + + gear3 = gl.glGenLists(1); + gl.glNewList(gear3, GL.GL_COMPILE); + gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, blue); + gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f); + gl.glEndList(); + + gl.glEnable(GL.GL_NORMALIZE); + + drawable.addMouseListener(this); + drawable.addMouseMotionListener(this); + + drawable.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + dispatchKey(e.getKeyCode()); + } + }); + } + + public void reshape(GLDrawable drawable, int x, int y, int width, int height) { + GL gl = drawable.getGL(); + + float h = (float)height / (float)width; + + gl.glMatrixMode(GL.GL_PROJECTION); + + System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR)); + System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER)); + System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION)); + System.err.println(); + System.err.println("glLoadTransposeMatrixfARB() supported: " + + gl.isFunctionAvailable("glLoadTransposeMatrixfARB")); + if (!gl.isFunctionAvailable("glLoadTransposeMatrixfARB")) { + // --- not using extensions + gl.glLoadIdentity(); + } else { + // --- using extensions + final float[] identityTranspose = new float[] { + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + }; + gl.glLoadTransposeMatrixfARB(identityTranspose); + } + gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f); + gl.glMatrixMode(GL.GL_MODELVIEW); + gl.glLoadIdentity(); + gl.glTranslatef(0.0f, 0.0f, -40.0f); + } + + public void display(GLDrawable drawable) { + angle += 2.0f; + + GL gl = drawable.getGL(); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + + gl.glPushMatrix(); + gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); + gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); + gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); + + gl.glPushMatrix(); + gl.glTranslatef(-3.0f, -2.0f, 0.0f); + gl.glRotatef(angle, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear1); + gl.glPopMatrix(); + + gl.glPushMatrix(); + gl.glTranslatef(3.1f, -2.0f, 0.0f); + gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear2); + gl.glPopMatrix(); + + gl.glPushMatrix(); + gl.glTranslatef(-3.1f, 4.2f, 0.0f); + gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear3); + gl.glPopMatrix(); + + gl.glPopMatrix(); + } + + public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {} + + private void gear(GL gl, + float inner_radius, + float outer_radius, + float width, + int teeth, + float tooth_depth) + { + int i; + float r0, r1, r2; + float angle, da; + float u, v, len; + + 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(GL.GL_FLAT); + + gl.glNormal3f(0.0f, 0.0f, 1.0f); + + /* draw front face */ + gl.glBegin(GL.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + if(i < teeth) + { + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f); + } + } + gl.glEnd(); + + /* draw front sides of teeth */ + gl.glBegin(GL.GL_QUADS); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2.0f * da), r2 * (float)Math.sin(angle + 2.0f * da), width * 0.5f); + 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(GL.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + } + gl.glEnd(); + + /* draw back sides of teeth */ + gl.glBegin(GL.GL_QUADS); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + } + gl.glEnd(); + + /* draw outward faces of teeth */ + gl.glBegin(GL.GL_QUAD_STRIP); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + u = r2 * (float)Math.cos(angle + da) - r1 * (float)Math.cos(angle); + v = r2 * (float)Math.sin(angle + da) - r1 * (float)Math.sin(angle); + len = (float)Math.sqrt(u * u + v * v); + u /= len; + v /= len; + gl.glNormal3f(v, -u, 0.0f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f); + gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f); + u = r1 * (float)Math.cos(angle + 3 * da) - r2 * (float)Math.cos(angle + 2 * da); + v = r1 * (float)Math.sin(angle + 3 * da) - r2 * (float)Math.sin(angle + 2 * da); + gl.glNormal3f(v, -u, 0.0f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f); + } + 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(GL.GL_SMOOTH); + + /* draw inside radius cylinder */ + gl.glBegin(GL.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glNormal3f(-(float)Math.cos(angle), -(float)Math.sin(angle), 0.0f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + } + gl.glEnd(); + } + + // Methods required for the implementation of MouseListener + public void mouseEntered(MouseEvent e) {} + public void mouseExited(MouseEvent e) {} + + public void mousePressed(MouseEvent e) { + prevMouseX = e.getX(); + prevMouseY = e.getY(); + if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { + mouseRButtonDown = true; + } + } + + public void mouseReleased(MouseEvent e) { + if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { + mouseRButtonDown = false; + } + } + + public void mouseClicked(MouseEvent e) {} + + // Methods required for the implementation of MouseMotionListener + public void mouseDragged(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + Dimension size = e.getComponent().getSize(); + + float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)size.width); + float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)size.height); + + prevMouseX = x; + prevMouseY = y; + + view_rotx += thetaX; + view_roty += thetaY; + } + + public void mouseMoved(MouseEvent e) {} + + public void dispatchKey(int keyCode) { + switch (keyCode) { + case KeyEvent.VK_Q: + case KeyEvent.VK_ESCAPE: + runExit(); + } + } + } + + public void runExit() { + // 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() { + animator.stop(); + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + if (fullScreen) { + try { + dev.setDisplayMode(origMode); + } catch (Exception e1) { + } + try { + dev.setFullScreenWindow(null); + } catch (Exception e2) { + } + fullScreen = false; + } + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + System.exit(0); + } + }).start(); + } +} diff --git a/src/demos/fullscreen/GearsFullscreen2.java b/src/demos/fullscreen/GearsFullscreen2.java new file mode 100755 index 0000000..5ed02f8 --- /dev/null +++ b/src/demos/fullscreen/GearsFullscreen2.java @@ -0,0 +1,448 @@ +package demos.fullscreen; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +import net.java.games.jogl.*; +import demos.util.*; + +/** + * GearsFullscreen2.java <BR> + * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P> + * + * This version is equal to Brian Paul's version 1.2 1999/10/21 <P> + * + * Illustrates more complex usage of GLCanvas in full-screen mode. On + * Windows this demo should be run with the system property + * -Dsun.java2d.noddraw=true specified to prevent Java2D from using + * DirectDraw, which is incompatible with OpenGL at the driver level. + */ + +public class GearsFullscreen2 { + private GraphicsDevice dev; + private DisplayMode origMode; + private boolean fullScreen; + private JFrame frame; + private Animator animator; + private int initWidth = 300; + private int initHeight = 300; + + public static void main(String[] args) { + new GearsFullscreen2().run(args); + } + + public void run(String[] args) { + dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + origMode = dev.getDisplayMode(); + DisplayMode newMode = null; + + if (dev.isFullScreenSupported()) { + newMode = ScreenResSelector.showSelectionDialog(); + if (newMode != null) { + initWidth = newMode.getWidth(); + initHeight = newMode.getHeight(); + } + } else { + System.err.println("NOTE: full-screen mode not supported; running in window instead"); + } + + frame = new JFrame("Gear Demo"); + if (newMode != null) { + frame.setUndecorated(true); + } + GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); + + canvas.addGLEventListener(new GearRenderer()); + frame.getContentPane().setLayout(new BorderLayout()); + + ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false); + + JButton button = new JButton("West"); + button.setToolTipText("West ToolTip"); + frame.getContentPane().add(button, BorderLayout.WEST); + + button = new JButton("East"); + button.setToolTipText("East ToolTip"); + frame.getContentPane().add(button, BorderLayout.EAST); + + button = new JButton("North"); + button.setToolTipText("North ToolTip"); + frame.getContentPane().add(button, BorderLayout.NORTH); + + button = new JButton("South"); + button.setToolTipText("South ToolTip"); + frame.getContentPane().add(button, BorderLayout.SOUTH); + + frame.getContentPane().add(canvas, BorderLayout.CENTER); + frame.setSize(initWidth, initHeight); + animator = new Animator(canvas); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + runExit(); + } + }); + frame.setVisible(true); + + if (dev.isFullScreenSupported() && (newMode != null)) { + dev.setFullScreenWindow(frame); + if (dev.isDisplayChangeSupported()) { + dev.setDisplayMode(newMode); + fullScreen = true; + } else { + // Not much point in having a full-screen window in this case + dev.setFullScreenWindow(null); + final Frame f2 = frame; + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + f2.setVisible(false); + f2.setUndecorated(false); + f2.setVisible(true); + f2.setSize(initWidth, initHeight); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + System.err.println("NOTE: was not able to change display mode; full-screen disabled"); + } + } + + animator.start(); + } + + class GearRenderer implements GLEventListener, MouseListener, MouseMotionListener { + private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f; + private int gear1, gear2, gear3; + private float angle = 0.0f; + + private int prevMouseX, prevMouseY; + private boolean mouseRButtonDown = false; + + public void init(GLDrawable drawable) { + // Use debug pipeline + // drawable.setGL(new DebugGL(drawable.getGL())); + + GL gl = drawable.getGL(); + + // FIXME: workaround for Windows full-screen bug when + // sun.java2d.noddraw=true and similar bug on Mac OS X + if (fullScreen) { + final GLDrawable tmpDrawable = drawable; + EventQueue.invokeLater(new Runnable() { + public void run() { + frame.setVisible(false); + frame.setBounds(0, 0, initWidth, initHeight); + frame.setVisible(true); + frame.toFront(); + } + }); + } + + System.err.println("INIT GL IS: " + gl.getClass().getName()); + + gl.setSwapInterval(1); + + float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f }; + float red[] = { 0.8f, 0.1f, 0.0f, 1.0f }; + float green[] = { 0.0f, 0.8f, 0.2f, 1.0f }; + float blue[] = { 0.2f, 0.2f, 1.0f, 1.0f }; + + gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos); + gl.glEnable(GL.GL_CULL_FACE); + gl.glEnable(GL.GL_LIGHTING); + gl.glEnable(GL.GL_LIGHT0); + gl.glEnable(GL.GL_DEPTH_TEST); + + /* make the gears */ + gear1 = gl.glGenLists(1); + gl.glNewList(gear1, GL.GL_COMPILE); + gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, red); + gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f); + gl.glEndList(); + + gear2 = gl.glGenLists(1); + gl.glNewList(gear2, GL.GL_COMPILE); + gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, green); + gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f); + gl.glEndList(); + + gear3 = gl.glGenLists(1); + gl.glNewList(gear3, GL.GL_COMPILE); + gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, blue); + gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f); + gl.glEndList(); + + gl.glEnable(GL.GL_NORMALIZE); + + drawable.addMouseListener(this); + drawable.addMouseMotionListener(this); + + drawable.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + dispatchKey(e.getKeyCode()); + } + }); + } + + public void reshape(GLDrawable drawable, int x, int y, int width, int height) { + GL gl = drawable.getGL(); + + float h = (float)height / (float)width; + + gl.glMatrixMode(GL.GL_PROJECTION); + + System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR)); + System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER)); + System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION)); + System.err.println(); + System.err.println("glLoadTransposeMatrixfARB() supported: " + + gl.isFunctionAvailable("glLoadTransposeMatrixfARB")); + if (!gl.isFunctionAvailable("glLoadTransposeMatrixfARB")) { + // --- not using extensions + gl.glLoadIdentity(); + } else { + // --- using extensions + final float[] identityTranspose = new float[] { + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + }; + gl.glLoadTransposeMatrixfARB(identityTranspose); + } + gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f); + gl.glMatrixMode(GL.GL_MODELVIEW); + gl.glLoadIdentity(); + gl.glTranslatef(0.0f, 0.0f, -40.0f); + } + + public void display(GLDrawable drawable) { + angle += 2.0f; + + GL gl = drawable.getGL(); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + + gl.glPushMatrix(); + gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); + gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); + gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); + + gl.glPushMatrix(); + gl.glTranslatef(-3.0f, -2.0f, 0.0f); + gl.glRotatef(angle, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear1); + gl.glPopMatrix(); + + gl.glPushMatrix(); + gl.glTranslatef(3.1f, -2.0f, 0.0f); + gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear2); + gl.glPopMatrix(); + + gl.glPushMatrix(); + gl.glTranslatef(-3.1f, 4.2f, 0.0f); + gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear3); + gl.glPopMatrix(); + + gl.glPopMatrix(); + } + + public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {} + + private void gear(GL gl, + float inner_radius, + float outer_radius, + float width, + int teeth, + float tooth_depth) + { + int i; + float r0, r1, r2; + float angle, da; + float u, v, len; + + 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(GL.GL_FLAT); + + gl.glNormal3f(0.0f, 0.0f, 1.0f); + + /* draw front face */ + gl.glBegin(GL.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + if(i < teeth) + { + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f); + } + } + gl.glEnd(); + + /* draw front sides of teeth */ + gl.glBegin(GL.GL_QUADS); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2.0f * da), r2 * (float)Math.sin(angle + 2.0f * da), width * 0.5f); + 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(GL.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + } + gl.glEnd(); + + /* draw back sides of teeth */ + gl.glBegin(GL.GL_QUADS); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + } + gl.glEnd(); + + /* draw outward faces of teeth */ + gl.glBegin(GL.GL_QUAD_STRIP); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + u = r2 * (float)Math.cos(angle + da) - r1 * (float)Math.cos(angle); + v = r2 * (float)Math.sin(angle + da) - r1 * (float)Math.sin(angle); + len = (float)Math.sqrt(u * u + v * v); + u /= len; + v /= len; + gl.glNormal3f(v, -u, 0.0f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f); + gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f); + u = r1 * (float)Math.cos(angle + 3 * da) - r2 * (float)Math.cos(angle + 2 * da); + v = r1 * (float)Math.sin(angle + 3 * da) - r2 * (float)Math.sin(angle + 2 * da); + gl.glNormal3f(v, -u, 0.0f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f); + } + 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(GL.GL_SMOOTH); + + /* draw inside radius cylinder */ + gl.glBegin(GL.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glNormal3f(-(float)Math.cos(angle), -(float)Math.sin(angle), 0.0f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + } + gl.glEnd(); + } + + // Methods required for the implementation of MouseListener + public void mouseEntered(MouseEvent e) {} + public void mouseExited(MouseEvent e) {} + + public void mousePressed(MouseEvent e) { + prevMouseX = e.getX(); + prevMouseY = e.getY(); + if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { + mouseRButtonDown = true; + } + } + + public void mouseReleased(MouseEvent e) { + if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { + mouseRButtonDown = false; + } + } + + public void mouseClicked(MouseEvent e) {} + + // Methods required for the implementation of MouseMotionListener + public void mouseDragged(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + Dimension size = e.getComponent().getSize(); + + float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)size.width); + float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)size.height); + + prevMouseX = x; + prevMouseY = y; + + view_rotx += thetaX; + view_roty += thetaY; + } + + public void mouseMoved(MouseEvent e) {} + + public void dispatchKey(int keyCode) { + switch (keyCode) { + case KeyEvent.VK_Q: + case KeyEvent.VK_ESCAPE: + runExit(); + } + } + } + + public void runExit() { + // 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() { + animator.stop(); + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + if (fullScreen) { + try { + dev.setDisplayMode(origMode); + } catch (Exception e1) { + } + try { + dev.setFullScreenWindow(null); + } catch (Exception e2) { + } + fullScreen = false; + } + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + System.exit(0); + } + }).start(); + } +} diff --git a/src/demos/fullscreen/JGearsFullscreen.java b/src/demos/fullscreen/JGearsFullscreen.java new file mode 100755 index 0000000..84c79b7 --- /dev/null +++ b/src/demos/fullscreen/JGearsFullscreen.java @@ -0,0 +1,461 @@ +package demos.fullscreen; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +import net.java.games.jogl.*; +import demos.util.*; + +/** + * JGearsFullscreen.java <BR> + * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P> + * + * This version is equal to Brian Paul's version 1.2 1999/10/21 <P> + * + * Illustrates usage of GLJPanel in full-screen mode. On Windows this + * demo should be run with the system property + * -Dsun.java2d.noddraw=true specified to prevent Java2D from using + * DirectDraw, which is incompatible with OpenGL at the driver level. + */ + +public class JGearsFullscreen { + private GraphicsDevice dev; + private DisplayMode origMode; + private boolean fullScreen; + private JFrame frame; + private Animator animator; + private int initWidth = 300; + private int initHeight = 300; + + public static void main(String[] args) { + new JGearsFullscreen().run(args); + } + + public void run(String[] args) { + dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + origMode = dev.getDisplayMode(); + DisplayMode newMode = null; + + if (dev.isFullScreenSupported()) { + newMode = ScreenResSelector.showSelectionDialog(); + if (newMode != null) { + initWidth = newMode.getWidth(); + initHeight = newMode.getHeight(); + } + } else { + System.err.println("NOTE: full-screen mode not supported; running in window instead"); + } + + frame = new JFrame("Gear Demo"); + if (newMode != null) { + frame.setUndecorated(true); + } + GLJPanel drawable = GLDrawableFactory.getFactory().createGLJPanel(new GLCapabilities()); + drawable.addGLEventListener(new GearRenderer()); + + frame.getContentPane().setLayout(new BorderLayout()); + + JButton button = new JButton("West"); + button.setToolTipText("West ToolTip"); + frame.getContentPane().add(button, BorderLayout.WEST); + + button = new JButton("East"); + button.setToolTipText("East ToolTip"); + frame.getContentPane().add(button, BorderLayout.EAST); + + button = new JButton("North"); + button.setToolTipText("North ToolTip"); + frame.getContentPane().add(button, BorderLayout.NORTH); + + button = new JButton("South"); + button.setToolTipText("South ToolTip"); + frame.getContentPane().add(button, BorderLayout.SOUTH); + + frame.getContentPane().add(drawable, BorderLayout.CENTER); + frame.setSize(initWidth, initHeight); + animator = new Animator(drawable); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + runExit(); + } + }); + frame.setVisible(true); + + if (dev.isFullScreenSupported() && (newMode != null)) { + dev.setFullScreenWindow(frame); + if (dev.isDisplayChangeSupported()) { + dev.setDisplayMode(newMode); + fullScreen = true; + } else { + // Not much point in having a full-screen window in this case + dev.setFullScreenWindow(null); + final Frame f2 = frame; + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + f2.setVisible(false); + f2.setUndecorated(false); + f2.setVisible(true); + f2.setSize(initWidth, initHeight); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + System.err.println("NOTE: was not able to change display mode; full-screen disabled"); + } + } + + animator.start(); + } + + class GearRenderer implements GLEventListener, MouseListener, MouseMotionListener { + private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f; + private int gear1, gear2, gear3; + private float angle = 0.0f; + + private int prevMouseX, prevMouseY; + private boolean mouseRButtonDown = false; + + public void init(GLDrawable drawable) { + // Use debug pipeline + // drawable.setGL(new DebugGL(drawable.getGL())); + + GL gl = drawable.getGL(); + + // FIXME: workaround for Windows full-screen bug when + // sun.java2d.noddraw=true and similar bug on Mac OS X + if (fullScreen) { + final GLDrawable tmpDrawable = drawable; + Runnable r = new Runnable() { + public void run() { + frame.setVisible(false); + frame.setBounds(0, 0, initWidth, initHeight); + frame.setVisible(true); + frame.toFront(); + frame.requestFocus(); + } + }; + // FIXME: this is a total hack to work around behavior seen on JDK 1.5 + // Should find a better way / place to do this (to ensure the + // fixup runnable is only invoked once things have settled + // down) + EventQueue.invokeLater(r); + EventQueue.invokeLater(r); + } + + System.err.println("INIT GL IS: " + gl.getClass().getName()); + + gl.setSwapInterval(1); + + float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f }; + float red[] = { 0.8f, 0.1f, 0.0f, 1.0f }; + float green[] = { 0.0f, 0.8f, 0.2f, 1.0f }; + float blue[] = { 0.2f, 0.2f, 1.0f, 1.0f }; + + gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos); + gl.glEnable(GL.GL_CULL_FACE); + gl.glEnable(GL.GL_LIGHTING); + gl.glEnable(GL.GL_LIGHT0); + gl.glEnable(GL.GL_DEPTH_TEST); + + /* make the gears */ + gear1 = gl.glGenLists(1); + gl.glNewList(gear1, GL.GL_COMPILE); + gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, red); + gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f); + gl.glEndList(); + + gear2 = gl.glGenLists(1); + gl.glNewList(gear2, GL.GL_COMPILE); + gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, green); + gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f); + gl.glEndList(); + + gear3 = gl.glGenLists(1); + gl.glNewList(gear3, GL.GL_COMPILE); + gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, blue); + gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f); + gl.glEndList(); + + gl.glEnable(GL.GL_NORMALIZE); + + drawable.addMouseListener(this); + drawable.addMouseMotionListener(this); + + // FIXME: for some reason, adding a key listener to the GLJPanel + // isn't working in this configuration + InputMap map = ((GLJPanel) drawable).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); + ActionMap actMap = ((GLJPanel) drawable).getActionMap(); + Action act = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + runExit(); + } + }; + + map.put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, 0), act); + map.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), act); + actMap.put(act, act); + } + + public void reshape(GLDrawable drawable, int x, int y, int width, int height) { + GL gl = drawable.getGL(); + + float h = (float)height / (float)width; + + gl.glMatrixMode(GL.GL_PROJECTION); + + System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR)); + System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER)); + System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION)); + System.err.println(); + System.err.println("glLoadTransposeMatrixfARB() supported: " + + gl.isFunctionAvailable("glLoadTransposeMatrixfARB")); + if (!gl.isFunctionAvailable("glLoadTransposeMatrixfARB")) { + // --- not using extensions + gl.glLoadIdentity(); + } else { + // --- using extensions + final float[] identityTranspose = new float[] { + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + }; + gl.glLoadTransposeMatrixfARB(identityTranspose); + } + gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f); + gl.glMatrixMode(GL.GL_MODELVIEW); + gl.glLoadIdentity(); + gl.glTranslatef(0.0f, 0.0f, -40.0f); + } + + public void display(GLDrawable drawable) { + angle += 2.0f; + + GL gl = drawable.getGL(); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + + gl.glPushMatrix(); + gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); + gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); + gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); + + gl.glPushMatrix(); + gl.glTranslatef(-3.0f, -2.0f, 0.0f); + gl.glRotatef(angle, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear1); + gl.glPopMatrix(); + + gl.glPushMatrix(); + gl.glTranslatef(3.1f, -2.0f, 0.0f); + gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear2); + gl.glPopMatrix(); + + gl.glPushMatrix(); + gl.glTranslatef(-3.1f, 4.2f, 0.0f); + gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f); + gl.glCallList(gear3); + gl.glPopMatrix(); + + gl.glPopMatrix(); + } + + public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {} + + private void gear(GL gl, + float inner_radius, + float outer_radius, + float width, + int teeth, + float tooth_depth) + { + int i; + float r0, r1, r2; + float angle, da; + float u, v, len; + + 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(GL.GL_FLAT); + + gl.glNormal3f(0.0f, 0.0f, 1.0f); + + /* draw front face */ + gl.glBegin(GL.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + if(i < teeth) + { + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f); + } + } + gl.glEnd(); + + /* draw front sides of teeth */ + gl.glBegin(GL.GL_QUADS); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2.0f * da), r2 * (float)Math.sin(angle + 2.0f * da), width * 0.5f); + 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(GL.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + } + gl.glEnd(); + + /* draw back sides of teeth */ + gl.glBegin(GL.GL_QUADS); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + } + gl.glEnd(); + + /* draw outward faces of teeth */ + gl.glBegin(GL.GL_QUAD_STRIP); + for (i = 0; i < teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); + u = r2 * (float)Math.cos(angle + da) - r1 * (float)Math.cos(angle); + v = r2 * (float)Math.sin(angle + da) - r1 * (float)Math.sin(angle); + len = (float)Math.sqrt(u * u + v * v); + u /= len; + v /= len; + gl.glNormal3f(v, -u, 0.0f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f); + gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), width * 0.5f); + gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f); + u = r1 * (float)Math.cos(angle + 3 * da) - r2 * (float)Math.cos(angle + 2 * da); + v = r1 * (float)Math.sin(angle + 3 * da) - r2 * (float)Math.sin(angle + 2 * da); + gl.glNormal3f(v, -u, 0.0f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), width * 0.5f); + gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); + gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f); + } + 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(GL.GL_SMOOTH); + + /* draw inside radius cylinder */ + gl.glBegin(GL.GL_QUAD_STRIP); + for (i = 0; i <= teeth; i++) + { + angle = i * 2.0f * (float) Math.PI / teeth; + gl.glNormal3f(-(float)Math.cos(angle), -(float)Math.sin(angle), 0.0f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); + gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); + } + gl.glEnd(); + } + + // Methods required for the implementation of MouseListener + public void mouseEntered(MouseEvent e) {} + public void mouseExited(MouseEvent e) {} + + public void mousePressed(MouseEvent e) { + prevMouseX = e.getX(); + prevMouseY = e.getY(); + if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { + mouseRButtonDown = true; + } + } + + public void mouseReleased(MouseEvent e) { + if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { + mouseRButtonDown = false; + } + } + + public void mouseClicked(MouseEvent e) {} + + // Methods required for the implementation of MouseMotionListener + public void mouseDragged(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + Dimension size = e.getComponent().getSize(); + + float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)size.width); + float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)size.height); + + prevMouseX = x; + prevMouseY = y; + + view_rotx += thetaX; + view_roty += thetaY; + } + + public void mouseMoved(MouseEvent e) {} + + public void dispatchKey(int keyCode) { + switch (keyCode) { + case KeyEvent.VK_Q: + case KeyEvent.VK_ESCAPE: + runExit(); + } + } + } + + public void runExit() { + // 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() { + animator.stop(); + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + if (fullScreen) { + try { + dev.setDisplayMode(origMode); + } catch (Exception e1) { + } + try { + dev.setFullScreenWindow(null); + } catch (Exception e2) { + } + fullScreen = false; + } + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + System.exit(0); + } + }).start(); + } +} diff --git a/src/demos/gears/Gears.java b/src/demos/gears/Gears.java index da8fdba..775dcf0 100644 --- a/src/demos/gears/Gears.java +++ b/src/demos/gears/Gears.java @@ -17,6 +17,11 @@ public class Gears { Frame frame = new Frame("Gear Demo"); GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); + // Use debug pipeline + // canvas.setGL(new DebugGL(canvas.getGL())); + System.err.println("CANVAS GL IS: " + canvas.getGL().getClass().getName()); + System.err.println("CANVAS GLU IS: " + canvas.getGLU().getClass().getName()); + canvas.addGLEventListener(new GearRenderer()); frame.add(canvas); frame.setSize(300, 300); @@ -47,11 +52,7 @@ public class Gears { private boolean mouseRButtonDown = false; public void init(GLDrawable drawable) { - // Use debug pipeline - // drawable.setGL(new DebugGL(drawable.getGL())); - GL gl = drawable.getGL(); - System.err.println("INIT GL IS: " + gl.getClass().getName()); gl.setSwapInterval(1); diff --git a/src/demos/hdr/HDR.java b/src/demos/hdr/HDR.java index 312741d..2e650fc 100755 --- a/src/demos/hdr/HDR.java +++ b/src/demos/hdr/HDR.java @@ -176,11 +176,11 @@ public class HDR { frame = new Frame("HDR test"); frame.setLayout(new BorderLayout()); - frame.setResizable(false); canvas.setSize(win_w, win_h); frame.add(canvas, BorderLayout.CENTER); frame.pack(); + frame.setResizable(false); frame.show(); canvas.requestFocus(); @@ -353,6 +353,9 @@ public class HDR { } drawQuadRect4(gl, win_w, win_h, pbuffer_w, pbuffer_h); gl.glDisable(GL.GL_TEXTURE_RECTANGLE_NV); + + // Try to avoid swamping the CPU on Linux + Thread.yield(); } public void reshape(GLDrawable drawable, int x, int y, int width, int height) {} diff --git a/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java b/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java index f97e875..13f3997 100644 --- a/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java +++ b/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java @@ -161,8 +161,12 @@ public class HWShadowmapsSimple { class Listener implements GLEventListener { public void init(GLDrawable drawable) { - // Use debug pipeline - // drawable.setGL(new DebugGL(drawable.getGL())); + // init() might get called more than once if the GLCanvas is + // added and removed, but we only want to install the DebugGL + // pipeline once + // if (!(drawable.getGL() instanceof DebugGL)) { + // drawable.setGL(new DebugGL(drawable.getGL())); + // } GL gl = drawable.getGL(); GLU glu = drawable.getGLU(); @@ -374,8 +378,12 @@ public class HWShadowmapsSimple { class PbufferListener implements GLEventListener { public void init(GLDrawable drawable) { - // Use debug pipeline - // drawable.setGL(new DebugGL(drawable.getGL())); + // init() might get called more than once if the GLCanvas is + // added and removed, but we only want to install the DebugGL + // pipeline once + // if (!(drawable.getGL() instanceof DebugGL)) { + // drawable.setGL(new DebugGL(drawable.getGL())); + // } GL gl = drawable.getGL(); GLU glu = drawable.getGLU(); diff --git a/src/demos/jgears/JGears.java b/src/demos/jgears/JGears.java index ee0690c..6adc528 100644 --- a/src/demos/jgears/JGears.java +++ b/src/demos/jgears/JGears.java @@ -17,6 +17,11 @@ public class JGears { Frame frame = new Frame("Gear Demo"); GLJPanel drawable = GLDrawableFactory.getFactory().createGLJPanel(new GLCapabilities()); + // Use debug pipeline + // drawable.setGL(new DebugGL(drawable.getGL())); + System.err.println("DRAWABLE GL IS: " + drawable.getGL().getClass().getName()); + System.err.println("DRAWABLE GLU IS: " + drawable.getGLU().getClass().getName()); + drawable.addGLEventListener(new GearRenderer()); frame.add(drawable); frame.setSize(300, 300); @@ -48,9 +53,6 @@ public class JGears { public void init(GLDrawable drawable) { - // Use debug pipeline - // drawable.setGL(new DebugGL(drawable.getGL())); - GL gl = drawable.getGL(); System.err.println("INIT GL IS: " + gl.getClass().getName()); diff --git a/src/demos/jrefract/JRefract.java b/src/demos/jrefract/JRefract.java index bc7606f..a2feafe 100755 --- a/src/demos/jrefract/JRefract.java +++ b/src/demos/jrefract/JRefract.java @@ -42,7 +42,6 @@ import java.util.*; import javax.imageio.*; import javax.imageio.stream.*; import javax.swing.*; -import javax.swing.event.*; import net.java.games.jogl.*; import net.java.games.jogl.util.*; @@ -64,31 +63,24 @@ import gleem.linalg.*; public class JRefract { private boolean useRegisterCombiners; - private ArrayList canvases; - + private GLJPanel canvas; + private Animator animator; private volatile boolean quit; - private volatile boolean animatorStopped; - private JDesktopPane desktop; public static void main(String[] args) { new JRefract().run(args); } - private JInternalFrame addWindow(boolean bunny) { - String str = bunny ? - "Refraction Using Vertex Programs" : - "Gears Demo"; - final JInternalFrame inner = new JInternalFrame(str); + public void run(String[] args) { + + JFrame frame = new JFrame("JOGL and Swing Interoperability"); + JDesktopPane desktop = new JDesktopPane(); + desktop.setSize(1024, 768); + JInternalFrame inner = new JInternalFrame("Refraction Using Vertex Programs"); inner.setResizable(true); - inner.setClosable(true); - inner.setVisible(true); - final GLJPanel canvas = GLDrawableFactory.getFactory().createGLJPanel(new GLCapabilities()); - if (bunny) { - canvas.addGLEventListener(new Listener()); - } else { - canvas.addGLEventListener(new GearRenderer()); - } + canvas = GLDrawableFactory.getFactory().createGLJPanel(new GLCapabilities()); + canvas.addGLEventListener(new Listener()); canvas.setSize(512, 512); canvas.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { @@ -96,15 +88,6 @@ public class JRefract { } }); - addJPanel(canvas); - - inner.addInternalFrameListener(new InternalFrameAdapter() { - public void internalFrameClosed(InternalFrameEvent e) { - removeJPanel(canvas); - System.gc(); - } - }); - inner.getContentPane().setLayout(new BorderLayout()); inner.getContentPane().add(canvas, BorderLayout.CENTER); inner.getContentPane().add(new JButton("West"), BorderLayout.WEST); @@ -112,20 +95,10 @@ public class JRefract { inner.getContentPane().add(new JButton("North"), BorderLayout.NORTH); inner.getContentPane().add(new JButton("South"), BorderLayout.SOUTH); inner.setSize(canvas.getSize()); - desktop.add(inner); - - return inner; - } - - public void run(String[] args) { - - canvases = new ArrayList(); - - JFrame frame = new JFrame("JOGL and Swing Interoperability"); - desktop = new JDesktopPane(); - desktop.setSize(1024, 768); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(desktop, BorderLayout.CENTER); + desktop.add(inner); + inner.setVisible(true); JInternalFrame inner2 = new JInternalFrame("Hello, World"); JLabel label = new JLabel("Hello, World!"); @@ -136,44 +109,7 @@ public class JRefract { desktop.add(inner2); inner2.setVisible(true); - JMenuBar menuBar = new JMenuBar(); - - JMenu menu = new JMenu("Actions"); - JMenuItem item = new JMenuItem("New bunny"); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - addWindow(true); - } - }); - menu.add(item); - - item = new JMenuItem("New gears"); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - addWindow(false); - } - }); - menu.add(item); - - item = new JMenuItem("Auto mode"); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - startAutoMode(); - } - }); - menu.add(item); - - item = new JMenuItem("Exit"); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - runExit(); - } - }); - menu.add(item); - - menuBar.add(menu); - frame.setJMenuBar(menuBar); - + animator = new Animator(canvas); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { runExit(); @@ -181,8 +117,7 @@ public class JRefract { }); frame.setSize(desktop.getSize()); frame.setVisible(true); - - new Thread(new ListAnimator()).start(); + animator.start(); } class Listener implements GLEventListener { @@ -311,9 +246,6 @@ public class JRefract { "END\n"; public void init(GLDrawable drawable) { - // Use debug pipeline - // drawable.setGL(new DebugGL(drawable.getGL())); - GL gl = drawable.getGL(); GLU glu = drawable.getGLU(); float cc = 1.0f; @@ -607,9 +539,7 @@ public class JRefract { for (int i = 0; i < suffixes.length; i++) { String resourceName = baseName + "_" + suffixes[i] + ".png"; // Note: use of BufferedInputStream works around 4764639/4892246 - BufferedInputStream bis = new BufferedInputStream(getClass().getClassLoader().getResourceAsStream(resourceName)); - BufferedImage img = ImageIO.read(bis); - bis.close(); + BufferedImage img = ImageIO.read(new BufferedInputStream(getClass().getClassLoader().getResourceAsStream(resourceName))); if (img == null) { throw new RuntimeException("Error reading PNG image " + resourceName); } @@ -835,6 +765,7 @@ public class JRefract { } private void runExit() { + quit = true; // Note: calling System.exit() synchronously inside the draw, // reshape or init callbacks can lead to deadlocks on certain // platforms (in particular, X11) because the JAWT's locking @@ -842,362 +773,9 @@ public class JRefract { // the exit routine in another thread. new Thread(new Runnable() { public void run() { - quit = true; - while (!animatorStopped) { - try { - Thread.sleep(1); - } catch (InterruptedException e) { - } - } + animator.stop(); System.exit(0); } }).start(); } - - private synchronized void addJPanel(GLJPanel panel) { - ArrayList newCanvases = (ArrayList) canvases.clone(); - newCanvases.add(panel); - canvases = newCanvases; - } - - private synchronized void removeJPanel(GLJPanel panel) { - ArrayList newCanvases = (ArrayList) canvases.clone(); - newCanvases.remove(panel); - canvases = newCanvases; - } - - class ListAnimator implements Runnable { - public void run() { - while (!quit) { - if (canvases.isEmpty()) { - try { - Thread.sleep(10); - } catch (InterruptedException e) { - } - } else { - for (Iterator iter = canvases.iterator(); iter.hasNext(); ) { - GLJPanel panel = (GLJPanel) iter.next(); - panel.display(); - } - try { - Thread.sleep(1); - } catch (InterruptedException e) { - } - } - } - animatorStopped = true; - } - } - - static class GearRenderer implements GLEventListener, MouseListener, MouseMotionListener { - private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f; - private int gear1, gear2, gear3; - private float angle = 0.0f; - - private int prevMouseX, prevMouseY; - private boolean mouseRButtonDown = false; - - - public void init(GLDrawable drawable) { - // Use debug pipeline - // drawable.setGL(new DebugGL(drawable.getGL())); - - GL gl = drawable.getGL(); - System.err.println("INIT GL IS: " + gl.getClass().getName()); - - float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f }; - float red[] = { 0.8f, 0.1f, 0.0f, 1.0f }; - float green[] = { 0.0f, 0.8f, 0.2f, 1.0f }; - float blue[] = { 0.2f, 0.2f, 1.0f, 1.0f }; - - gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos); - gl.glEnable(GL.GL_CULL_FACE); - gl.glEnable(GL.GL_LIGHTING); - gl.glEnable(GL.GL_LIGHT0); - gl.glEnable(GL.GL_DEPTH_TEST); - - /* make the gears */ - gear1 = gl.glGenLists(1); - gl.glNewList(gear1, GL.GL_COMPILE); - gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, red); - gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f); - gl.glEndList(); - - gear2 = gl.glGenLists(1); - gl.glNewList(gear2, GL.GL_COMPILE); - gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, green); - gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f); - gl.glEndList(); - - gear3 = gl.glGenLists(1); - gl.glNewList(gear3, GL.GL_COMPILE); - gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, blue); - gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f); - gl.glEndList(); - - gl.glEnable(GL.GL_NORMALIZE); - - drawable.addMouseListener(this); - drawable.addMouseMotionListener(this); - } - - public void reshape(GLDrawable drawable, int x, int y, int width, int height) { - GL gl = drawable.getGL(); - - float h = (float)height / (float)width; - - gl.glMatrixMode(GL.GL_PROJECTION); - - System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR)); - System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER)); - System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION)); - System.err.println(); - System.err.println("glLoadTransposeMatrixfARB() supported: " + - gl.isFunctionAvailable("glLoadTransposeMatrixfARB")); - if (!gl.isFunctionAvailable("glLoadTransposeMatrixfARB")) { - // --- not using extensions - gl.glLoadIdentity(); - } else { - // --- using extensions - final float[] identityTranspose = new float[] { - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - }; - gl.glLoadTransposeMatrixfARB(identityTranspose); - } - gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f); - gl.glMatrixMode(GL.GL_MODELVIEW); - gl.glLoadIdentity(); - gl.glTranslatef(0.0f, 0.0f, -40.0f); - } - - public void display(GLDrawable drawable) { - angle += 2.0f; - - GL gl = drawable.getGL(); - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - - gl.glPushMatrix(); - gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); - gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); - gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f); - - gl.glPushMatrix(); - gl.glTranslatef(-3.0f, -2.0f, 0.0f); - gl.glRotatef(angle, 0.0f, 0.0f, 1.0f); - gl.glCallList(gear1); - gl.glPopMatrix(); - - gl.glPushMatrix(); - gl.glTranslatef(3.1f, -2.0f, 0.0f); - gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f); - gl.glCallList(gear2); - gl.glPopMatrix(); - - gl.glPushMatrix(); - gl.glTranslatef(-3.1f, 4.2f, 0.0f); - gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f); - gl.glCallList(gear3); - gl.glPopMatrix(); - - gl.glPopMatrix(); - } - - public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {} - - private void gear(GL gl, - float inner_radius, - float outer_radius, - float width, - int teeth, - float tooth_depth) - { - int i; - float r0, r1, r2; - float angle, da; - float u, v, len; - - 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(GL.GL_FLAT); - - gl.glNormal3f(0.0f, 0.0f, 1.0f); - - /* draw front face */ - gl.glBegin(GL.GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) - { - angle = i * 2.0f * (float) Math.PI / teeth; - gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); - gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); - if(i < teeth) - { - gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); - gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f); - } - } - gl.glEnd(); - - /* draw front sides of teeth */ - gl.glBegin(GL.GL_QUADS); - for (i = 0; i < teeth; i++) - { - angle = i * 2.0f * (float) Math.PI / teeth; - gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); - gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f); - gl.glVertex3f(r2 * (float)Math.cos(angle + 2.0f * da), r2 * (float)Math.sin(angle + 2.0f * da), width * 0.5f); - 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(GL.GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) - { - angle = i * 2.0f * (float) Math.PI / teeth; - gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); - gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); - gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); - gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); - } - gl.glEnd(); - - /* draw back sides of teeth */ - gl.glBegin(GL.GL_QUADS); - for (i = 0; i < teeth; i++) - { - angle = i * 2.0f * (float) Math.PI / teeth; - gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); - gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f); - gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f); - gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); - } - gl.glEnd(); - - /* draw outward faces of teeth */ - gl.glBegin(GL.GL_QUAD_STRIP); - for (i = 0; i < teeth; i++) - { - angle = i * 2.0f * (float) Math.PI / teeth; - gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), width * 0.5f); - gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f); - u = r2 * (float)Math.cos(angle + da) - r1 * (float)Math.cos(angle); - v = r2 * (float)Math.sin(angle + da) - r1 * (float)Math.sin(angle); - len = (float)Math.sqrt(u * u + v * v); - u /= len; - v /= len; - gl.glNormal3f(v, -u, 0.0f); - gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), width * 0.5f); - gl.glVertex3f(r2 * (float)Math.cos(angle + da), r2 * (float)Math.sin(angle + da), -width * 0.5f); - gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f); - gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), width * 0.5f); - gl.glVertex3f(r2 * (float)Math.cos(angle + 2 * da), r2 * (float)Math.sin(angle + 2 * da), -width * 0.5f); - u = r1 * (float)Math.cos(angle + 3 * da) - r2 * (float)Math.cos(angle + 2 * da); - v = r1 * (float)Math.sin(angle + 3 * da) - r2 * (float)Math.sin(angle + 2 * da); - gl.glNormal3f(v, -u, 0.0f); - gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), width * 0.5f); - gl.glVertex3f(r1 * (float)Math.cos(angle + 3 * da), r1 * (float)Math.sin(angle + 3 * da), -width * 0.5f); - gl.glNormal3f((float)Math.cos(angle), (float)Math.sin(angle), 0.0f); - } - 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(GL.GL_SMOOTH); - - /* draw inside radius cylinder */ - gl.glBegin(GL.GL_QUAD_STRIP); - for (i = 0; i <= teeth; i++) - { - angle = i * 2.0f * (float) Math.PI / teeth; - gl.glNormal3f(-(float)Math.cos(angle), -(float)Math.sin(angle), 0.0f); - gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f); - gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), width * 0.5f); - } - gl.glEnd(); - } - - // Methods required for the implementation of MouseListener - public void mouseEntered(MouseEvent e) {} - public void mouseExited(MouseEvent e) {} - - public void mousePressed(MouseEvent e) { - prevMouseX = e.getX(); - prevMouseY = e.getY(); - if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { - mouseRButtonDown = true; - } - } - - public void mouseReleased(MouseEvent e) { - if ((e.getModifiers() & e.BUTTON3_MASK) != 0) { - mouseRButtonDown = false; - } - } - - public void mouseClicked(MouseEvent e) {} - - // Methods required for the implementation of MouseMotionListener - public void mouseDragged(MouseEvent e) { - int x = e.getX(); - int y = e.getY(); - Dimension size = e.getComponent().getSize(); - - float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)size.width); - float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)size.height); - - prevMouseX = x; - prevMouseY = y; - - view_rotx += thetaX; - view_roty += thetaY; - } - - public void mouseMoved(MouseEvent e) {} - } - - private JInternalFrame curFrame; - private void startAutoMode() { - new Thread(new Runnable() { - public void run() { - while (true) { - try { - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - curFrame = addWindow(false); - } - }); - } catch (Exception e) { - e.printStackTrace(); - } - - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - } - - try { - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - curFrame.doDefaultCloseAction(); - } - }); - } catch (Exception e) { - e.printStackTrace(); - } - - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - } - } - } - }).start(); - } } diff --git a/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java b/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java index d2a04af..9fa329d 100644 --- a/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java +++ b/src/demos/proceduralTexturePhysics/ProceduralTexturePhysics.java @@ -128,7 +128,6 @@ public class ProceduralTexturePhysics { public void init(GLDrawable drawable) { GL gl = drawable.getGL(); - gl.setSwapInterval(1); try { checkExtension(gl, "GL_ARB_multitexture"); diff --git a/src/demos/tess/Tess.java b/src/demos/tess/Tess.java index ccbd7a6..354a0c9 100644 --- a/src/demos/tess/Tess.java +++ b/src/demos/tess/Tess.java @@ -101,10 +101,14 @@ public class Tess { private int startList; public void init(GLDrawable drawable) { - drawable.setGL(new DebugGL(drawable.getGL())); - gl = drawable.getGL(); glu = drawable.getGLU(); + // init() might get called more than once if the GLCanvas is + // added and removed, but we only want to install the DebugGL + // pipeline once + if (!(drawable.getGL() instanceof DebugGL)) { + drawable.setGL(new DebugGL(drawable.getGL())); + } double[][] rect = new double[][]{{50.0, 50.0, 0.0}, {200.0, 50.0, 0.0}, diff --git a/src/demos/testContextDestruction/TestContextDestruction.java b/src/demos/testContextDestruction/TestContextDestruction.java index 3adb73c..2edff00 100755 --- a/src/demos/testContextDestruction/TestContextDestruction.java +++ b/src/demos/testContextDestruction/TestContextDestruction.java @@ -178,7 +178,12 @@ public class TestContextDestruction { class Listener implements GLEventListener { public void init(GLDrawable drawable) { System.out.println("Listener.init()"); - drawable.setGL(new DebugGL(drawable.getGL())); + // init() might get called more than once if the GLCanvas is + // added and removed, but we only want to install the DebugGL + // pipeline once + if (!(drawable.getGL() instanceof DebugGL)) { + drawable.setGL(new DebugGL(drawable.getGL())); + } GL gl = drawable.getGL(); diff --git a/src/demos/testContextSharing/TestContextSharing.java b/src/demos/testContextSharing/TestContextSharing.java index 88f453a..e50c4d0 100644 --- a/src/demos/testContextSharing/TestContextSharing.java +++ b/src/demos/testContextSharing/TestContextSharing.java @@ -97,7 +97,12 @@ public class TestContextSharing { class Listener implements GLEventListener { public void init(GLDrawable drawable) { - drawable.setGL(new DebugGL(drawable.getGL())); + // init() might get called more than once if the GLCanvas is + // added and removed, but we only want to install the DebugGL + // pipeline once + if (!(drawable.getGL() instanceof DebugGL)) { + drawable.setGL(new DebugGL(drawable.getGL())); + } GL gl = drawable.getGL(); diff --git a/src/demos/util/FileUtils.java b/src/demos/util/FileUtils.java index 37befc7..442485d 100755 --- a/src/demos/util/FileUtils.java +++ b/src/demos/util/FileUtils.java @@ -20,7 +20,7 @@ * 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 - * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * 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 diff --git a/src/demos/util/ObjReader.java b/src/demos/util/ObjReader.java index 10882f0..382a658 100644 --- a/src/demos/util/ObjReader.java +++ b/src/demos/util/ObjReader.java @@ -68,16 +68,8 @@ public class ObjReader { this(new File(filename)); } - public ObjReader(InputStream in) throws IOException { - this(new InputStreamReader(in)); - } - public ObjReader(File file) throws IOException { - this (new FileReader(file)); - } - - public ObjReader(Reader r) throws IOException { - BufferedReader reader = new BufferedReader(r); + BufferedReader reader = new BufferedReader(new FileReader(file)); String line = null; int lineNo = 0; float[] floatTmp = new float[3]; diff --git a/src/demos/util/ScreenResSelector.java b/src/demos/util/ScreenResSelector.java new file mode 100755 index 0000000..07df833 --- /dev/null +++ b/src/demos/util/ScreenResSelector.java @@ -0,0 +1,241 @@ +/* + * 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 + * 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. + * + * 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.util; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import javax.swing.*; + +public class ScreenResSelector { + static interface DisplayModeFilter { + public boolean filter(DisplayMode mode); + } + + public static java.util.List getAvailableDisplayModes() { + java.util.List modes = getDisplayModes(); + final DisplayMode curMode = getCurrentDisplayMode(); + // Filter everything which is higher frequency than the current + // display mode + modes = filterDisplayModes(modes, new DisplayModeFilter() { + public boolean filter(DisplayMode mode) { + return (mode.getRefreshRate() <= curMode.getRefreshRate()); + } + }); + // Filter everything that is not at least 24-bit + modes = filterDisplayModes(modes, new DisplayModeFilter() { + public boolean filter(DisplayMode mode) { + // Bit depth < 0 means "multi-depth" -- can't reason about it + return (mode.getBitDepth() < 0 || mode.getBitDepth() >= 24); + } + }); + // Filter everything less than 640x480 + modes = filterDisplayModes(modes, new DisplayModeFilter() { + public boolean filter(DisplayMode mode) { + return (mode.getWidth() >= 640 && mode.getHeight() >= 480); + } + }); + if (modes.size() == 0) { + throw new RuntimeException("Couldn't find any valid display modes"); + } + return modes; + } + + /** Shows a modal dialog containing the available screen resolutions + and requests selection of one of them. Returns the selected one. */ + public static DisplayMode showSelectionDialog() { + SelectionDialog dialog = new SelectionDialog(); + dialog.show(); + dialog.waitFor(); + return dialog.selected(); + } + + public static void main(String[] args) { + DisplayMode mode = showSelectionDialog(); + if (mode != null) { + System.err.println("Selected display mode:"); + System.err.println(modeToString(mode)); + } else { + System.err.println("No display mode selected."); + } + System.exit(0); + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private static DisplayMode getCurrentDisplayMode() { + GraphicsDevice dev = getDefaultScreenDevice(); + return dev.getDisplayMode(); + } + + private static java.util.List/*<DisplayMode>*/ getDisplayModes() { + GraphicsDevice dev = getDefaultScreenDevice(); + DisplayMode[] modes = dev.getDisplayModes(); + return toList(modes); + } + + private static GraphicsDevice getDefaultScreenDevice() { + return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + } + + private static java.util.List/*<DisplayMode>*/ toList(DisplayMode[] modes) { + java.util.List res = new ArrayList(); + for (int i = 0; i < modes.length; i++) { + res.add(modes[i]); + } + return res; + } + + private static String modeToString(DisplayMode mode) { + return (((mode.getBitDepth() > 0) ? (mode.getBitDepth() + " bits, ") : "") + + mode.getWidth() + "x" + mode.getHeight() + ", " + + mode.getRefreshRate() + " Hz"); + } + + private static String[] modesToString(java.util.List/*<DisplayMode>*/ modes) { + String[] res = new String[modes.size()]; + int i = 0; + for (Iterator iter = modes.iterator(); iter.hasNext(); ) { + res[i++] = modeToString((DisplayMode) iter.next()); + } + return res; + } + + private static java.util.List/*<DisplayMode>*/ filterDisplayModes(java.util.List/*<DisplayMode>*/ modes, + DisplayModeFilter filter) { + java.util.List res = new ArrayList(); + for (Iterator iter = modes.iterator(); iter.hasNext(); ) { + DisplayMode mode = (DisplayMode) iter.next(); + if (filter.filter(mode)) { + res.add(mode); + } + } + return res; + } + + static class SelectionDialog extends JFrame { + private Object monitor = new Object(); + private java.util.List modes; + private volatile boolean done = false; + private volatile int selectedIndex; + + public SelectionDialog() { + super(); + + setTitle("Display Modes"); + modes = getAvailableDisplayModes(); + String[] strings = modesToString(modes); + final JList modeList = new JList(strings); + modeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + modeList.setSelectedIndex(0); + JScrollPane scroller = new JScrollPane(modeList); + getContentPane().setLayout(new BorderLayout()); + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + panel.add(new JLabel("Select full-screen display mode,"), BorderLayout.NORTH); + panel.add(new JLabel("or Cancel for windowed mode:"), BorderLayout.CENTER); + getContentPane().add(BorderLayout.NORTH, panel); + getContentPane().add(BorderLayout.CENTER, scroller); + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); + buttonPanel.add(Box.createGlue()); + JButton button = new JButton("OK"); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + selectedIndex = modeList.getSelectedIndex(); + done = true; + synchronized(monitor) { + monitor.notify(); + } + hide(); + dispose(); + } + }); + buttonPanel.add(button); + buttonPanel.add(Box.createHorizontalStrut(10)); + button = new JButton("Cancel"); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + selectedIndex = -1; + done = true; + synchronized(monitor) { + monitor.notify(); + } + hide(); + dispose(); + } + }); + buttonPanel.add(button); + buttonPanel.add(Box.createGlue()); + getContentPane().add(BorderLayout.SOUTH, buttonPanel); + setSize(300, 200); + center(this, Toolkit.getDefaultToolkit().getScreenSize()); + } + + public void waitFor() { + synchronized(monitor) { + while (!done) { + try { + monitor.wait(); + } catch (InterruptedException e) { + } + } + } + } + + public DisplayMode selected() { + if (selectedIndex < 0) { + return null; + } else { + return (DisplayMode) modes.get(selectedIndex); + } + } + } + + private static void center(Component component, + Dimension containerDimension) { + Dimension sz = component.getSize(); + int x = ((containerDimension.width - sz.width) / 2); + int y = ((containerDimension.height - sz.height) / 2); + component.setLocation(x, y); + } +} diff --git a/src/demos/vertexArrayRange/VertexArrayRange.java b/src/demos/vertexArrayRange/VertexArrayRange.java index 5252f0e..3534c64 100644 --- a/src/demos/vertexArrayRange/VertexArrayRange.java +++ b/src/demos/vertexArrayRange/VertexArrayRange.java @@ -219,6 +219,8 @@ public class VertexArrayRange { setFlag('i', true); // infinite viewer and light canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); + // canvas.setGL(new TraceGL(canvas.getGL(), System.err)); + // canvas.setGL(new DebugGL(canvas.getGL())); VARListener listener = new VARListener(); canvas.addGLEventListener(listener); @@ -278,14 +280,17 @@ public class VertexArrayRange { boolean exiting = false; public void init(GLDrawable drawable) { - // drawable.setGL(new TraceGL(drawable.getGL(), System.err)); - // drawable.setGL(new DebugGL(drawable.getGL())); - GL gl = drawable.getGL(); GLU glu = drawable.getGLU(); // Try and disable synch-to-retrace for fastest framerate - gl.setSwapInterval(0); + if (gl.isFunctionAvailable("wglSwapIntervalEXT")) { + System.err.println("wglSwapIntervalEXT available; disabling sync-to-refresh for best framerate"); + gl.wglSwapIntervalEXT(0); + } + else { + System.err.println("wglSwapIntervalEXT not available; cannot disable sync-to-refresh"); + } try { ensurePresent("glVertexArrayRangeNV"); diff --git a/src/demos/vertexBufferObject/VertexBufferObject.java b/src/demos/vertexBufferObject/VertexBufferObject.java index 02bae92..78e10a9 100644 --- a/src/demos/vertexBufferObject/VertexBufferObject.java +++ b/src/demos/vertexBufferObject/VertexBufferObject.java @@ -214,6 +214,8 @@ public class VertexBufferObject { setFlag('i', true); // infinite viewer and light canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); + // canvas.setGL(new TraceGL(canvas.getGL(), System.err)); + // canvas.setGL(new DebugGL(canvas.getGL())); VBOListener listener = new VBOListener(); canvas.addGLEventListener(listener); @@ -272,9 +274,6 @@ public class VertexBufferObject { boolean exiting = false; public void init(GLDrawable drawable) { - // drawable.setGL(new TraceGL(drawable.getGL(), System.err)); - // drawable.setGL(new DebugGL(drawable.getGL())); - GL gl = drawable.getGL(); GLU glu = drawable.getGLU(); diff --git a/www/hdr_sm.jpg b/www/hdr_sm.jpg Binary files differnew file mode 100755 index 0000000..bce90ff --- /dev/null +++ b/www/hdr_sm.jpg diff --git a/www/webstart/HDR.jnlp b/www/webstart/HDR.jnlp new file mode 100755 index 0000000..6249d83 --- /dev/null +++ b/www/webstart/HDR.jnlp @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<jnlp codebase="https://jogl-demos.dev.java.net/webstart/" + href="HDR.jnlp"> + <information> + <title>JOGL High Dynamic Range Rendering Demo</title> + <vendor>Sun Microsystems, Inc.</vendor> + <homepage href="http://jogl-demos.dev.java.net/"/> + <description>High Dynamic Range Rendering Demo</description> + <description kind="short">NVidia's High Dynamic Range (HDR) rendering demo ported to Java and JOGL.</description> + <offline-allowed/> + </information> + + <resources> + <j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+"/> + <property name="sun.java2d.noddraw" value="true"/> + <jar href="jogl-demos.jar" main="true"/> + <jar href="jogl-demos-util.jar" /> + <jar href="jogl-demos-data.jar" /> + <extension name="jogl" href="https://jogl.dev.java.net/webstart/jogl.jnlp" /> + </resources> + + <application-desc main-class="demos.hdr.HDR"> + <argument>demos/data/images/stpeters_cross.hdr</argument> + <argument>512</argument> + <argument>384</argument> + <argument>2</argument> + <argument>7</argument> + <argument>3</argument> + <argument>demos/data/models/teapot.obj</argument> + </application-desc> +</jnlp> diff --git a/www/webstart/TestHandleBox.jnlp b/www/webstart/TestHandleBox.jnlp index 24ac6ec..1617c1d 100644 --- a/www/webstart/TestHandleBox.jnlp +++ b/www/webstart/TestHandleBox.jnlp @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<jnlp spec="1.0" - codebase="https://jogl-demos.dev.java.net/webstart/" +<jnlp codebase="https://jogl-demos.dev.java.net/webstart/" href="TestHandleBox.jnlp"> <information> <title>HandleBox Manipulator</title> diff --git a/www/webstart/TestTranslate1.jnlp b/www/webstart/TestTranslate1.jnlp index 87b213e..8396b84 100644 --- a/www/webstart/TestTranslate1.jnlp +++ b/www/webstart/TestTranslate1.jnlp @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<jnlp spec="1.0" - codebase="https://jogl-demos.dev.java.net/webstart/" +<jnlp codebase="https://jogl-demos.dev.java.net/webstart/" href="TestTranslate1.jnlp"> <information> <title>Translate1 Manipulator</title> diff --git a/www/webstart/TestTranslate2.jnlp b/www/webstart/TestTranslate2.jnlp index 9e1df03..068195a 100644 --- a/www/webstart/TestTranslate2.jnlp +++ b/www/webstart/TestTranslate2.jnlp @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<jnlp spec="1.0" - codebase="https://jogl-demos.dev.java.net/webstart/" +<jnlp codebase="https://jogl-demos.dev.java.net/webstart/" href="TestTranslate2.jnlp"> <information> <title>Translate2 Manipulator</title> diff --git a/www/webstart/jogl-demos-data.jar b/www/webstart/jogl-demos-data.jar Binary files differindex 55fe5f0..b139687 100644 --- a/www/webstart/jogl-demos-data.jar +++ b/www/webstart/jogl-demos-data.jar diff --git a/www/webstart/jogl-demos-util.jar b/www/webstart/jogl-demos-util.jar Binary files differindex 23a7da0..79989a9 100644 --- a/www/webstart/jogl-demos-util.jar +++ b/www/webstart/jogl-demos-util.jar diff --git a/www/webstart/jogl-demos.jar b/www/webstart/jogl-demos.jar Binary files differindex 3de7904..518fd11 100644 --- a/www/webstart/jogl-demos.jar +++ b/www/webstart/jogl-demos.jar |