diff options
Diffstat (limited to 'src/net/java/joglutils')
74 files changed, 2017 insertions, 1791 deletions
diff --git a/src/net/java/joglutils/GLJFrame.java b/src/net/java/joglutils/GLJFrame.java index 0746d5f..dbfba66 100644 --- a/src/net/java/joglutils/GLJFrame.java +++ b/src/net/java/joglutils/GLJFrame.java @@ -1,21 +1,21 @@ /*
* Copyright (c) 2006 Erik Tollerud ([email protected]) 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.
- *
+ *
* The names of Erik Tollerud, Sun Microsystems, Inc. or the names of
* contributors may not 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
@@ -23,12 +23,12 @@ * SUN MICROSYSTEMS, INC. ("SUN"), AND SUN'S 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 ERIK
- * TOLLERUD, SUN, OR SUN'S LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
+ * TOLLERUD, SUN, OR SUN'S 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 BEN
* CHAPPELL OR 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.
@@ -36,30 +36,45 @@ package net.java.joglutils;
-import javax.media.opengl.*;
-import javax.media.opengl.awt.*;
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.*;
-import com.sun.opengl.util.Animator;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.event.InputMethodListener;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
+
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLCapabilities;
+import com.jogamp.opengl.GLCapabilitiesChooser;
+import com.jogamp.opengl.GLContext;
+import com.jogamp.opengl.GLEventListener;
+import com.jogamp.opengl.GLProfile;
+import com.jogamp.opengl.awt.GLCanvas;
+import com.jogamp.opengl.util.Animator;
/**
- * A JFrame containing a heavyweight {@link GLCanvas} with a single attached {@link GLEventListener}.
+ * A JFrame containing a heavyweight {@link GLCanvas} with a single attached {@link GLEventListener}.
* Note: the default close operation has been changed to exit rather than dispose.
* @author Erik J. Tollerud
*/
public class GLJFrame extends JFrame {
private GLEventListener listener;
private GLCapabilities caps;
- private GLCapabilitiesChooser chooser;
+ private final GLCapabilitiesChooser chooser;
private Animator animator;
private GLContext contextToShareWith;
-
+
/**
* Creates new form GLJFrame
* @param listener the GLEventListener to attach to the GLCanvas
*/
- public GLJFrame(GLEventListener listener) {
+ public GLJFrame(final GLEventListener listener) {
this("OpenGL Window", listener);
}
/**
@@ -67,7 +82,7 @@ public class GLJFrame extends JFrame { * @param title the title for the window
* @param listener the GLEventListener to attach to the GLCanvas
*/
- public GLJFrame(String title, GLEventListener listener) {
+ public GLJFrame(final String title, final GLEventListener listener) {
super(title);
this.listener = listener;
this.caps = new GLCapabilities(GLProfile.getDefault());
@@ -85,7 +100,7 @@ public class GLJFrame extends JFrame { * @param listener the GLEventListener to attach to the GLCanvas
* @param contextToShareWith the context to share with
*/
- public GLJFrame(String title, GLEventListener listener, GLCapabilities caps,GLCapabilitiesChooser chooser,GLContext contextToShareWith) {
+ public GLJFrame(final String title, final GLEventListener listener, final GLCapabilities caps,final GLCapabilitiesChooser chooser,final GLContext contextToShareWith) {
super(title);
this.listener = listener;
this.caps = caps;
@@ -95,17 +110,17 @@ public class GLJFrame extends JFrame { ((GLCanvas)mainCanvas).addGLEventListener(listener);
animator = null;
}
-
+
/**
* Creates new form GLJFrame
* @param title title for the window
* @param listener the GLEventListener to attach to the GLCanvas
* @param capabilities the GLCapabilities to request for the GLCanvas
*/
- public GLJFrame(String title, GLEventListener listener, GLCapabilities capabilities) {
+ public GLJFrame(final String title, final GLEventListener listener, final GLCapabilities capabilities) {
this(title,listener,capabilities,null,null);
}
-
+
/**
* Creates new form GLJFrame
* @param title title for the window
@@ -113,27 +128,27 @@ public class GLJFrame extends JFrame { * @param capabilities the GLCapabilities to request for the GLCanvas
* @param chooser the capabilities chooser to use in creating the GLCanvas on this frame
*/
- public GLJFrame(String title, GLEventListener listener, GLCapabilities capabilities, GLCapabilitiesChooser chooser) {
+ public GLJFrame(final String title, final GLEventListener listener, final GLCapabilities capabilities, final GLCapabilitiesChooser chooser) {
this(title,listener,capabilities,chooser,null);
}
-
+
/**
* Creates new form GLJFrame
* @param listener the GLEventListener to attach to the GLCanvas
* @param contextToShareWith the context to share with
* @see javax.media.opengl.GLCanvas#javax.media.opengl.GLCanvas(javax.media.opengl.GLCapabilities,javax.media.opengl.GLCapabilitiesChooser,javax.media.opengl.GLContext,javax.media.opengl.GraphicsDevice)
*/
- public GLJFrame(GLEventListener listener, GLContext contextToShareWith) {
+ public GLJFrame(final GLEventListener listener, final GLContext contextToShareWith) {
this(listener);
this.contextToShareWith = contextToShareWith;
-
+
}
/**
* Creates new form GLJFrame
* @param listener the GLEventListener to attach to the GLCanvas
* @param capabilities the GLCapabilities to request for the GLCanvas
*/
- public GLJFrame(GLEventListener listener, GLCapabilities capabilities) {
+ public GLJFrame(final GLEventListener listener, final GLCapabilities capabilities) {
this("OpenGL Window", listener, capabilities);
}
/**
@@ -142,7 +157,7 @@ public class GLJFrame extends JFrame { * @param width the horizontal size for the GLCanvas in pixels
* @param height the vertical size for the GLCanvas in pixels
*/
- public GLJFrame(GLEventListener listener, int width, int height) {
+ public GLJFrame(final GLEventListener listener, final int width, final int height) {
this("OpenGL Window",listener);
mainCanvas.setSize(width,height);
this.pack();
@@ -154,7 +169,7 @@ public class GLJFrame extends JFrame { * @param width the horizontal size for the GLCanvas in pixels
* @param height the vertical size for the GLCanvas in pixels
*/
- public GLJFrame(String title, GLEventListener listener, int width, int height) {
+ public GLJFrame(final String title, final GLEventListener listener, final int width, final int height) {
this(title,listener);
mainCanvas.setSize(width,height);
this.pack();
@@ -164,7 +179,7 @@ public class GLJFrame extends JFrame { * @param listener the GLEventListener to attach to the GLCanvas
* @param fullscreen if true, this window is generated in fullscreen mode
*/
- public GLJFrame(GLEventListener listener, boolean fullscreen) {
+ public GLJFrame(final GLEventListener listener, final boolean fullscreen) {
this("OpenGL Window",listener);
this.setFullscreen(fullscreen);
}
@@ -174,11 +189,11 @@ public class GLJFrame extends JFrame { * @param listener the GLEventListener to attach to the GLCanvas
* @param fullscreen if true, this window is generated in fullscreen mode
*/
- public GLJFrame(String title, GLEventListener listener, boolean fullscreen) {
+ public GLJFrame(final String title, final GLEventListener listener, final boolean fullscreen) {
this(title,listener);
this.setFullscreen(fullscreen);
}
-
+
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
@@ -186,10 +201,11 @@ public class GLJFrame extends JFrame { */
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
- mainCanvas = new GLCanvas(caps,chooser,contextToShareWith,null);
+ mainCanvas = new GLCanvas(caps,chooser,null);
+ ((GLCanvas)mainCanvas).setSharedContext(contextToShareWith);
addComponentListener(new java.awt.event.ComponentAdapter() {
- public void componentResized(java.awt.event.ComponentEvent evt) {
+ public void componentResized(final java.awt.event.ComponentEvent evt) {
formComponentResized(evt);
}
});
@@ -199,11 +215,11 @@ public class GLJFrame extends JFrame { pack();
}// </editor-fold>//GEN-END:initComponents
-
- private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
+
+ private void formComponentResized(final java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
this.mainCanvas.setSize(this.getRootPane().getSize());
}//GEN-LAST:event_formComponentResized
-
+
// Variables declaration - do not modify//GEN-BEGIN:variables
private java.awt.Canvas mainCanvas;
// End of variables declaration//GEN-END:variables
@@ -211,11 +227,11 @@ public class GLJFrame extends JFrame { * Sets the event listener attached to the GLcanvas. Note that this method does not repaint this component, so it will not immediately update.
* @param listener the GLEventListener to attach to the GLCanvas
*/
- public void setGLEventListener(GLEventListener listener) {
+ public void setGLEventListener(final GLEventListener listener) {
((GLCanvas)this.mainCanvas).removeGLEventListener(this.listener);
this.listener = listener;
((GLCanvas)this.mainCanvas).addGLEventListener(listener);
-
+
}
/**
* Retrieves the event listener for the GLJFrame
@@ -229,17 +245,17 @@ public class GLJFrame extends JFrame { * @param fs the mode to set this window to - true for full screen, false for windowed mode
* @return true if full screen exclusive mode is supported, false if not.
*/
- public boolean setFullscreen(boolean fs) {
+ public boolean setFullscreen(final boolean fs) {
//TODO: fix to make double-buffered and return to non-fs mode properly (use initComponents()?)
- GraphicsDevice dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
- boolean visible = this.isVisible();
+ final GraphicsDevice dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ final boolean visible = this.isVisible();
if (fs) {
this.dispose();
this.setUndecorated(true);
this.setResizable(false);
try{
dev.setFullScreenWindow(this);
- } catch (Exception e) {
+ } catch (final Exception e) {
dev.setFullScreenWindow(null);
e.printStackTrace();
JOptionPane.showMessageDialog(this,"Could not enter fullscreen exclusive mode.","Fullscreen error",JOptionPane.ERROR_MESSAGE);
@@ -259,9 +275,9 @@ public class GLJFrame extends JFrame { * @param width the new horizontal size for the GLCanvass in pixels
* @param height the new vertical size for the GLCanvass in pixels
*/
- public void setSize(int width, int height) {
-
- java.awt.GraphicsDevice dev = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ public void setSize(final int width, final int height) {
+
+ final java.awt.GraphicsDevice dev = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if (dev.getFullScreenWindow() != this) {
mainCanvas.setSize(width,height);
this.pack();
@@ -272,8 +288,8 @@ public class GLJFrame extends JFrame { * Resizes this GLJFrame to match a GLCanvas of the specified size. This has no effect if fullscreen mode is active.
* @param d the new size for the GLCanvass in pixels
*/
- public void setSize(java.awt.Dimension d) {
- java.awt.GraphicsDevice dev = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ public void setSize(final java.awt.Dimension d) {
+ final java.awt.GraphicsDevice dev = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if (dev.getFullScreenWindow() != this) {
mainCanvas.setSize(d);
this.pack();
@@ -284,7 +300,7 @@ public class GLJFrame extends JFrame { * @return true if this window is in fullscreen mode
*/
public boolean isFullscreen() {
- java.awt.GraphicsDevice dev = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ final java.awt.GraphicsDevice dev = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
return (dev.getFullScreenWindow() == this);
}
/**
@@ -298,41 +314,41 @@ public class GLJFrame extends JFrame { * Rebuilds the GLCanvas with the specified capbilities. Will dispose and re-create the JFrame and GLCanvas with the new capabilities.
* @param caps the capabilities to be copied into this GLJFrame
*/
- public void setGLCapabilities(GLCapabilities caps) {
+ public void setGLCapabilities(final GLCapabilities caps) {
//get old setup
- boolean vis = this.isVisible();
+ final boolean vis = this.isVisible();
this.caps = (GLCapabilities)caps.clone();
- boolean fs = this.isFullscreen();
- java.awt.Dimension d = this.mainCanvas.getSize();
-
+ final boolean fs = this.isFullscreen();
+ final java.awt.Dimension d = this.mainCanvas.getSize();
+
this.dispose();
-
+
//re-form canvas with new caps
this.mainCanvas = new GLCanvas(caps);
this.getContentPane().removeAll();
this.add(mainCanvas);
-
-
+
+
mainCanvas.setSize(d);
-
- GLCanvas glc = (GLCanvas) mainCanvas;
+
+ final GLCanvas glc = (GLCanvas) mainCanvas;
//re-apply GLEventListener
glc.addGLEventListener(listener);
//re-apply input listeners from the JPanel listeners
- for(InputMethodListener l : this.getInputMethodListeners())
+ for(final InputMethodListener l : this.getInputMethodListeners())
glc.addInputMethodListener(l);
- for(KeyListener l : this.getKeyListeners())
+ for(final KeyListener l : this.getKeyListeners())
glc.addKeyListener(l);
- for(MouseListener l : this.getMouseListeners())
+ for(final MouseListener l : this.getMouseListeners())
glc.addMouseListener(l);
- for(MouseMotionListener l : this.getMouseMotionListeners())
+ for(final MouseMotionListener l : this.getMouseMotionListeners())
glc.addMouseMotionListener(l);
- for(MouseWheelListener l : this.getMouseWheelListeners())
+ for(final MouseWheelListener l : this.getMouseWheelListeners())
glc.addMouseWheelListener(l);
-
+
this.setFullscreen(fs);
this.setVisible(vis);
-
+
}
/**
* Repaint the JFrame and render the GLCanvas if no animator is present. If animator is attached and running, only repaints the JFrame.
@@ -348,29 +364,29 @@ public class GLJFrame extends JFrame { * Removes InputMethodListeners, KeyListeners,MouseListeners, MouseMotionListeners, and MouseWheelListeners from this and the GLCanvas.
*/
public void clearInputListeners() {
- InputMethodListener[] imls = super.getInputMethodListeners();
- KeyListener[] kls = super.getKeyListeners();
- MouseListener[] mls = super.getMouseListeners();
- MouseMotionListener[] mmls = super.getMouseMotionListeners();
- MouseWheelListener[] mwls = super.getMouseWheelListeners();
- for(InputMethodListener l : imls) {
+ final InputMethodListener[] imls = super.getInputMethodListeners();
+ final KeyListener[] kls = super.getKeyListeners();
+ final MouseListener[] mls = super.getMouseListeners();
+ final MouseMotionListener[] mmls = super.getMouseMotionListeners();
+ final MouseWheelListener[] mwls = super.getMouseWheelListeners();
+ for(final InputMethodListener l : imls) {
mainCanvas.removeInputMethodListener(l);
super.removeInputMethodListener(l);
}
-
- for(KeyListener l : kls){
+
+ for(final KeyListener l : kls){
mainCanvas.removeKeyListener(l);
super.removeKeyListener(l);
}
- for(MouseListener l : mls){
+ for(final MouseListener l : mls){
mainCanvas.removeMouseListener(l);
super.removeMouseListener(l);
}
- for(MouseMotionListener l : mmls){
+ for(final MouseMotionListener l : mmls){
mainCanvas.removeMouseMotionListener(l);
super.removeMouseMotionListener(l);
}
- for(MouseWheelListener l : mwls){
+ for(final MouseWheelListener l : mwls){
mainCanvas.removeMouseWheelListener(l);
super.removeMouseWheelListener(l);
}
@@ -399,7 +415,7 @@ public class GLJFrame extends JFrame { * Specifies an {@link Animator} for updating the GLCanvas, and starts it.
* @param anim Animator to use to animate the GLCanvas
*/
- public void setAnimator(Animator anim) {
+ public void setAnimator(final Animator anim) {
this.setAnimator(anim,true);
}
/**
@@ -407,7 +423,7 @@ public class GLJFrame extends JFrame { * @param anim Animator to use to animate the GLCanvas
* @param start starts the animator if true, just sets it if not
*/
- public void setAnimator(Animator anim, boolean start) {
+ public void setAnimator(final Animator anim, final boolean start) {
if (this.animator != null) {
this.animator.stop();
this.animator.remove((GLCanvas)mainCanvas);
@@ -432,61 +448,61 @@ public class GLJFrame extends JFrame { public boolean isAnimated() {
return (animator!=null);
}
-
+
/**
* Removes the specified key listener so that it no longer receives key events from this component and the GLCanvas. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to this component. if the listener is null, no exception is thrown and no action is performed.
* @param l the key listener.
*/
- public void removeKeyListener(KeyListener l) {
+ public void removeKeyListener(final KeyListener l) {
super.removeKeyListener(l);
mainCanvas.removeKeyListener(l);
}
-
+
/**
* Adds the specified key listener to receive key events from this component and the GLCanvas. If l is null, no exception is thrown and no action is performed.
* @param l the key listener.
*/
- public void addKeyListener(KeyListener l) {
+ public void addKeyListener(final KeyListener l) {
super.addKeyListener(l);
mainCanvas.addKeyListener(l);
}
-
+
/**
* Removes the specified mouse listener so that it no longer receives mouse events from this component and the GLCanvas. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added. if the listener is null, no exception is thrown and no action is performed.
* @param l the mouse listener
*/
- public void removeMouseListener(MouseListener l) {
+ public void removeMouseListener(final MouseListener l) {
super.removeMouseListener(l);
mainCanvas.removeMouseListener(l);
}
-
+
/**
* Adds the specified mouse listener to receive mouse events from this component and the GLCanvas. if the listener is null, no exception is thrown and no action is performed.
* @param l the mouse listener
*/
- public void addMouseListener(MouseListener l) {
+ public void addMouseListener(final MouseListener l) {
super.addMouseListener(l);
mainCanvas.addMouseListener(l);
}
-
+
/**
* Removes the specified mouse wheel listener so that it no longer receives mouse wheel events from this component and the GLCanvas. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added. If l is null, no exception is thrown and no action is performed.
* @param l the mouse wheel listener
*/
- public void removeMouseWheelListener(MouseWheelListener l) {
+ public void removeMouseWheelListener(final MouseWheelListener l) {
super.removeMouseWheelListener(l);
mainCanvas.removeMouseWheelListener(l);
}
-
+
/**
* Removes the specified mouse motion listener so that it no longer receives mouse motion events from this component and the GLCanvas. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added. if the listener is null, no exception is thrown and no action is performed.
* @param l the mouse motion listener.
*/
- public void removeMouseMotionListener(MouseMotionListener l) {
+ public void removeMouseMotionListener(final MouseMotionListener l) {
super.removeMouseMotionListener(l);
mainCanvas.removeMouseMotionListener(l);
}
-
+
/**
*
* Adds the specified mouse wheel listener to receive mouse wheel events from this component and the GLCanvas.
@@ -496,34 +512,34 @@ public class GLJFrame extends JFrame { * If l is null, no exception is thrown and no action is performed.
* @param l the mouse wheel listener
*/
- public void addMouseWheelListener(MouseWheelListener l) {
+ public void addMouseWheelListener(final MouseWheelListener l) {
super.addMouseWheelListener(l);
mainCanvas.addMouseWheelListener(l);
}
-
+
/**
* Adds the specified mouse motion listener to receive mouse motion events from this component and the GLCanvas. if the listener is null, no exception is thrown and no action is performed.
* @param l the mouse motion listener.
*/
- public void addMouseMotionListener(MouseMotionListener l) {
+ public void addMouseMotionListener(final MouseMotionListener l) {
super.addMouseMotionListener(l);
mainCanvas.addMouseMotionListener(l);
}
-
+
/**
* Removes the specified input method listener so that it no longer receives input method events from this component and the GLCanvas. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added. if the listener is null, no exception is thrown and no action is performed.
* @param l the input method listener
*/
- public void removeInputMethodListener(java.awt.event.InputMethodListener l) {
+ public void removeInputMethodListener(final java.awt.event.InputMethodListener l) {
super.removeInputMethodListener(l);
mainCanvas.removeInputMethodListener(l);
}
-
+
/**
* Adds the specified input method listener to receive input method events from this component and the GLCanvas. A component will only receive input method events from input methods if it also overrides getInputMethodRequests to return an InputMethodRequests instance. if the listener is null, no exception is thrown and no action is performed.
* @param l the input method listener
*/
- public void addInputMethodListener(java.awt.event.InputMethodListener l) {
+ public void addInputMethodListener(final java.awt.event.InputMethodListener l) {
super.addInputMethodListener(l);
mainCanvas.addInputMethodListener(l);
}
@@ -540,7 +556,7 @@ public class GLJFrame extends JFrame { * @see javax.media.opengl.GLCanvas#setGL(javax.media.opengl.GL)
* @param gl The pipeline to attach to this GLCanvas
*/
- public void setGL(GL gl) {
+ public void setGL(final GL gl) {
((GLCanvas)mainCanvas).setGL(gl);
}
/**
@@ -551,7 +567,7 @@ public class GLJFrame extends JFrame { public GLContext getContext() {
return ((GLCanvas)mainCanvas).getContext();
}
-
+
/**
* Retrieves a GLAutoDrawable view of the associated GLCanvas
* @return a GLAutoDrawable corresponding to the GLCanvas on this GLJFrame
@@ -559,5 +575,5 @@ public class GLJFrame extends JFrame { public GLAutoDrawable getAutoDrawable() {
return (GLAutoDrawable)mainCanvas;
}
-
+
}
diff --git a/src/net/java/joglutils/JPanelDialog.java b/src/net/java/joglutils/JPanelDialog.java index 9c108b0..b10d654 100644 --- a/src/net/java/joglutils/JPanelDialog.java +++ b/src/net/java/joglutils/JPanelDialog.java @@ -35,9 +35,17 @@ */
package net.java.joglutils;
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JPanel;
/**
* This class is a basic encapsulation of a JPanel in a dialog.
diff --git a/src/net/java/joglutils/jogltext/FontDrawer.java b/src/net/java/joglutils/jogltext/FontDrawer.java index 866ab0e..5fa808f 100644 --- a/src/net/java/joglutils/jogltext/FontDrawer.java +++ b/src/net/java/joglutils/jogltext/FontDrawer.java @@ -36,12 +36,23 @@ package net.java.joglutils.jogltext;
-import java.awt.*;
-import java.awt.geom.*;
-import java.awt.font.*;
-import java.text.*;
-import javax.media.opengl.*;
-import javax.media.opengl.glu.*;
+import java.awt.Font;
+import java.awt.font.FontRenderContext;
+import java.awt.font.GlyphVector;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.PathIterator;
+import java.text.StringCharacterIterator;
+
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2;
+import com.jogamp.opengl.GL2ES3;
+import com.jogamp.opengl.GL2GL3;
+import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.opengl.glu.GLU;
+import com.jogamp.opengl.glu.GLUtessellator;
+import com.jogamp.opengl.glu.GLUtessellatorCallback;
+import com.jogamp.opengl.glu.GLUtessellatorCallbackAdapter;
/**
* This class renders a TrueType Font into OpenGL
@@ -51,22 +62,22 @@ import javax.media.opengl.glu.*; *@created January 29, 2004
*/
public class FontDrawer {
-
+
public enum NormalMode {NONE, FLAT, AVERAGED};
-
+
private Font font;
private float depth;
-
+
private boolean edgeOnly;
private NormalMode normalMode;
-
+
/**
- * Intstantiates a new FontDrawer initially rendering in the specified font.
- *
+ * Intstantiates a new FontDrawer initially rendering in the specified font.
+ *
* @param font the initial font for this FontDrawer
* @throws java.lang.NullPointerException if the supplied font is null
*/
- public FontDrawer(Font font) throws NullPointerException {
+ public FontDrawer(final Font font) throws NullPointerException {
if (font == null)
throw new NullPointerException("Can't use a null font to create a FontDrawer");
this.font = font;
@@ -74,18 +85,18 @@ public class FontDrawer { edgeOnly = false;
normalMode = NormalMode.FLAT;
}
-
+
/**
* Specifies which font to render with this FontDrawer
* @param font a font to use for rendering
** @throws java.lang.NullPointerException if the supplied font is null
*/
- public void setFont(Font font) throws NullPointerException {
+ public void setFont(final Font font) throws NullPointerException {
if (font == null)
throw new NullPointerException("Can't set a FontDrawer font to null");
this.font = font;
}
-
+
/**
* Retrieves the Font currently associated with this FontDrawer
* @return the Font in which this object renders strings
@@ -93,18 +104,18 @@ public class FontDrawer { public Font getFont() {
return this.font;
}
-
+
/**
* Determines how long the sides of the rendered text is. In the special case of 0, the rendering is 2D.
* @param depth specifies the z-size of the rendered 3D text. Negative numbers will be set to 0.
*/
- public void setDepth(float depth) {
+ public void setDepth(final float depth) {
if (depth <= 0)
this.depth = 0;
else
this.depth = depth;
}
-
+
/**
* Retrieves the z-depth used for this FontDrawer's text rendering.
* @return the z-depth of the rendered 3D text.
@@ -112,15 +123,15 @@ public class FontDrawer { public float getDepth() {
return this.depth;
}
-
+
/**
* Sets if the text should be rendered as filled polygons or wireframe.
* @param fill if true, uses filled polygons, if false, renderings are wireframe.
*/
- public void setFill(boolean fill) {
+ public void setFill(final boolean fill) {
this.edgeOnly = !fill;
}
-
+
/**
* Determines if the text is being rendered as filled polygons or wireframes.
* @return if true, uses filled polygons, if false, renderings are wireframe.
@@ -128,7 +139,7 @@ public class FontDrawer { public boolean isFill() {
return !this.edgeOnly;
}
-
+
/**
* Sets technique for rendering Normals. Available options:
* None: Performs no calls to glNormal* - best performance
@@ -137,10 +148,10 @@ public class FontDrawer { *
* @param mode the mode to render in. Default is flat.
*/
- public void setNormal( NormalMode mode ) {
+ public void setNormal( final NormalMode mode ) {
this.normalMode = mode;
}
-
+
/**
* Determines which normal-calculation technique is being used.
* @see setNormal
@@ -149,18 +160,18 @@ public class FontDrawer { public NormalMode getNormal() {
return this.normalMode;
}
-
+
/**
- * Renders a string into the specified GL object, starting at the (0,0,0) point in OpenGL coordinates.
+ * Renders a string into the specified GL object, starting at the (0,0,0) point in OpenGL coordinates.
* Note that this creates a new GLU instance everytime it is called, which will negatively impact performance.
*
* @param str the string to render.
* @param gl the OpenGL context in which to render the text.
*/
- public void drawString(String str, GL2 gl) {
+ public void drawString(final String str, final GL2 gl) {
drawString(str,new GLU(),gl);
}
-
+
/**
* Renders a string into the specified GL object, starting at the (0,0,0) point in OpenGL coordinates.
*
@@ -168,13 +179,13 @@ public class FontDrawer { * @param glu a GLU instance to use for the text rendering (provided to prevent continuous re-instantiation of a GLU object)
* @param gl the OpenGL context in which to render the text.
*/
- public void drawString(String str, GLU glu, GL2 gl) {
- GlyphVector gv = font.createGlyphVector(
+ public void drawString(final String str, final GLU glu, final GL2 gl) {
+ final GlyphVector gv = font.createGlyphVector(
new FontRenderContext(new AffineTransform(), true, true),
new StringCharacterIterator(str));
- GeneralPath gp = (GeneralPath)gv.getOutline();
+ final GeneralPath gp = (GeneralPath)gv.getOutline();
PathIterator pi = gp.getPathIterator(AffineTransform.getScaleInstance(1.0, -1.0), 1.0f);
-
+
if (this.normalMode != NormalMode.NONE)
gl.glNormal3f(0,0,-1.0f);
tesselateFace(glu, gl, pi, pi.getWindingRule(), this.edgeOnly);
@@ -196,14 +207,14 @@ public class FontDrawer { drawSidesAvgNorm(gl,pi,this.edgeOnly,this.depth);
break;
}
-
+
}
-
+
}
-
+
/**
* Renders a string into the specified GL object, starting at the (xOff,yOff,zOff) point in OpenGL coordinates.
- * Note that this creates a new GLU instance everytime it is called, which will negatively impact performance.
+ * Note that this creates a new GLU instance everytime it is called, which will negatively impact performance.
*
* @param xOff the distance to translate the text in the x-direction
* @param yOff the distance to translate the text in the y-direction
@@ -211,13 +222,13 @@ public class FontDrawer { * @param str the string to render.
* @param gl the OpenGL context in which to render the text.
*/
- public void drawString(String str, GL2 gl, float xOff, float yOff, float zOff) {
+ public void drawString(final String str, final GL2 gl, final float xOff, final float yOff, final float zOff) {
drawString(str,new GLU(),gl,xOff,yOff,zOff);
}
-
+
/**
* Renders a string into the specified GL object, starting at the (xOff,yOff,zOff) point in OpenGL coordinates.
- *
+ *
* @param xOff the distance to translate the text in the x-direction
* @param yOff the distance to translate the text in the y-direction
* @param zOff the distance to translate the text in the z-direction
@@ -225,80 +236,80 @@ public class FontDrawer { * @param glu a GLU instance to use for the text rendering (provided to prevent continuous re-instantiation of a GLU object)
* @param gl the OpenGL context in which to render the text.
*/
- public void drawString(String str, GLU glu, GL2 gl, float xOff, float yOff, float zOff) {
+ public void drawString(final String str, final GLU glu, final GL2 gl, final float xOff, final float yOff, final float zOff) {
gl.glPushAttrib(GL2.GL_TRANSFORM_BIT);
- gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glPushMatrix();
gl.glTranslatef(xOff,yOff,zOff);
this.drawString(str,glu,gl);
gl.glPopMatrix();
gl.glPopAttrib();
}
-
- private void tesselateFace(GLU glu, GL2 gl, PathIterator pi, int windingRule, boolean justBoundary) {
+
+ private void tesselateFace(final GLU glu, final GL2 gl, final PathIterator pi, final int windingRule, final boolean justBoundary) {
tesselateFace(glu,gl,pi,windingRule,justBoundary,0);
}
-
- private void tesselateFace(GLU glu, GL2 gl, PathIterator pi, int windingRule, boolean justBoundary,double tessZ) {
- GLUtessellatorCallback aCallback = new GLUtesselatorCallbackImpl(gl);
- GLUtessellator tess = glu.gluNewTess();
-
- glu.gluTessCallback(tess, GLU.GLU_TESS_BEGIN, aCallback);
- glu.gluTessCallback(tess, GLU.GLU_TESS_END, aCallback);
- glu.gluTessCallback(tess, GLU.GLU_TESS_ERROR, aCallback);
- glu.gluTessCallback(tess, GLU.GLU_TESS_VERTEX, aCallback);
- glu.gluTessCallback(tess, GLU.GLU_TESS_COMBINE, aCallback);
-
- glu.gluTessNormal(tess, 0.0, 0.0, -1.0);
-
+
+ private void tesselateFace(final GLU glu, final GL2 gl, final PathIterator pi, final int windingRule, final boolean justBoundary,final double tessZ) {
+ final GLUtessellatorCallback aCallback = new GLUtesselatorCallbackImpl(gl);
+ final GLUtessellator tess = GLU.gluNewTess();
+
+ GLU.gluTessCallback(tess, GLU.GLU_TESS_BEGIN, aCallback);
+ GLU.gluTessCallback(tess, GLU.GLU_TESS_END, aCallback);
+ GLU.gluTessCallback(tess, GLU.GLU_TESS_ERROR, aCallback);
+ GLU.gluTessCallback(tess, GLU.GLU_TESS_VERTEX, aCallback);
+ GLU.gluTessCallback(tess, GLU.GLU_TESS_COMBINE, aCallback);
+
+ GLU.gluTessNormal(tess, 0.0, 0.0, -1.0);
+
switch (windingRule) {
case PathIterator.WIND_EVEN_ODD:
- glu.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_ODD);
+ GLU.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_ODD);
break;
case PathIterator.WIND_NON_ZERO:
- glu.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
+ GLU.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
break;
}
-
+
if (justBoundary) {
- glu.gluTessProperty(tess, GLU.GLU_TESS_BOUNDARY_ONLY, GL2.GL_TRUE);
+ GLU.gluTessProperty(tess, GLU.GLU_TESS_BOUNDARY_ONLY, GL.GL_TRUE);
} else {
- glu.gluTessProperty(tess, GLU.GLU_TESS_BOUNDARY_ONLY, GL2.GL_FALSE);
+ GLU.gluTessProperty(tess, GLU.GLU_TESS_BOUNDARY_ONLY, GL.GL_FALSE);
}
-
- glu.gluTessBeginPolygon(tess, (double[])null);
-
+
+ GLU.gluTessBeginPolygon(tess, (double[])null);
+
for (; !pi.isDone(); pi.next()) {
- double[] coords = new double[3];
+ final double[] coords = new double[3];
coords[2] = tessZ;
-
+
switch (pi.currentSegment(coords)) {
case PathIterator.SEG_MOVETO:
- glu.gluTessBeginContour(tess);
+ GLU.gluTessBeginContour(tess);
break;
case PathIterator.SEG_LINETO:
- glu.gluTessVertex(tess, coords, 0, coords);
+ GLU.gluTessVertex(tess, coords, 0, coords);
break;
case PathIterator.SEG_CLOSE:
- glu.gluTessEndContour(tess);
+ GLU.gluTessEndContour(tess);
break;
}
}
- glu.gluTessEndPolygon(tess);
-
- glu.gluDeleteTess(tess);
+ GLU.gluTessEndPolygon(tess);
+
+ GLU.gluDeleteTess(tess);
}
-
- private void drawSidesNoNorm(GL2 gl, PathIterator pi, boolean justBoundary,float tessZ) {
+
+ private void drawSidesNoNorm(final GL2 gl, final PathIterator pi, final boolean justBoundary,final float tessZ) {
//TODO: texture coords
-
+
if (justBoundary)
- gl.glPolygonMode(GL2.GL_FRONT_AND_BACK,GL2.GL_LINE);
+ gl.glPolygonMode(GL.GL_FRONT_AND_BACK,GL2GL3.GL_LINE);
else
- gl.glPolygonMode(GL2.GL_FRONT_AND_BACK,GL2.GL_FILL);
-
- for(float[] coords = new float[6];!pi.isDone();pi.next()) {
- float[] currRender = new float[3];
+ gl.glPolygonMode(GL.GL_FRONT_AND_BACK,GL2GL3.GL_FILL);
+
+ for(final float[] coords = new float[6];!pi.isDone();pi.next()) {
+ final float[] currRender = new float[3];
switch(pi.currentSegment(coords)) {
case PathIterator.SEG_MOVETO:
gl.glBegin(GL2.GL_QUAD_STRIP);
@@ -331,21 +342,21 @@ public class FontDrawer { }
}
}
-
- private void drawSidesFlatNorm(GL2 gl, PathIterator pi, boolean justBoundary,float tessZ) {
+
+ private void drawSidesFlatNorm(final GL2 gl, final PathIterator pi, final boolean justBoundary,final float tessZ) {
//TODO: texture coords
-
+
if (justBoundary)
- gl.glPolygonMode(GL2.GL_FRONT_AND_BACK,GL2.GL_LINE);
+ gl.glPolygonMode(GL.GL_FRONT_AND_BACK,GL2GL3.GL_LINE);
else
- gl.glPolygonMode(GL2.GL_FRONT_AND_BACK,GL2.GL_FILL);
-
- float[] lastCoord = new float[3];
- float[] firstCoord = new float[3];
- for(float[] coords = new float[6];!pi.isDone();pi.next()) {
+ gl.glPolygonMode(GL.GL_FRONT_AND_BACK,GL2GL3.GL_FILL);
+
+ final float[] lastCoord = new float[3];
+ final float[] firstCoord = new float[3];
+ for(final float[] coords = new float[6];!pi.isDone();pi.next()) {
switch(pi.currentSegment(coords)) {
case PathIterator.SEG_MOVETO:
- gl.glBegin(GL2.GL_QUADS);
+ gl.glBegin(GL2ES3.GL_QUADS);
lastCoord[0] = coords[0];
lastCoord[1] = coords[1];
firstCoord[0] = coords[0];
@@ -362,7 +373,7 @@ public class FontDrawer { gl.glVertex3fv(coords,0);
coords[2] = 0;
gl.glVertex3fv(coords,0);
-
+
lastCoord[0] = coords[0];
lastCoord[1] = coords[1];
break;
@@ -384,25 +395,25 @@ public class FontDrawer { }
}
}
-
-
- private void drawSidesAvgNorm(GL2 gl, PathIterator pi, boolean justBoundary,float tessZ) {
+
+
+ private void drawSidesAvgNorm(final GL2 gl, final PathIterator pi, final boolean justBoundary,final float tessZ) {
//TODO: improve performance with some form of caching?
//TODO: texture coords
//TODO: check last coord - might not quite be correct?
-
+
if (justBoundary)
- gl.glPolygonMode(GL2.GL_FRONT_AND_BACK,GL2.GL_LINE);
+ gl.glPolygonMode(GL.GL_FRONT_AND_BACK,GL2GL3.GL_LINE);
else
- gl.glPolygonMode(GL2.GL_FRONT_AND_BACK,GL2.GL_FILL);
-
-
+ gl.glPolygonMode(GL.GL_FRONT_AND_BACK,GL2GL3.GL_FILL);
+
+
float[] firstCoord = null;
float[] secondCoord = null;
float[] thirdCoord = null;
float[] twoBackCoord = null;
float[] oneBackCoord = null;
- for(float[] coords = new float[6];!pi.isDone();pi.next()) {
+ for(final float[] coords = new float[6];!pi.isDone();pi.next()) {
switch(pi.currentSegment(coords)) {
case PathIterator.SEG_MOVETO:
firstCoord = new float[3];
@@ -418,20 +429,20 @@ public class FontDrawer { twoBackCoord = firstCoord.clone();
oneBackCoord = secondCoord.clone();
} else {
- float avgdeltax = oneBackCoord[0] - twoBackCoord[0] + coords[0] - oneBackCoord[0];
- float avgdeltay = oneBackCoord[1] - twoBackCoord[1] + coords[1] - oneBackCoord[1];
+ final float avgdeltax = oneBackCoord[0] - twoBackCoord[0] + coords[0] - oneBackCoord[0];
+ final float avgdeltay = oneBackCoord[1] - twoBackCoord[1] + coords[1] - oneBackCoord[1];
if (thirdCoord == null) {
thirdCoord = new float[3];
thirdCoord[0] = coords[0];
thirdCoord[1] = coords[1];
-
+
}
gl.glNormal3f(-avgdeltay,avgdeltax,0);
oneBackCoord[2] = 0.0f;
gl.glVertex3fv(oneBackCoord,0);
oneBackCoord[2] = tessZ;
gl.glVertex3fv(oneBackCoord,0);
-
+
//copy to not have to recreate
twoBackCoord[0] = oneBackCoord[0];
twoBackCoord[1] = oneBackCoord[1];
@@ -447,7 +458,7 @@ public class FontDrawer { gl.glVertex3fv(oneBackCoord,0);
oneBackCoord[2] = tessZ;
gl.glVertex3fv(oneBackCoord,0);
-
+
avgdeltax = firstCoord[0] - oneBackCoord[0] + secondCoord[0] - firstCoord[0];
avgdeltay = firstCoord[1] - oneBackCoord[1] + secondCoord[1] - firstCoord[1];
gl.glNormal3f(-avgdeltay,avgdeltax,0);
@@ -455,7 +466,7 @@ public class FontDrawer { gl.glVertex3fv(firstCoord,0);
firstCoord[2] = tessZ;
gl.glVertex3fv(firstCoord,0);
-
+
avgdeltax = secondCoord[0] - firstCoord[0] + thirdCoord[0] - secondCoord[0];
avgdeltay = secondCoord[1] - firstCoord[1] + thirdCoord[1] - secondCoord[1];
gl.glNormal3f(-avgdeltay,avgdeltax,0);
@@ -463,7 +474,7 @@ public class FontDrawer { gl.glVertex3fv(secondCoord,0);
secondCoord[2] = tessZ;
gl.glVertex3fv(secondCoord,0);
-
+
gl.glEnd();
firstCoord = null;
secondCoord = null;
@@ -476,24 +487,24 @@ public class FontDrawer { }
}
}
-
- private class GLUtesselatorCallbackImpl extends javax.media.opengl.glu.GLUtessellatorCallbackAdapter {
- private GL2 gl;
-
- public GLUtesselatorCallbackImpl(GL2 gl) {
+
+ private class GLUtesselatorCallbackImpl extends GLUtessellatorCallbackAdapter {
+ private final GL2 gl;
+
+ public GLUtesselatorCallbackImpl(final GL2 gl) {
this.gl = gl;
}
-
- public void begin(int type) {
+
+ public void begin(final int type) {
gl.glBegin(type);
}
-
- public void vertex(java.lang.Object vertexData) {
- double[] coords = (double[])vertexData;
-
+
+ public void vertex(final java.lang.Object vertexData) {
+ final double[] coords = (double[])vertexData;
+
gl.glVertex3dv(coords,0);
}
-
+
public void end() {
gl.glEnd();
}
diff --git a/src/net/java/joglutils/jogltext/TextRenderer3D.java b/src/net/java/joglutils/jogltext/TextRenderer3D.java index ec78ba9..53ad967 100644 --- a/src/net/java/joglutils/jogltext/TextRenderer3D.java +++ b/src/net/java/joglutils/jogltext/TextRenderer3D.java @@ -32,8 +32,8 @@ * You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
- *
+ *
+ *
* Cleaned up, added correct normal calculations and removed extraneous stuff.
* Also modified method signatures to match, as closely as reasonable, those
* of TextRenderer. Also added support for compiling the shapes to display lists
@@ -55,13 +55,21 @@ import java.text.StringCharacterIterator; import java.util.ArrayList;
import java.util.Iterator;
-import javax.media.opengl.*;
-import javax.media.opengl.glu.*;
-import javax.vecmath.Vector3f;
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2;
+import com.jogamp.opengl.GL2ES3;
+import com.jogamp.opengl.GL2GL3;
+import com.jogamp.opengl.fixedfunc.GLLightingFunc;
+import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.opengl.glu.GLU;
+import com.jogamp.opengl.glu.GLUtessellator;
+import com.jogamp.opengl.glu.GLUtessellatorCallback;
+import com.jogamp.opengl.glu.GLUtessellatorCallbackAdapter;
+import com.jogamp.opengl.math.VectorUtil;
/**
* This class renders a TrueType Font into OpenGL
- *
+ *
* @author Davide Raccagni
* @author Erik Tollerud
* @created January 29, 2004
@@ -76,43 +84,43 @@ public class TextRenderer3D private boolean calcNormals = true;;
private float flatness = 0.0001f;
-
- private Vector3f vecA = new Vector3f();
- private Vector3f vecB = new Vector3f();
- private Vector3f normal = new Vector3f();
- private GLU glu = new GLU();
- private GL2 gl = GLU.getCurrentGL().getGL2();
+ private final float[] vecA = new float[3];
+ private final float[] vecB = new float[3];
+ private final float[] normal = new float[3];
+
+ private final GLU glu = new GLU();
+ private final GL2 gl = GLU.getCurrentGL().getGL2();
private int lastIndex = -1;
- private ArrayList<Integer> listIndex = new ArrayList<Integer>();
+ private final ArrayList<Integer> listIndex = new ArrayList<Integer>();
/**
* Intstantiates a new TextRenderer3D initially rendering in the specified
* font.
- *
+ *
* @param font - the initial font for this TextRenderer3D
* depth - the extruded depth for the font
* @throws java.lang.NullPointerException
* if the supplied font is null
*/
- public TextRenderer3D(Font font, float depth) throws NullPointerException
+ public TextRenderer3D(final Font font, final float depth) throws NullPointerException
{
if (font == null)
throw new NullPointerException("Can't use a null font to create a TextRenderer3D");
this.font = font;
this.depth = depth;
}
-
+
/**
* Specifies which font to render with this TextRenderer3D
- *
+ *
* @param font
* a font to use for rendering *
* @throws java.lang.NullPointerException
* if the supplied font is null
*/
- public void setFont(Font font) throws NullPointerException
+ public void setFont(final Font font) throws NullPointerException
{
if (font == null)
throw new NullPointerException("Can't set a TextRenderer3D font to null");
@@ -121,7 +129,7 @@ public class TextRenderer3D /**
* Retrieves the Font currently associated with this TextRenderer3D
- *
+ *
* @return the Font in which this object renders strings
*/
public Font getFont()
@@ -132,12 +140,12 @@ public class TextRenderer3D /**
* Determines how long the sides of the rendered text is. In the special
* case of 0, the rendering is 2D.
- *
+ *
* @param depth
* specifies the z-size of the rendered 3D text. Negative numbers
* will be set to 0.
*/
- public void setDepth(float depth)
+ public void setDepth(final float depth)
{
if (depth <= 0)
this.depth = 0;
@@ -147,7 +155,7 @@ public class TextRenderer3D /**
* Retrieves the z-depth used for this TextRenderer3D's text rendering.
- *
+ *
* @return the z-depth of the rendered 3D text.
*/
public float getDepth()
@@ -157,12 +165,12 @@ public class TextRenderer3D /**
* Sets if the text should be rendered as filled polygons or wireframe.
- *
+ *
* @param fill
* if true, uses filled polygons, if false, renderings are
* wireframe.
*/
- public void setFill(boolean fill)
+ public void setFill(final boolean fill)
{
this.edgeOnly = !fill;
}
@@ -170,7 +178,7 @@ public class TextRenderer3D /**
* Determines if the text is being rendered as filled polygons or
* wireframes.
- *
+ *
* @return if true, uses filled polygons, if false, renderings are
* wireframe.
*/
@@ -181,7 +189,7 @@ public class TextRenderer3D /**
* Set the flatness to which the glyph's curves will be flattened
- *
+ *
* @return
*/
public float getFlatness()
@@ -191,28 +199,28 @@ public class TextRenderer3D /**
* Get the current flatness to which the glyph's curves will be flattened
- *
+ *
* @return
*/
- public void setFlatness(float flatness)
+ public void setFlatness(final float flatness)
{
this.flatness = flatness;
}
-
+
/**
* Sets whether the normals will eb calculated for each face
- *
+ *
* @param mode
* the mode to render in. Default is flat.
*/
- public void setCalcNormals( boolean normals)
+ public void setCalcNormals( final boolean normals)
{
this.calcNormals = normals;
}
/**
* Gets whether normals are being calculated
- *
+ *
* @see setNormal
* @return the normal technique for this TextRenderer3D.
*/
@@ -221,26 +229,26 @@ public class TextRenderer3D return this.calcNormals;
}
- public void draw( String str, float xOff, float yOff, float zOff, float scaleFactor )
+ public void draw( final String str, final float xOff, final float yOff, final float zOff, final float scaleFactor )
{
gl.glPushAttrib(GL2.GL_TRANSFORM_BIT);
- gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glPushMatrix();
- gl.glEnable( GL2.GL_NORMALIZE);
-
+ gl.glEnable( GLLightingFunc.GL_NORMALIZE);
+
gl.glScalef(scaleFactor, scaleFactor, scaleFactor);
gl.glTranslatef(xOff, yOff, zOff);
-
+
this.draw(str);
-
+
gl.glPopMatrix();
gl.glPopAttrib();
}
-
+
/**
* Renders a string into the specified GL object, starting at the (0,0,0)
* point in OpenGL coordinates.
- *
+ *
* @param str
* the string to render.
* @param glu
@@ -249,76 +257,76 @@ public class TextRenderer3D * @param gl
* the OpenGL context in which to render the text.
*/
- public void draw( String str )
+ public void draw( final String str )
{
- GlyphVector gv = font.createGlyphVector(new FontRenderContext(new AffineTransform(), true, true),
+ final GlyphVector gv = font.createGlyphVector(new FontRenderContext(new AffineTransform(), true, true),
new StringCharacterIterator(str));
- GeneralPath gp = (GeneralPath) gv.getOutline();
+ final GeneralPath gp = (GeneralPath) gv.getOutline();
PathIterator pi = gp.getPathIterator(AffineTransform.getScaleInstance(1.0, -1.0), flatness);
// dumpShape(gl, gp);
-
+
if (calcNormals)
gl.glNormal3f(0, 0, -1.0f);
-
+
tesselateFace(glu, gl, pi, this.edgeOnly, 0.0f);
-
+
if (this.depth != 0.0)
{
pi = gp.getPathIterator(AffineTransform.getScaleInstance(1.0, -1.0), flatness);
-
+
if (calcNormals)
gl.glNormal3f(0, 0, 1.0f);
-
+
tesselateFace(glu, gl, pi, this.edgeOnly, this.depth);
-
+
pi = gp.getPathIterator(AffineTransform.getScaleInstance(1.0, -1.0), flatness);
-
+
// TODO: add diagonal corner/VBO technique
drawSides(gl, pi, this.edgeOnly, this.depth);
}
- }
+ }
/**
- * Creates the specified string as a display list. Can subsequently be drawn
+ * Creates the specified string as a display list. Can subsequently be drawn
* by calling "call".
- *
+ *
* @param str
* @param xOff
* @param yOff
* @param zOff
* @param scaleFactor
*/
- public int compile( String str, float xOff, float yOff, float zOff, float scaleFactor )
- {
- int index = gl.glGenLists(1);
+ public int compile( final String str, final float xOff, final float yOff, final float zOff, final float scaleFactor )
+ {
+ final int index = gl.glGenLists(1);
gl.glNewList( index, GL2.GL_COMPILE);
draw( str, xOff, yOff, zOff, scaleFactor);
gl.glEndList();
-
+
listIndex.add(index);
return index;
}
-
+
/**
- * Creates the specified string as a display list. Can subsequently be drawn
+ * Creates the specified string as a display list. Can subsequently be drawn
* by calling "call".
- *
+ *
* @param str
*/
- public int compile( String str )
- {
- int index = gl.glGenLists(1);
+ public int compile( final String str )
+ {
+ final int index = gl.glGenLists(1);
gl.glNewList( index, GL2.GL_COMPILE);
draw( str );
gl.glEndList();
-
+
listIndex.add(index);
-
+
return index;
}
-
+
/**
* Draws the current compiled string, if any.
*
@@ -328,41 +336,41 @@ public class TextRenderer3D if (lastIndex != -1)
gl.glCallList(this.lastIndex);
}
-
+
/**
* Draws the specified compiled string, if any.
*
*/
- public void call( int index )
+ public void call( final int index )
{
gl.glCallList( index );
}
-
+
/**
* Diposes of the ALL the current compiled shapes, if any.
*
*/
public void dispose()
{
- for (Iterator iter = listIndex.iterator(); iter.hasNext();)
+ for (final Iterator iter = listIndex.iterator(); iter.hasNext();)
{
- int index = (Integer) iter.next();
+ final int index = (Integer) iter.next();
gl.glDeleteLists( index, 1);
}
-
+
lastIndex = -1;
}
-
+
/**
* Diposes of the specified compiled shapes, if it is in the list.
* If it is the last-compiled, that index is cleared (set to -1)
*
*/
- public void dispose( int index )
+ public void dispose( final int index )
{
- for (Iterator iter = listIndex.iterator(); iter.hasNext();)
+ for (final Iterator iter = listIndex.iterator(); iter.hasNext();)
{
- int i = (Integer) iter.next();
+ final int i = (Integer) iter.next();
if (i == index)
{
gl.glDeleteLists( index, 1);
@@ -372,69 +380,69 @@ public class TextRenderer3D }
}
}
-
+
/**
* Get the bounding box for the supplied string with the current font, etc.
- *
+ *
* @param str
* @return
*/
- public Rectangle2D getBounds( String str )
+ public Rectangle2D getBounds( final String str )
{
- GlyphVector gv = font.createGlyphVector(new FontRenderContext(new AffineTransform(), true, true),
+ final GlyphVector gv = font.createGlyphVector(new FontRenderContext(new AffineTransform(), true, true),
new StringCharacterIterator(str));
- GeneralPath gp = (GeneralPath) gv.getOutline();
-
+ final GeneralPath gp = (GeneralPath) gv.getOutline();
+
return gp.getBounds2D();
- }
-
+ }
+
/**
- * Get the bounding box for the supplied string for the current font and
+ * Get the bounding box for the supplied string for the current font and
* specified scale factor.
- *
+ *
* @param str
* @param scaleFactor
* @return
*/
- public Rectangle2D getBounds( String str, float scaleFactor )
+ public Rectangle2D getBounds( final String str, final float scaleFactor )
{
gl.glPushAttrib(GL2.GL_TRANSFORM_BIT);
- gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glPushMatrix();
-
+
gl.glScalef(scaleFactor, scaleFactor, scaleFactor);
-
- GlyphVector gv = font.createGlyphVector(new FontRenderContext(new AffineTransform(), true, true),
+
+ final GlyphVector gv = font.createGlyphVector(new FontRenderContext(new AffineTransform(), true, true),
new StringCharacterIterator(str));
- GeneralPath gp = (GeneralPath) gv.getOutline();
+ final GeneralPath gp = (GeneralPath) gv.getOutline();
- Rectangle2D rect = gp.getBounds2D();
+ final Rectangle2D rect = gp.getBounds2D();
gl.glPopMatrix();
- gl.glPopAttrib();
-
+ gl.glPopAttrib();
+
return rect;
- }
-
+ }
+
// construct the sides of each glyph by walking around and extending each vertex
// out to the depth of the extrusion
- private void drawSides(GL2 gl, PathIterator pi, boolean justBoundary, float depth)
+ private void drawSides(final GL2 gl, final PathIterator pi, final boolean justBoundary, final float depth)
{
if (justBoundary)
- gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE);
+ gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE);
else
- gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL);
+ gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
+
+ final float[] lastCoord = new float[3];
+ final float[] firstCoord = new float[3];
+ final float[] coords = new float[6];
- float[] lastCoord = new float[3];
- float[] firstCoord = new float[3];
- float[] coords = new float[6];
-
while ( !pi.isDone() )
{
switch (pi.currentSegment(coords))
{
case PathIterator.SEG_MOVETO:
- gl.glBegin(GL2.GL_QUADS);
+ gl.glBegin(GL2ES3.GL_QUADS);
lastCoord[0] = coords[0];
lastCoord[1] = coords[1];
firstCoord[0] = coords[0];
@@ -442,9 +450,9 @@ public class TextRenderer3D break;
case PathIterator.SEG_LINETO:
if (calcNormals)
- setNormal(gl, lastCoord[0]-coords[0], lastCoord[1]-coords[1], 0.0f,
+ setNormal(gl, lastCoord[0]-coords[0], lastCoord[1]-coords[1], 0.0f,
0.0f, 0.0f, depth);
-
+
lastCoord[2] = 0;
gl.glVertex3fv(lastCoord, 0);
lastCoord[2] = depth;
@@ -462,7 +470,7 @@ public class TextRenderer3D break;
case PathIterator.SEG_CLOSE:
if(calcNormals)
- setNormal(gl, lastCoord[0]-firstCoord[0], lastCoord[1]-firstCoord[1], 0.0f,
+ setNormal(gl, lastCoord[0]-firstCoord[0], lastCoord[1]-firstCoord[1], 0.0f,
0.0f, 0.0f, depth );
lastCoord[2] = 0;
@@ -479,90 +487,89 @@ public class TextRenderer3D throw new RuntimeException(
"PathIterator segment not SEG_MOVETO, SEG_LINETO, SEG_CLOSE; Inappropriate font.");
}
-
+
pi.next();
}
}
// simple convenience for calculating and setting the normal
- private void setNormal ( GL2 gl, float x1, float y1, float z1, float x2, float y2, float z2 )
+ private void setNormal ( final GL2 gl, final float x1, final float y1, final float z1, final float x2, final float y2, final float z2 )
{
- vecA.set( x1, y1, z1);
- vecB.set( x2, y2, z2);
- normal.cross( vecA, vecB );
- normal.normalize();
- gl.glNormal3f( normal.x, normal.y, normal.z );
+ vecA[0] = x1; vecA[1] = y1; vecA[2] = z1;
+ vecB[0] = x2; vecB[1] = y2; vecB[2] = z2;
+ final float[] normal = VectorUtil.normalizeVec3(VectorUtil.crossVec3(new float[3], vecA, vecB));
+ gl.glNormal3f( normal[0], normal[1], normal[2] );
}
// routine that tesselates the current set of glyphs
- private void tesselateFace(GLU glu, GL2 gl, PathIterator pi, boolean justBoundary, double tessZ)
+ private void tesselateFace(final GLU glu, final GL2 gl, final PathIterator pi, final boolean justBoundary, final double tessZ)
{
- GLUtessellatorCallback aCallback = new GLUtesselatorCallbackImpl(gl);
- GLUtessellator tess = glu.gluNewTess();
+ final GLUtessellatorCallback aCallback = new GLUtesselatorCallbackImpl(gl);
+ final GLUtessellator tess = GLU.gluNewTess();
- glu.gluTessCallback(tess, GLU.GLU_TESS_BEGIN, aCallback);
- glu.gluTessCallback(tess, GLU.GLU_TESS_END, aCallback);
- glu.gluTessCallback(tess, GLU.GLU_TESS_ERROR, aCallback);
- glu.gluTessCallback(tess, GLU.GLU_TESS_VERTEX, aCallback);
- glu.gluTessCallback(tess, GLU.GLU_TESS_COMBINE, aCallback);
+ GLU.gluTessCallback(tess, GLU.GLU_TESS_BEGIN, aCallback);
+ GLU.gluTessCallback(tess, GLU.GLU_TESS_END, aCallback);
+ GLU.gluTessCallback(tess, GLU.GLU_TESS_ERROR, aCallback);
+ GLU.gluTessCallback(tess, GLU.GLU_TESS_VERTEX, aCallback);
+ GLU.gluTessCallback(tess, GLU.GLU_TESS_COMBINE, aCallback);
- glu.gluTessNormal(tess, 0.0, 0.0, -1.0);
+ GLU.gluTessNormal(tess, 0.0, 0.0, -1.0);
if ( pi.getWindingRule() == PathIterator.WIND_EVEN_ODD)
- glu.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_ODD);
+ GLU.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_ODD);
else
- glu.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
-
+ GLU.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
+
if (justBoundary)
- glu.gluTessProperty(tess, GLU.GLU_TESS_BOUNDARY_ONLY, GL2.GL_TRUE);
+ GLU.gluTessProperty(tess, GLU.GLU_TESS_BOUNDARY_ONLY, GL.GL_TRUE);
else
- glu.gluTessProperty(tess, GLU.GLU_TESS_BOUNDARY_ONLY, GL2.GL_FALSE);
+ GLU.gluTessProperty(tess, GLU.GLU_TESS_BOUNDARY_ONLY, GL.GL_FALSE);
- glu.gluTessBeginPolygon(tess, (double[]) null);
+ GLU.gluTessBeginPolygon(tess, (double[]) null);
while (!pi.isDone())
{
- double[] coords = new double[3];
+ final double[] coords = new double[3];
coords[2] = tessZ;
switch (pi.currentSegment(coords))
{
case PathIterator.SEG_MOVETO:
- glu.gluTessBeginContour(tess);
+ GLU.gluTessBeginContour(tess);
break;
case PathIterator.SEG_LINETO:
- glu.gluTessVertex(tess, coords, 0, coords);
+ GLU.gluTessVertex(tess, coords, 0, coords);
break;
case PathIterator.SEG_CLOSE:
- glu.gluTessEndContour(tess);
+ GLU.gluTessEndContour(tess);
break;
}
-
+
pi.next();
}
- glu.gluTessEndPolygon(tess);
+ GLU.gluTessEndPolygon(tess);
- glu.gluDeleteTess(tess);
+ GLU.gluDeleteTess(tess);
}
// Private class that implements the required callbacks for the tesselator
- private class GLUtesselatorCallbackImpl extends javax.media.opengl.glu.GLUtessellatorCallbackAdapter
+ private class GLUtesselatorCallbackImpl extends GLUtessellatorCallbackAdapter
{
- private GL2 gl;
+ private final GL2 gl;
- public GLUtesselatorCallbackImpl(GL2 gl)
+ public GLUtesselatorCallbackImpl(final GL2 gl)
{
this.gl = gl;
}
- public void begin(int type)
+ public void begin(final int type)
{
gl.glBegin(type);
}
- public void vertex(java.lang.Object vertexData)
+ public void vertex(final java.lang.Object vertexData)
{
- double[] coords = (double[]) vertexData;
+ final double[] coords = (double[]) vertexData;
gl.glVertex3dv(coords, 0);
}
@@ -583,39 +590,39 @@ public class TextRenderer3D PathIterator pi = path.getPathIterator(AffineTransform.getScaleInstance(1.0, -1.0));
FlatteningPathIterator pif = new FlatteningPathIterator(pi, 0.005);
-
+
while ( !pif.isDone() )
{
int type = pif.currentSegment(coords);
dumpSegment(count++, coords, type );
-
+
pif.next();
}
}
private String Segment[] = { "MoveTo", "LineTo", "QuadTo", "CubicTo", "Close" };
private String Winding[] = { "EvenOdd", "NonZero" };
-
+
protected void dumpSegment( int num, float[] points, int type )
{
System.out.print(num + " " + Segment[type]);
-
+
switch(type)
{
case PathIterator.SEG_MOVETO:
case PathIterator.SEG_LINETO:
System.out.print(" " + points[0] + "," + points[1] );
break;
-
+
case PathIterator.SEG_QUADTO:
System.out.print(" " + points[0] + "," + points[1] + " " + points[2] + "," + points[3] );
break;
-
+
case PathIterator.SEG_CUBICTO:
System.out.print(" " + points[0] + "," + points[1] + " " + points[2] + "," + points[3] + " " + points[4] + "," + points[5] );
break;
}
-
+
System.out.println();
}
*/
diff --git a/src/net/java/joglutils/lighting/ColorButton.java b/src/net/java/joglutils/lighting/ColorButton.java index 51f7c92..4020448 100644 --- a/src/net/java/joglutils/lighting/ColorButton.java +++ b/src/net/java/joglutils/lighting/ColorButton.java @@ -36,9 +36,14 @@ package net.java.joglutils.lighting;
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.Action;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JColorChooser;
/**
*
diff --git a/src/net/java/joglutils/lighting/Light.java b/src/net/java/joglutils/lighting/Light.java index 07b780a..9ab2a07 100644 --- a/src/net/java/joglutils/lighting/Light.java +++ b/src/net/java/joglutils/lighting/Light.java @@ -36,10 +36,17 @@ package net.java.joglutils.lighting;
-import javax.media.opengl.*;
import java.awt.Color;
-import java.util.*;
-import java.nio.*;
+import java.nio.FloatBuffer;
+import java.util.HashMap;
+
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2;
+import com.jogamp.opengl.GL2ES1;
+import com.jogamp.opengl.GL2ES2;
+import com.jogamp.opengl.GLContext;
+import com.jogamp.opengl.fixedfunc.GLLightingFunc;
+import com.jogamp.opengl.glu.GLU;
/**
*
@@ -52,14 +59,14 @@ import java.nio.*; * @author Erik J. Tollerud
*/
public class Light {
-
+
static HashMap<GL,boolean[]> assignedLights = new HashMap<GL,boolean[]>();
static HashMap<GL,Boolean> shaderBuiltin = new HashMap<GL,Boolean>();
static HashMap<GL,Integer> shaderProgNums = new HashMap<GL,Integer>();
-
+
private GL2 attachedGL;
private int lightNumber;
-
+
//Light defaults are determined by constructor
private float[] ambient;
private float[] diffuse;
@@ -72,29 +79,29 @@ public class Light { private float constantAttenuation;
private float linearAttenuation;
private float quadraticAttenuation;
-
+
private boolean phongShaded;
private boolean phongDiffColorMat;
private boolean phongAmbColorMat;
-
-
+
+
/**
* Creates a new instance of Light with the default settings.
*/
public Light() {
attachedGL = null;
lightNumber = -1;
-
- float[] localAmb = {0.0f,0.0f,0.0f,1.0f};
+
+ final float[] localAmb = {0.0f,0.0f,0.0f,1.0f};
ambient = localAmb;
- float[] localDiff = {1.0f,1.0f,1.0f,1.0f};
+ final float[] localDiff = {1.0f,1.0f,1.0f,1.0f};
diffuse = localDiff;
- float[] localSpec = {1.0f,1.0f,1.0f,1.0f};
+ final float[] localSpec = {1.0f,1.0f,1.0f,1.0f};
specular = localSpec;
- float[] localPos = {0,0,1};
+ final float[] localPos = {0,0,1};
lightPosition = localPos;
lightW = 0;
- float[] localSpotDir = {0,0,-1};
+ final float[] localSpotDir = {0,0,-1};
spotDirection = localSpotDir;
spotCutoff= 180;
spotExponent = 0;
@@ -104,25 +111,25 @@ public class Light { phongShaded = false;
phongDiffColorMat = false;
phongAmbColorMat = false;
-
+
}
/**
* Creates a new instance of Light with default settings attached to the specified {@link GL} Context
* @param gl the OpenGL context to attach the light to
* @throws net.java.joglutils.lighting.LightingException if the light number is invalid or is already in use by another Light. Light is detached from any OpenGL Context.
*/
- public Light(GL2 gl) throws LightingException {
+ public Light(final GL2 gl) throws LightingException {
this();
-
+
this.attachedGL = gl;
- this.lightNumber = this.findAndAssignFreeLightNumber(gl);
+ this.lightNumber = Light.findAndAssignFreeLightNumber(gl);
if (this.lightNumber == -1) {
this.attachedGL = null;
throw new LightingException("No more Lights available in specified OpenGL context");
}
-
+
retrieve();
-
+
}
/**
* Creates a new instance of Light with default settings attached to the specified {@link GL} Context with an explicit light number
@@ -130,36 +137,36 @@ public class Light { * @param lightNumber the light number to be used (must be on [0,7])
* @throws net.java.joglutils.lighting.LightingException if the light number is invalid or is already in use by another Light. Light is detached from any OpenGL Context.
*/
- public Light(GL2 gl, int lightNumber) throws LightingException {
+ public Light(final GL2 gl, final int lightNumber) throws LightingException {
this();
if (lightNumber < 0 || lightNumber > maxNumberOfLightsInGL(gl))
throw new LightingException("Requested light not availible in specified OpenGL context");
-
+
this.attachedGL = gl;
- this.lightNumber = this.findAndAssignFreeLightNumber(gl);
+ this.lightNumber = Light.findAndAssignFreeLightNumber(gl);
if (this.lightNumber == -1) {
this.attachedGL = null;
throw new LightingException("No more Lights available in specified OpenGL context");
}
-
+
retrieve();
}
-
+
protected void finalize() {
//Must free light number if this Light is destroyed
if (this.attachedGL != null)
- this.unassignLightNumber(this.attachedGL,this.lightNumber);
+ Light.unassignLightNumber(this.attachedGL,this.lightNumber);
}
-
+
/**
* Determines the OpenGL light identifier associated with this Light. If no GL context is attached to this
* object, the result is undefined (although generally reflects the last light used)
* @return the OpenGL identifier for this light
*/
public int getGLLightIdentifier() {
- return this.numToID(this.lightNumber);
+ return Light.numToID(this.lightNumber);
}
-
+
/**
* Determines the number of the light associated with this Light. If no GL context is attached to this
* object, the result is undefined (although generally reflects the last light used)
@@ -173,50 +180,50 @@ public class Light { * @param lightNumber the light number to apply to this Light (must be on [0,7])
* @throws net.java.joglutils.lighting.LightingException in use by another Light object on the attached OpenGL Context. Light is detached from any OpenGL Context.
*/
- public void setLightNumber(int lightNumber) throws LightingException {
+ public void setLightNumber(final int lightNumber) throws LightingException {
if(lightNumber < 0 || lightNumber > 7)
throw new LightingException("Attempted to assign a light number that was not on [0,7]");
-
+
if (this.attachedGL != null) {
if(!isLightNumberFree(this.attachedGL,lightNumber))
throw new LightingException("Attempted to assign a light number that was not free on the attached OpenGL Context");
-
- this.unassignLightNumber(this.attachedGL,this.lightNumber);
- this.assignLightNumber(this.attachedGL,lightNumber);
+
+ Light.unassignLightNumber(this.attachedGL,this.lightNumber);
+ Light.assignLightNumber(this.attachedGL,lightNumber);
}
this.lightNumber = lightNumber;
}
-
+
/**
* Sets the OpenGL light to use in subsequent method calls from a GL identifier
* @param lightID the OpenGL light ID (must be of the GL_LIGHTn family)
* @throws net.java.joglutils.lighting.LightingException if the input is not a valid light or the light is in use by another Light on the attached OpenGL Context. Light is detached from any OpenGL Context.
*/
- public void setLightID(int lightID) throws LightingException {
- setLightNumber(this.idToNum(lightID));
+ public void setLightID(final int lightID) throws LightingException {
+ setLightNumber(Light.idToNum(lightID));
}
-
+
/**
* Attached the specified OpenGL context to this object
* @param gl the OpenGL context to attach this to
* @throws net.java.joglutils.lighting.LightingException if the specified context has no free lights. Light is detached from any OpenGL Context.
*/
- public void setAttachedGL(GL2 gl) throws LightingException {
- this.unassignLightNumber(this.attachedGL,this.lightNumber);
- if(!this.hasFreeLights(gl)) {
+ public void setAttachedGL(final GL2 gl) throws LightingException {
+ Light.unassignLightNumber(this.attachedGL,this.lightNumber);
+ if(!Light.hasFreeLights(gl)) {
this.attachedGL = null;
this.lightNumber = -1;
throw new LightingException("attempted to attach Light object to OpenGL Context with no free lights");
}
-
+
this.lightNumber = findAndAssignFreeLightNumber(gl);
this.attachedGL = gl;
if (this.phongShaded) {
- if(!this.shaderBuiltin.containsKey(gl))
- this.initializePhongShader(gl);
+ if(!Light.shaderBuiltin.containsKey(gl))
+ Light.initializePhongShader(gl);
}
}
-
+
/**
* Returns the OpenGL context attached to this Lighting object
* @return the attached OpenGL context, or null if there is no attached context
@@ -228,7 +235,7 @@ public class Light { * Detaches the currently attached OpenGL context from this object
*/
public void detachGL() {
- this.unassignLightNumber(this.attachedGL,this.lightNumber);
+ Light.unassignLightNumber(this.attachedGL,this.lightNumber);
this.attachedGL = null;
}
/**
@@ -240,15 +247,15 @@ public class Light { return false;
return true;
}
-
-
+
+
/**
* Applies the settings on this Light to the attached {@link GL} Context.
* Note that this will not apply Phong Shader settings.
*/
public void apply() {
apply(this.attachedGL,this.lightNumber);
-
+
}
/**
* Reconfigure the settings for this Light from the state of the attached
@@ -275,7 +282,7 @@ public class Light { * @param gl the OpenGL context to use.
* @throws net.java.joglutils.lighting.LightingException if the light number stored in this Light is invalid on the specified context.
*/
- public void apply(GL2 gl) throws LightingException {
+ public void apply(final GL2 gl) throws LightingException {
apply(gl,this.lightNumber);
}
/**
@@ -284,16 +291,16 @@ public class Light { * @param gl the OpenGL context to use.
* @throws net.java.joglutils.lighting.LightingException if the light number stored in this Light is invalid on the specified context.
*/
- public void retrieve(GL2 gl) throws LightingException {
+ public void retrieve(final GL2 gl) throws LightingException {
retrieve(gl,this.lightNumber);
-
+
}
/**
* Enables the light number stored in this Light on the specified OpenGL Context.
* @param gl the OpenGL context to use.
* @throws net.java.joglutils.lighting.LightingException if the light number stored in this Light is invalid on the specified context.
*/
- public void enable(GL2 gl) throws LightingException {
+ public void enable(final GL2 gl) throws LightingException {
enable(gl,this.lightNumber);
}
/**
@@ -301,7 +308,7 @@ public class Light { * @param gl the OpenGL context to use.
* @throws net.java.joglutils.lighting.LightingException if the light number stored in this Light is invalid on the specified context.
*/
- public void disable(GL2 gl) throws LightingException {
+ public void disable(final GL2 gl) throws LightingException {
disable(gl,this.lightNumber);
}
/**
@@ -311,31 +318,31 @@ public class Light { * @param lightNumber the number of the light to use (should be on [0,7]).
* @throws net.java.joglutils.lighting.LightingException if the requested light is not valid on the specified context.
*/
- public void apply(GL2 gl, int lightNumber) throws LightingException {
- if(!this.isLightNumberValid(gl, lightNumber))
+ public void apply(final GL2 gl, final int lightNumber) throws LightingException {
+ if(!Light.isLightNumberValid(gl, lightNumber))
throw new LightingException("attempted to apply Light settings to invalid lightNumber for the requested OpenGL context");
-
- int lightID = numToID(lightNumber);
-
+
+ final int lightID = numToID(lightNumber);
+
//set color components
- gl.glLightfv(lightID,GL2.GL_AMBIENT,ambient,0);
- gl.glLightfv(lightID,GL2.GL_DIFFUSE,diffuse,0);
- gl.glLightfv(lightID,GL2.GL_SPECULAR,specular,0);
+ gl.glLightfv(lightID,GLLightingFunc.GL_AMBIENT,ambient,0);
+ gl.glLightfv(lightID,GLLightingFunc.GL_DIFFUSE,diffuse,0);
+ gl.glLightfv(lightID,GLLightingFunc.GL_SPECULAR,specular,0);
//OpenGL position information is contanied in Light lightPosition and light distance
- float[] position = new float[4];
+ final float[] position = new float[4];
position[0] = lightPosition[0];
position[1] = lightPosition[1];
position[2] = lightPosition[2];
position[3] = lightW;
- gl.glLightfv(lightID,GL2.GL_POSITION,position,0);
+ gl.glLightfv(lightID,GLLightingFunc.GL_POSITION,position,0);
//set other parameters
- gl.glLightfv(lightID,GL2.GL_SPOT_DIRECTION,spotDirection,0);
- gl.glLightf(lightID,GL2.GL_SPOT_CUTOFF,spotCutoff);
- gl.glLightf(lightID,GL2.GL_SPOT_EXPONENT,spotExponent);
- gl.glLightf(lightID,GL2.GL_CONSTANT_ATTENUATION,constantAttenuation);
- gl.glLightf(lightID,GL2.GL_LINEAR_ATTENUATION,linearAttenuation);
- gl.glLightf(lightID,GL2.GL_QUADRATIC_ATTENUATION,quadraticAttenuation);
-
+ gl.glLightfv(lightID,GLLightingFunc.GL_SPOT_DIRECTION,spotDirection,0);
+ gl.glLightf(lightID,GLLightingFunc.GL_SPOT_CUTOFF,spotCutoff);
+ gl.glLightf(lightID,GLLightingFunc.GL_SPOT_EXPONENT,spotExponent);
+ gl.glLightf(lightID,GLLightingFunc.GL_CONSTANT_ATTENUATION,constantAttenuation);
+ gl.glLightf(lightID,GLLightingFunc.GL_LINEAR_ATTENUATION,linearAttenuation);
+ gl.glLightf(lightID,GLLightingFunc.GL_QUADRATIC_ATTENUATION,quadraticAttenuation);
+
this.lightNumber = lightNumber;
}
/**
@@ -345,39 +352,39 @@ public class Light { * @param lightNumber the number of the light to use (should be on [0,7]).
* @throws net.java.joglutils.lighting.LightingException if the requested light is not valid on the specified context.
*/
- public void retrieve(GL2 gl, int lightNumber) throws LightingException{
- if(!this.isLightNumberValid(gl, lightNumber))
+ public void retrieve(final GL2 gl, final int lightNumber) throws LightingException{
+ if(!Light.isLightNumberValid(gl, lightNumber))
throw new LightingException("attempted to retrieve Light settings to invalid lightNumber for the requested OpenGL context");
-
- int lightID = numToID(lightNumber);
- FloatBuffer buff = FloatBuffer.allocate(24);
-
+
+ final int lightID = numToID(lightNumber);
+ final FloatBuffer buff = FloatBuffer.allocate(24);
+
//get color components - 4 each
- gl.glGetLightfv(lightID,GL2.GL_AMBIENT,buff);
+ gl.glGetLightfv(lightID,GLLightingFunc.GL_AMBIENT,buff);
buff.get(this.ambient);
- gl.glGetLightfv(lightID,GL2.GL_DIFFUSE,buff);
+ gl.glGetLightfv(lightID,GLLightingFunc.GL_DIFFUSE,buff);
buff.get(this.diffuse);
- gl.glGetLightfv(lightID,GL2.GL_SPECULAR,buff);
+ gl.glGetLightfv(lightID,GLLightingFunc.GL_SPECULAR,buff);
buff.get(this.specular);
//get light position - 4 (including distance)
- gl.glGetLightfv(lightID,GL2.GL_POSITION,buff);
+ gl.glGetLightfv(lightID,GLLightingFunc.GL_POSITION,buff);
buff.get(this.lightPosition);
this.lightW = buff.get();
//get spot direction- 3
- gl.glGetLightfv(lightID,GL2.GL_SPOT_DIRECTION,buff);
+ gl.glGetLightfv(lightID,GLLightingFunc.GL_SPOT_DIRECTION,buff);
buff.get(this.spotDirection);
//get individual floats - 1 each
- gl.glGetLightfv(lightID,GL2.GL_SPOT_CUTOFF,buff);
+ gl.glGetLightfv(lightID,GLLightingFunc.GL_SPOT_CUTOFF,buff);
this.spotCutoff = buff.get();
- gl.glGetLightfv(lightID,GL2.GL_SPOT_EXPONENT,buff);
+ gl.glGetLightfv(lightID,GLLightingFunc.GL_SPOT_EXPONENT,buff);
this.spotExponent = buff.get();
- gl.glGetLightfv(lightID,GL2.GL_CONSTANT_ATTENUATION,buff);
+ gl.glGetLightfv(lightID,GLLightingFunc.GL_CONSTANT_ATTENUATION,buff);
this.constantAttenuation = buff.get();
- gl.glGetLightfv(lightID,GL2.GL_LINEAR_ATTENUATION,buff);
+ gl.glGetLightfv(lightID,GLLightingFunc.GL_LINEAR_ATTENUATION,buff);
this.linearAttenuation = buff.get();
- gl.glGetLightfv(lightID,GL2.GL_QUADRATIC_ATTENUATION,buff);
+ gl.glGetLightfv(lightID,GLLightingFunc.GL_QUADRATIC_ATTENUATION,buff);
this.quadraticAttenuation = buff.get();
-
+
this.lightNumber = lightNumber;
}
/**
@@ -386,68 +393,68 @@ public class Light { * @param lightNumber the number of the light to use (should be on [0,7]).
* @throws net.java.joglutils.lighting.LightingException if the requested light is not valid on the specified context.
*/
- public void enable(GL2 gl, int lightNumber) throws LightingException {
- if(!this.isLightNumberValid(gl, lightNumber))
+ public void enable(final GL2 gl, final int lightNumber) throws LightingException {
+ if(!Light.isLightNumberValid(gl, lightNumber))
throw new LightingException("attempted to enable Light on with an invalid lightNumber for the requested OpenGL context");
gl.glEnable(numToID(lightNumber));
this.lightNumber = lightNumber;
-
+
if(this.phongShaded) {
//TODO:link in shader as just another one?
if(!shaderBuiltin.containsKey(gl))
initializePhongShader(gl);
-
+
if(shaderBuiltin.get(gl)) {
- int progID = shaderProgNums.get(gl);
+ final int progID = shaderProgNums.get(gl);
gl.glUseProgram(progID+lightNumber);
-
- int diffMatCol = gl.glGetUniformLocation(progID,"diffMatCol");
- int ambMatCol = gl.glGetUniformLocation(progID,"ambMatCol");
-
+
+ final int diffMatCol = gl.glGetUniformLocation(progID,"diffMatCol");
+ final int ambMatCol = gl.glGetUniformLocation(progID,"ambMatCol");
+
gl.glUniform1i(diffMatCol,phongDiffColorMat ? 1 : 0);
gl.glUniform1i(ambMatCol,phongAmbColorMat ? 1 : 0);
-
-
+
+
/*for light one program
int progID = shaderProgNums.get(gl);
-
+
int lightNumUniform = gl.glGetUniformLocation(progID,"lightNumber");
gl.glUniform1i(lightNumUniform,lightNumber);
-
+
gl.glUseProgram(progID);
*/
} else {
- int progID = shaderProgNums.get(gl);
-
- int diffMatCol = gl.glGetUniformLocationARB(progID,"diffMatCol");
- int ambMatCol = gl.glGetUniformLocationARB(progID,"ambMatCol");
-
+ final int progID = shaderProgNums.get(gl);
+
+ final int diffMatCol = gl.glGetUniformLocationARB(progID,"diffMatCol");
+ final int ambMatCol = gl.glGetUniformLocationARB(progID,"ambMatCol");
+
gl.glUniform1iARB(diffMatCol,phongDiffColorMat ? 1 : 0);
gl.glUniform1iARB(ambMatCol,phongAmbColorMat ? 1 : 0);
-
+
gl.glUseProgramObjectARB(progID+lightNumber);
/*for light one program
int progID = shaderProgNums.get(gl);
-
+
int lightNumUniform = gl.glGetUniformLocationARB(progID,"lightNumber");
gl.glUniform1iARB(lightNumUniform,lightNumber);
-
+
gl.glUseProgramObjectARB(progID);
*/
}
} else {
- Integer result = shaderProgNums.get(gl);
+ final Integer result = shaderProgNums.get(gl);
if (result != null) {
- int lightID = result+lightNumber;
- java.nio.IntBuffer buffer = java.nio.IntBuffer.allocate(1);
- gl.glGetIntegerv(GL2.GL_CURRENT_PROGRAM,buffer);
- int currProgram = buffer.get();
-
+ final int lightID = result+lightNumber;
+ final java.nio.IntBuffer buffer = java.nio.IntBuffer.allocate(1);
+ gl.glGetIntegerv(GL2ES2.GL_CURRENT_PROGRAM,buffer);
+ final int currProgram = buffer.get();
+
if (currProgram == lightID)
gl.glUseProgramObjectARB(0);
}
}
-
+
}
/**
* Disables the requested light on the specified OpenGL Context.
@@ -455,12 +462,12 @@ public class Light { * @param lightNumber the number of the light to use (should be on [0,7]).
* @throws net.java.joglutils.lighting.LightingException if the requested light is not valid on the specified context.
*/
- public void disable(GL2 gl, int lightNumber) throws LightingException {
- if(!this.isLightNumberValid(gl, lightNumber))
+ public void disable(final GL2 gl, final int lightNumber) throws LightingException {
+ if(!Light.isLightNumberValid(gl, lightNumber))
throw new LightingException("attempted to disable Light on with an invalid lightNumber for the requested OpenGL context");
gl.glDisable(numToID(lightNumber));
this.lightNumber = lightNumber;
-
+
if (this.phongShaded) {
if(gl.isFunctionAvailable("glUseProgram"))
gl.glUseProgram(0);
@@ -468,20 +475,20 @@ public class Light { gl.glUseProgramObjectARB(0);
}
}
-
+
//-----------------Setters and Getters-----------------
//TODO: implement range checking on all of these
-
+
/**
* Sets the ambient (light "filling the room") color for this Light. Default is {0,0,0,1}.
* @param ambient the Color to be copied into this Light. Later changes to the Color object will not be reflected in the Light.
*/
- public void setAmbient(Color ambient) {
+ public void setAmbient(final Color ambient) {
this.ambient = ambient.getRGBComponents(null);
if (this.attachedGL != null)
- this.attachedGL.glLightfv(numToID(lightNumber),GL2.GL_AMBIENT,this.ambient,0);
+ this.attachedGL.glLightfv(numToID(lightNumber),GLLightingFunc.GL_AMBIENT,this.ambient,0);
}
-
+
/**
* Retrieves the ambient color for this Light.
* @return a copy of the color used in this Light.
@@ -489,18 +496,18 @@ public class Light { public Color getAmbient() {
return new Color(ambient[0],ambient[1],ambient[2],ambient[3]);
}
-
+
/**
* Sets the diffuse ("dull reflection") color for this Light. Default is {1,1,1,1}.
* @param diffuse the Color to be copied into this Light. Later changes to the Color object will not be reflected in the Light.
*/
- public void setDiffuse(Color diffuse) {
+ public void setDiffuse(final Color diffuse) {
this.diffuse = diffuse.getRGBComponents(null);
if (this.attachedGL != null)
- this.attachedGL.glLightfv(numToID(lightNumber),GL2.GL_DIFFUSE,this.diffuse,0);
-
+ this.attachedGL.glLightfv(numToID(lightNumber),GLLightingFunc.GL_DIFFUSE,this.diffuse,0);
+
}
-
+
/**
* Retrieves the diffuse color for this Light.
* @return a copy of the color used in this Light.
@@ -508,17 +515,17 @@ public class Light { public Color getDiffuse() {
return new Color(diffuse[0],diffuse[1],diffuse[2],diffuse[3]);
}
-
+
/**
* Sets the specular ("shiny reflection") color for this Light. Default is {1,1,1,1}.
* @param specular the Color to be copied into this Light. Later changes to the Color object will not be reflected in the Light.
*/
- public void setSpecular(Color specular) {
+ public void setSpecular(final Color specular) {
this.specular = specular.getRGBComponents(null);
if (this.attachedGL != null)
- this.attachedGL.glLightfv(numToID(lightNumber),GL2.GL_SPECULAR,this.specular,0);
+ this.attachedGL.glLightfv(numToID(lightNumber),GLLightingFunc.GL_SPECULAR,this.specular,0);
}
-
+
/**
* Retrieves the specular color for this Light.
* @return a copy of the color used in this Light.
@@ -526,25 +533,25 @@ public class Light { public Color getSpecular() {
return new Color(specular[0],specular[1],specular[2],specular[3]);
}
-
+
/**
* Specifies the direction vector for this Light.
* (i.e. this the first 3 components specified when setting GL_POSITION with glLight)
* Default is {0,0,1}.
* @param lightPosition an array of three components in {x,y,z} format to be copied into the Light.
*/
- public void setLightPosition(float[] lightPosition) {
+ public void setLightPosition(final float[] lightPosition) {
if (this.attachedGL != null) {
- float[] position = new float[4];
+ final float[] position = new float[4];
position[0] = lightPosition[0];
position[1] = lightPosition[1];
position[2] = lightPosition[2];
position[3] = this.lightW;
- this.attachedGL.glLightfv(numToID(lightNumber),GL2.GL_POSITION,position,0);
+ this.attachedGL.glLightfv(numToID(lightNumber),GLLightingFunc.GL_POSITION,position,0);
}
this.lightPosition = lightPosition.clone();
}
-
+
/**
* Specifies the direction vector for this Light.
* (i.e. this the first 3 components specified when setting GL_POSITION with glLight)
@@ -553,11 +560,11 @@ public class Light { * @param lighty the y component of the light position
* @param lightz the z component of the light position
*/
- public void setLightPosition(float lightx, float lighty, float lightz) {
- float[] pos = {lightx,lighty,lightz};
+ public void setLightPosition(final float lightx, final float lighty, final float lightz) {
+ final float[] pos = {lightx,lighty,lightz};
setLightPosition(pos);
}
-
+
/**
* Retrieves the direction vector for this light.
* @return a copy of the position of this Light
@@ -565,28 +572,28 @@ public class Light { public float[] getLightPosition() {
return this.lightPosition.clone();
}
-
+
/**
* Sets the spotlight direction for this Light. Default is {0,0,-1}.
* @param spotDirection A 3-element array in {x,y,z} format specifying the spotlight direction vector.
*/
- public void setSpotDirection(float[] spotDirection) {
+ public void setSpotDirection(final float[] spotDirection) {
if (this.attachedGL != null)
- this.attachedGL.glLightfv(numToID(lightNumber),GL2.GL_SPOT_DIRECTION,spotDirection,0);
+ this.attachedGL.glLightfv(numToID(lightNumber),GLLightingFunc.GL_SPOT_DIRECTION,spotDirection,0);
this.spotDirection = spotDirection.clone();
}
-
+
/**
* Sets the spotlight direction for this Light. Default is {0,0,-1}.
* @param spotx the x coordinate of the spotlight direction vector.
* @param spoty the y coordinate of the spotlight direction vector.
* @param spotz the z coordinate of the spotlight direction vector.
*/
- public void setSpotDirection(float spotx, float spoty, float spotz) {
- float[] spotVec = {spotx, spoty, spotz};
+ public void setSpotDirection(final float spotx, final float spoty, final float spotz) {
+ final float[] spotVec = {spotx, spoty, spotz};
setSpotDirection(spotVec);
}
-
+
/**
* Retrieves a vector indicating the spotlight direction used in this Light.
* @return a copy of the spotlight direction of this Light
@@ -594,25 +601,25 @@ public class Light { public float[] getSpotDirection() {
return this.spotDirection.clone();
}
-
+
/**
* Specifies the w-component to be used for this Light. Default is 0.
* (i.e. this the last component specified when setting GL_POSITION with glLight)
* If 0, this light is treated as a direction source.
* @param lightW the distance to be applied.
*/
- public void setLightW(float lightW) {
+ public void setLightW(final float lightW) {
if (this.attachedGL != null) {
- float[] position = new float[4];
+ final float[] position = new float[4];
position[0] = this.lightPosition[0];
position[1] = this.lightPosition[1];
position[2] = this.lightPosition[2];
position[3] = lightW;
- this.attachedGL.glLightfv(numToID(lightNumber),GL2.GL_POSITION,position,0);
+ this.attachedGL.glLightfv(numToID(lightNumber),GLLightingFunc.GL_POSITION,position,0);
}
this.lightW = lightW;
}
-
+
/**
* Retrieves the w-component of this Light.
* @return the component. If 0, this Light is a directional source.
@@ -626,17 +633,17 @@ public class Light { public void makeDirectional() {
this.setLightW(0.0f);
}
-
+
/**
* Sets the spotlight cutoff angle for this Light. Default is 180.
* @param spotCutoff the angle to use.
*/
- public void setSpotCutoff(float spotCutoff) {
+ public void setSpotCutoff(final float spotCutoff) {
if (this.attachedGL != null)
- this.attachedGL.glLightf(numToID(lightNumber),GL2.GL_SPOT_CUTOFF,spotCutoff);
+ this.attachedGL.glLightf(numToID(lightNumber),GLLightingFunc.GL_SPOT_CUTOFF,spotCutoff);
this.spotCutoff = spotCutoff;
}
-
+
/**
* Retrieves the spotlight cutoff angle for this Light.
* @return the angle used in this Light.
@@ -644,17 +651,17 @@ public class Light { public float getSpotCutoff() {
return spotCutoff;
}
-
+
/**
* Sets the spotlight exponent in this Light. Default is 0.
* @param spotExponent the exponent to set on this Light.
*/
- public void setSpotExponent(float spotExponent) {
+ public void setSpotExponent(final float spotExponent) {
if (this.attachedGL != null)
- this.attachedGL.glLightf(numToID(lightNumber),GL2.GL_SPOT_EXPONENT,spotExponent);
+ this.attachedGL.glLightf(numToID(lightNumber),GLLightingFunc.GL_SPOT_EXPONENT,spotExponent);
this.spotExponent = spotExponent;
}
-
+
/**
* Retrieves the spotlight exponent in this Light.
* @return the exponent used in this Light.
@@ -662,18 +669,18 @@ public class Light { public float getSpotExponent() {
return spotExponent;
}
-
+
/**
* Sets the coefficient of the constant term in the attenuation equation for this Light.
* Default is 1.
* @param constantAttenuation the value to use for the constant coefficient.
*/
- public void setConstantAttenuation(float constantAttenuation) {
+ public void setConstantAttenuation(final float constantAttenuation) {
if (this.attachedGL != null)
- this.attachedGL.glLightf(numToID(lightNumber),GL2.GL_CONSTANT_ATTENUATION,constantAttenuation);
+ this.attachedGL.glLightf(numToID(lightNumber),GLLightingFunc.GL_CONSTANT_ATTENUATION,constantAttenuation);
this.constantAttenuation = constantAttenuation;
}
-
+
/**
* Retrieves the coefficient of the constant term in the attenuation equation for this Light.
* @return the constant coefficient.
@@ -681,18 +688,18 @@ public class Light { public float getConstantAttenuation() {
return constantAttenuation;
}
-
+
/**
* Sets the coefficient of the linear term in the attenuation equation for this Light.
* Default is 0.
* @param linearAttenuation the value to use for the linear coefficient.
*/
- public void setLinearAttenuation(float linearAttenuation) {
+ public void setLinearAttenuation(final float linearAttenuation) {
if (this.attachedGL != null)
- this.attachedGL.glLightf(numToID(lightNumber),GL2.GL_LINEAR_ATTENUATION,linearAttenuation);
+ this.attachedGL.glLightf(numToID(lightNumber),GLLightingFunc.GL_LINEAR_ATTENUATION,linearAttenuation);
this.linearAttenuation = linearAttenuation;
}
-
+
/**
* Retrieves the coefficient of the linear term in the attenuation equation for this Light.
* @return the linear coefficient.
@@ -700,18 +707,18 @@ public class Light { public float getLinearAttenuation() {
return linearAttenuation;
}
-
+
/**
* Sets the coefficient of the quadratic term in the attenuation equation for this Light.
* Default is 0.
* @param quadraticAttenuation the value to use for the quadratic coefficient.
*/
- public void setQuadraticAttenuation(float quadraticAttenuation) {
+ public void setQuadraticAttenuation(final float quadraticAttenuation) {
if (this.attachedGL != null)
- this.attachedGL.glLightf(numToID(lightNumber),GL2.GL_QUADRATIC_ATTENUATION,quadraticAttenuation);
+ this.attachedGL.glLightf(numToID(lightNumber),GLLightingFunc.GL_QUADRATIC_ATTENUATION,quadraticAttenuation);
this.quadraticAttenuation = quadraticAttenuation;
}
-
+
/**
* Retrieves the coefficient of the quadratic term in the attenuation equation for this Light.
* @return the quadratic coefficient.
@@ -719,129 +726,129 @@ public class Light { public float getQuadraticAttenuation() {
return quadraticAttenuation;
}
-
-
-
+
+
+
//------------------public statics---------------
/**
* Determines the maximum number of lights in the specified {@link GL} context
* @param gl the OpenGL context to test
* @return the maximum number of lights (highest possible in OpenGL is 8)
*/
- public static int maxNumberOfLightsInGL(GL2 gl) {
- java.nio.IntBuffer buff = java.nio.IntBuffer.allocate(1);
- gl.glGetIntegerv(gl.GL_MAX_LIGHTS,buff);
+ public static int maxNumberOfLightsInGL(final GL2 gl) {
+ final java.nio.IntBuffer buff = java.nio.IntBuffer.allocate(1);
+ gl.glGetIntegerv(GL2ES1.GL_MAX_LIGHTS,buff);
return buff.get();
}
-
+
/**
* Converts the specified OpenGL light ID number to a number
* @return the appropriate light number (on [0,7])
* @param lightID the OpenGL ID (should be one of GL_LIGHTn where n is on [0,7])
* @throws net.java.joglutils.lighting.LightingException if the supplied lightID is not an OpenGL light ID
*/
- public static int idToNum(int lightID) throws LightingException {
+ public static int idToNum(final int lightID) throws LightingException {
int retNum = -1;
switch (lightID) {
- case GL2.GL_LIGHT0:
+ case GLLightingFunc.GL_LIGHT0:
retNum = 0;
break;
- case GL2.GL_LIGHT1:
+ case GLLightingFunc.GL_LIGHT1:
retNum = 1;
break;
- case GL2.GL_LIGHT2:
+ case GLLightingFunc.GL_LIGHT2:
retNum = 2;
break;
- case GL2.GL_LIGHT3:
+ case GLLightingFunc.GL_LIGHT3:
retNum = 3;
break;
- case GL2.GL_LIGHT4:
+ case GLLightingFunc.GL_LIGHT4:
retNum = 4;
break;
- case GL2.GL_LIGHT5:
+ case GLLightingFunc.GL_LIGHT5:
retNum = 5;
break;
- case GL2.GL_LIGHT6:
+ case GLLightingFunc.GL_LIGHT6:
retNum = 6;
break;
- case GL2.GL_LIGHT7:
+ case GLLightingFunc.GL_LIGHT7:
retNum = 7;
break;
default:
throw new LightingException("tried to determine light number of a non-ID int");
}
return retNum;
-
+
}
-
+
/**
* Determines the OpenGL ID for the specified light number
* @return the OpenGL ID for that light number (from the GL_LIGHTn family)
* @param lightNum a number on [0,7] specifying the a light
* @throws net.java.joglutils.lighting.LightingException if the supplied lightID is not an OpenGL light ID
*/
- public static int numToID(int lightNum) throws LightingException {
+ public static int numToID(final int lightNum) throws LightingException {
int retID = -1;
switch (lightNum) {
case 0:
- retID = GL2.GL_LIGHT0;
+ retID = GLLightingFunc.GL_LIGHT0;
break;
case 1:
- retID = GL2.GL_LIGHT1;
+ retID = GLLightingFunc.GL_LIGHT1;
break;
case 2:
- retID = GL2.GL_LIGHT2;
+ retID = GLLightingFunc.GL_LIGHT2;
break;
case 3:
- retID = GL2.GL_LIGHT3;
+ retID = GLLightingFunc.GL_LIGHT3;
break;
case 4:
- retID = GL2.GL_LIGHT4;
+ retID = GLLightingFunc.GL_LIGHT4;
break;
case 5:
- retID = GL2.GL_LIGHT5;
+ retID = GLLightingFunc.GL_LIGHT5;
break;
case 6:
- retID = GL2.GL_LIGHT6;
+ retID = GLLightingFunc.GL_LIGHT6;
break;
case 7:
- retID = GL2.GL_LIGHT7;
+ retID = GLLightingFunc.GL_LIGHT7;
break;
default:
throw new LightingException("tried to determine ID of a number not on [0,7]");
}
return retID;
}
-
+
/**
* Determines if there is space in a specified OpenGL context for another Light to be attached
* @param gl the openGL context to test
* @return true if another Light object can be attached to this GL context
*/
- public static boolean hasFreeLights(GL2 gl) {
- boolean[] lights = assignedLights.get(gl);
+ public static boolean hasFreeLights(final GL2 gl) {
+ final boolean[] lights = assignedLights.get(gl);
if (lights == null)
return true;
- for (boolean b : lights) {
+ for (final boolean b : lights) {
if (!b)
return true;
}
return false;
}
-
+
/**
* Sets if phong per-fragment shading (as opposed to fixed-functionality per-vertex shading) is to be used with this Light. Must come before the light is enabled.
* This uses a vertex and fragment shader, so the fixed-functionality pipeline will not function normally.
* @param usePhongShading if Phong should be used. If true and this Light is attached to a GL Context, initializes on this Light's context
* @throws net.java.joglutils.lighting.LightingException if the current OpenGL context does not support GLSL shaders or the shader did not sucessfully compile and link
*/
- public void setPhongShaded(boolean usePhongShading) throws LightingException {
+ public void setPhongShaded(final boolean usePhongShading) throws LightingException {
if (this.attachedGL != null)
initializePhongShader(this.attachedGL);
-
+
this.phongShaded = usePhongShading;
}
-
+
/**
* Tells if this Light is using Phong shading
* @return true if this Light is in Phong shading mode
@@ -849,17 +856,17 @@ public class Light { public boolean isPhongShaded() {
return this.phongShaded;
}
-
+
/**
* Sets whether or not the opengl color should be used for the phong color shader
* @param ambient the ambient color material mode
* @param diffuse the diffuse color material mode
*/
- public void setPhongColorMaterial(boolean ambient, boolean diffuse) {
+ public void setPhongColorMaterial(final boolean ambient, final boolean diffuse) {
this.phongAmbColorMat = ambient;
this.phongDiffColorMat = diffuse;
}
-
+
/**
* Determines if color material is used for ambient in the Phong shader
* @return true if color material is used for the phong ambient shader
@@ -867,7 +874,7 @@ public class Light { public boolean isAmbientPhongColorMaterial() {
return this.phongAmbColorMat;
}
-
+
/**
* Determines if color material is used for diffuse in the Phong shader
* @return true if color material is used for the phong diffuse shader
@@ -875,21 +882,21 @@ public class Light { public boolean isDiffusePhongColorMaterial() {
return this.phongDiffColorMat;
}
-
+
/**
* Initializes Phong shading mode for this Light (instead of the fixed functionality Gouraud shading) on the current OpenGL context. Must be called before Phong shading can be activated.
* @throws net.java.joglutils.lighting.LightingException if the OpenGL context does not support GLSL shaders or the shader did not sucessfully compile and link
*/
public static void initializePhongShader() throws LightingException {
- initializePhongShader(javax.media.opengl.glu.GLU.getCurrentGL().getGL2());
+ initializePhongShader(GLU.getCurrentGL().getGL2());
}
-
+
/**
* Initializes Phong shading mode for this Light (instead of the fixed functionality Gouraud shading). Must be called on the context before Phong shading can be activated.
* @param gl the openGL context on which to initialize the shader
* @throws net.java.joglutils.lighting.LightingException if the OpenGL context does not support GLSL shaders or the shader did not sucessfully compile and link
*/
- public static void initializePhongShader(GL2 gl) throws LightingException {
+ public static void initializePhongShader(final GL2 gl) throws LightingException {
/* Old way that only works for light zero
//program source
final String[] fragSource = {
@@ -922,41 +929,41 @@ public class Light { "gl_Position = ftransform ();\n",
"}\n"
};
-
+
int[] vertLengths = new int[vertSource.length];
for (int i=0; i < vertLengths.length;++i)
vertLengths[i] = vertSource[i].length();
int[] fragLengths = new int[fragSource.length];
for (int i=0; i < fragLengths.length;++i)
fragLengths[i] = fragSource[i].length();
-
-
+
+
boolean builtin;
int progID;
-
+
if(gl.isFunctionAvailable("glCreateProgram"))
builtin = true;
else if (gl.isFunctionAvailable("glCreateProgramObjectARB"))
builtin = false;
else
throw new LightingException("Could not generate Shader for Light - GLSL Shaders not supported by this GL Context");
-
+
if(builtin) {
progID = gl.glCreateProgram();
int vertID = gl.glCreateShader(GL2.GL_VERTEX_SHADER);
int fragID = gl.glCreateShader(GL2.GL_FRAGMENT_SHADER);
-
+
gl.glShaderSource(vertID,vertSource.length,vertSource,vertLengths,0);
gl.glShaderSource(fragID,fragSource.length,fragSource,fragLengths,0);
-
+
gl.glCompileShader(vertID);
gl.glCompileShader(fragID);
-
+
gl.glAttachShader(progID,vertID);
gl.glAttachShader(progID,fragID);
-
+
gl.glLinkProgram(progID);
-
+
int[] getProgArray = new int[1];
gl.glGetProgramiv(progID,GL2.GL_LINK_STATUS,getProgArray,0);
if (getProgArray[0] == GL2.GL_FALSE) {
@@ -967,23 +974,23 @@ public class Light { String log = new String(logArray);
throw new LightingException("Shader Program could not link. Log:\n"+log);
}
-
+
} else {
progID = gl.glCreateProgramObjectARB();
int vertID = gl.glCreateShaderObjectARB(GL2.GL_VERTEX_SHADER_ARB);
int fragID = gl.glCreateShaderObjectARB(GL2.GL_FRAGMENT_SHADER_ARB);
-
+
gl.glShaderSourceARB(vertID,vertSource.length,vertSource,vertLengths,0);
gl.glShaderSourceARB(fragID,fragSource.length,fragSource,fragLengths,0);
-
+
gl.glCompileShaderARB(vertID);
gl.glCompileShaderARB(fragID);
-
+
gl.glAttachObjectARB(progID,vertID);
gl.glAttachObjectARB(progID,fragID);
-
+
gl.glLinkProgramARB(progID);
-
+
int[] getProgArray = new int[1];
gl.glGetObjectParameterivARB(progID,GL2.GL_OBJECT_LINK_STATUS_ARB,getProgArray,0);
if (getProgArray[0] == GL2.GL_FALSE) {
@@ -996,168 +1003,170 @@ public class Light { }
}
*/
-
+
boolean builtin;
int progID;
-
+
if(gl.isFunctionAvailable("glCreateProgram"))
builtin = true;
else if (gl.isFunctionAvailable("glCreateProgramObjectARB"))
builtin = false;
else
throw new LightingException("Could not generate Shader for Light - GLSL Shaders not supported by this GL Context");
-
+
if(builtin) {
progID = gl.glCreateProgram();
//generate the other 7 shaders so that the numbers are in order
for (int currID = 1+progID; currID < (progID+8); ++currID) {
- int result = gl.glCreateProgram();
+ final int result = gl.glCreateProgram();
if (result != currID)
throw new LightingException("Couldn't generate shader programs in numerical order - can't use Phong Shading");
}
-
- int vertID = gl.glCreateShader(GL2.GL_VERTEX_SHADER);
- String[] vertSource = generatePhongVertexShaderSource();
+
+ final int vertID = gl.glCreateShader(GL2ES2.GL_VERTEX_SHADER);
+ final String[] vertSource = generatePhongVertexShaderSource();
gl.glShaderSource(vertID,vertSource.length,vertSource,generateShaderLengths(vertSource),0);
-
-
+
+
//generate program for each light and compile and link
for (int currID = progID;currID < (8+progID);++currID) {
-
- int fragID = gl.glCreateShader(GL2.GL_FRAGMENT_SHADER);
- String[] fragSource = generatePhongFragmentShaderSource(currID-progID);
+
+ final int fragID = gl.glCreateShader(GL2ES2.GL_FRAGMENT_SHADER);
+ final String[] fragSource = generatePhongFragmentShaderSource(currID-progID);
gl.glShaderSource(fragID,fragSource.length,fragSource,generateShaderLengths(fragSource),0);
-
+
gl.glCompileShader(vertID);
gl.glCompileShader(fragID);
-
+
gl.glAttachShader(currID,vertID);
gl.glAttachShader(currID,fragID);
-
+
gl.glLinkProgram(currID);
-
- int[] getProgArray = new int[1];
- gl.glGetProgramiv(currID,GL2.GL_LINK_STATUS,getProgArray,0);
- if (getProgArray[0] == GL2.GL_FALSE) {
- gl.glGetProgramiv(currID,GL2.GL_INFO_LOG_LENGTH,getProgArray,0);
- int logLength = getProgArray[0];
- byte[] logArray = new byte[logLength];
+
+ final int[] getProgArray = new int[1];
+ gl.glGetProgramiv(currID,GL2ES2.GL_LINK_STATUS,getProgArray,0);
+ if (getProgArray[0] == GL.GL_FALSE) {
+ gl.glGetProgramiv(currID,GL2ES2.GL_INFO_LOG_LENGTH,getProgArray,0);
+ final int logLength = getProgArray[0];
+ final byte[] logArray = new byte[logLength];
gl.glGetProgramInfoLog(currID,logLength,getProgArray,0,logArray,0);
- String log = new String(logArray);
+ final String log = new String(logArray);
throw new LightingException("Shader Program could not link. Log:\n"+log);
}
}
} else {
- progID = gl.glCreateProgramObjectARB();
+ // FIXME: praying that int-cast works ;-)
+ progID = (int) gl.glCreateProgramObjectARB();
//generate the other 7 shaders so that the numbers are in order
for (int currID = 1+progID; currID < (progID+8); ++currID) {
- int result = gl.glCreateProgramObjectARB();
+ final int result = (int) gl.glCreateProgramObjectARB();
if (result != currID)
throw new LightingException("Couldn't generate shader programs in numerical order - can't use Phong Shading");
}
-
- int vertID = gl.glCreateShaderObjectARB(GL2.GL_VERTEX_SHADER);
- String[] vertSource = generatePhongVertexShaderSource();
+
+ final int vertID = (int) gl.glCreateShaderObjectARB(GL2ES2.GL_VERTEX_SHADER);
+ final String[] vertSource = generatePhongVertexShaderSource();
gl.glShaderSourceARB(vertID,vertSource.length,vertSource,generateShaderLengths(vertSource),0);
-
+
//TODO: do this in a way that doesn't depend on the numbers being in order
//generate program for each light and compile and link
for (int currID = progID;currID < (8+progID);++currID) {
-
- int fragID = gl.glCreateShaderObjectARB(GL2.GL_FRAGMENT_SHADER);
- String[] fragSource = generatePhongFragmentShaderSource(currID-progID);
+ final int fragID = (int) gl.glCreateShaderObjectARB(GL2ES2.GL_FRAGMENT_SHADER);
+ final String[] fragSource = generatePhongFragmentShaderSource(currID-progID);
gl.glShaderSourceARB(fragID,fragSource.length,fragSource,generateShaderLengths(fragSource),0);
-
+
gl.glCompileShaderARB(vertID);
gl.glCompileShaderARB(fragID);
-
+
gl.glAttachObjectARB(currID,vertID);
gl.glAttachObjectARB(currID,fragID);
-
+
gl.glLinkProgramARB(currID);
-
- int[] getProgArray = new int[1];
+
+ final int[] getProgArray = new int[1];
gl.glGetObjectParameterivARB(currID,GL2.GL_OBJECT_LINK_STATUS_ARB,getProgArray,0);
- if (getProgArray[0] == GL2.GL_FALSE) {
+ if (getProgArray[0] == GL.GL_FALSE) {
gl.glGetObjectParameterivARB(currID,GL2.GL_OBJECT_INFO_LOG_LENGTH_ARB,getProgArray,0);
- int logLength = getProgArray[0];
- byte[] logArray = new byte[logLength];
+ final int logLength = getProgArray[0];
+ final byte[] logArray = new byte[logLength];
gl.glGetInfoLogARB(currID,logLength,getProgArray,0,logArray,0);
- String log = new String(logArray);
+ final String log = new String(logArray);
throw new LightingException("Shader Program could not link. Log:\n"+log);
}
}
}
-
+
shaderProgNums.put(gl,progID);
shaderBuiltin.put(gl, builtin);
}
-
+
/**
* Removes the Phong Shader program from the current GL Context
*
* @throws net.java.joglutils.lighting.LightingException if there is no Phong Shader
**/
-
+
public static void removePhongShader() throws LightingException {
- removePhongShader(javax.media.opengl.glu.GLU.getCurrentGL().getGL2());
+ removePhongShader(GLContext.getCurrentGL().getGL2());
}
-
+
/**
* Removes the Phong Shader program from the specified GL Context
*
* @param gl the OpenGL context to remove the Phong shader program from
* @throws net.java.joglutils.lighting.LightingException if there is no Phong Shader initialized on this context
*/
- public static void removePhongShader(GL2 gl) throws LightingException {
+ public static void removePhongShader(final GL2 gl) throws LightingException {
if (shaderBuiltin.containsKey(gl)) {
- int progID = shaderProgNums.remove(gl);
+ final int progID = shaderProgNums.remove(gl);
if(shaderBuiltin.remove(gl)) {
- java.nio.IntBuffer intBuff = java.nio.IntBuffer.allocate(3);
+ final java.nio.IntBuffer intBuff = java.nio.IntBuffer.allocate(3);
for (int currID = progID; currID < (8+progID); ++currID) {
gl.glGetAttachedShaders(currID,2,intBuff,intBuff);
if (intBuff.get() != 2)
throw new LightingException("More than 2 shaders attached to the Light phong shader program. Program ID Number:"+progID);
-
+
gl.glDeleteShader(intBuff.get());
gl.glDeleteShader(intBuff.get());
-
+
gl.glDeleteProgram(currID);
intBuff.clear();
}
} else {
- java.nio.IntBuffer intBuff = java.nio.IntBuffer.allocate(3);
+ final java.nio.IntBuffer intBuff = java.nio.IntBuffer.allocate(3);
+ final java.nio.LongBuffer longBuff = java.nio.LongBuffer.allocate(3);
for (int currID = progID; currID < (8+progID); ++currID) {
- gl.glGetAttachedObjectsARB(currID,2,intBuff,intBuff);
+ gl.glGetAttachedObjectsARB(currID,2,intBuff,longBuff);
if (intBuff.get() != 2)
throw new LightingException("More than 2 shaders attached to the Light phong shader program. Program ID Number:"+progID);
-
- gl.glDeleteObjectARB(intBuff.get());
- gl.glDeleteObjectARB(intBuff.get());
-
+
+ gl.glDeleteObjectARB(longBuff.get());
+ gl.glDeleteObjectARB(longBuff.get());
+
gl.glDeleteObjectARB(currID);
intBuff.clear();
+ longBuff.clear();
}
}
} else
throw new LightingException("Tried to remove Light phong shader on a GL Context with no phong shader");
}
-
+
//----------- Private internal functions/methods below this point------------
- private static boolean isLightNumberValid(GL2 gl ,int lightNumber) {
+ private static boolean isLightNumberValid(final GL2 gl ,final int lightNumber) {
return (lightNumber > -1 && lightNumber < maxNumberOfLightsInGL(gl));
}
- private static boolean isLightNumberFree(GL2 gl, int lightNumber) {
- boolean[] lights = assignedLights.get(gl);
+ private static boolean isLightNumberFree(final GL2 gl, final int lightNumber) {
+ final boolean[] lights = assignedLights.get(gl);
if (lights == null)
return true;
if (lightNumber >= lights.length || lightNumber < 0)
return false;
return (!lights[lightNumber]);
-
+
}
-
- private static int findAndAssignFreeLightNumber(GL2 gl) {
+
+ private static int findAndAssignFreeLightNumber(final GL2 gl) {
boolean[] lights = assignedLights.get(gl);
if (lights == null) {
lights = new boolean[maxNumberOfLightsInGL(gl)];
@@ -1177,9 +1186,9 @@ public class Light { return i;
}
return -1;
-
+
}
- private static void assignLightNumber(GL2 gl, int lightNumber) {
+ private static void assignLightNumber(final GL2 gl, final int lightNumber) {
//No range checking
boolean[] lights = assignedLights.get(gl);
if (lights == null) {
@@ -1187,19 +1196,19 @@ public class Light { lights[lightNumber] = true;
} else
lights[lightNumber] = true;
-
+
assignedLights.put(gl,lights);
}
-
- private static void unassignLightNumber(GL2 gl, int lightNumber) {
+
+ private static void unassignLightNumber(final GL2 gl, final int lightNumber) {
//No range checking
- boolean[] lights = assignedLights.get(gl);
+ final boolean[] lights = assignedLights.get(gl);
lights[lightNumber] = false;
assignedLights.put(gl,lights);
}
-
- private static String[] generatePhongFragmentShaderSource(int lightNumber) {
- String[] fragSource = {
+
+ private static String[] generatePhongFragmentShaderSource(final long l) {
+ final String[] fragSource = {
"varying vec3 normalEye;\n",
"varying vec3 positionEye;\n",
"uniform bool ambMatCol;\n",
@@ -1209,23 +1218,23 @@ public class Light { "{\n",
"\n",
"vec3 N = normalize (normalEye);\n",
- "vec3 L = normalize (gl_LightSource["+lightNumber+"].position.xyz);\n",
+ "vec3 L = normalize (gl_LightSource["+l+"].position.xyz);\n",
"vec3 E = normalize (-positionEye);\n",
"vec3 H = normalize (L + E);\n",
"\n",
- "vec4 ambientColor = (ambMatCol ? gl_Color : gl_FrontMaterial.ambient ) * (gl_LightSource["+lightNumber+"].ambient+gl_LightModel.ambient);\n",
- "vec4 diffuseColor = (diffMatCol ? gl_Color : gl_FrontMaterial.diffuse ) * gl_LightSource["+lightNumber+"].diffuse * max (dot (N, L), 0.0);\n",
+ "vec4 ambientColor = (ambMatCol ? gl_Color : gl_FrontMaterial.ambient ) * (gl_LightSource["+l+"].ambient+gl_LightModel.ambient);\n",
+ "vec4 diffuseColor = (diffMatCol ? gl_Color : gl_FrontMaterial.diffuse ) * gl_LightSource["+l+"].diffuse * max (dot (N, L), 0.0);\n",
//"vec4 ambientColor = gl_FrontMaterial.ambient * (gl_LightSource["+lightNumber+"].ambient+gl_LightModel.ambient);\n",
//"vec4 diffuseColor = gl_FrontMaterial.diffuse * gl_LightSource["+lightNumber+"].diffuse * max (dot (N, L), 0.0);\n",
//"vec4 ambientColor = gl_Color * (gl_LightSource["+lightNumber+"].ambient+gl_LightModel.ambient);\n",
//"vec4 diffuseColor = gl_Color * gl_LightSource["+lightNumber+"].diffuse * max (dot (N, L), 0.0);\n",
- "vec4 specularColor = gl_FrontMaterial.specular * gl_LightSource["+lightNumber+"]. specular * pow (max (dot (N, H), 0.0), gl_FrontMaterial.shininess);\n",
+ "vec4 specularColor = gl_FrontMaterial.specular * gl_LightSource["+l+"]. specular * pow (max (dot (N, H), 0.0), gl_FrontMaterial.shininess);\n",
"gl_FragColor = ambientColor + diffuseColor + specularColor;\n",
"}\n"
};
return fragSource;
}
-
+
private static String[] generatePhongVertexShaderSource() {
final String[] vertSource={
"varying vec3 normalEye;\n",
@@ -1241,13 +1250,13 @@ public class Light { };
return vertSource;
}
-
- private static int[] generateShaderLengths(String[] shaderSource) {
- int[] vertLengths = new int[shaderSource.length];
+
+ private static int[] generateShaderLengths(final String[] shaderSource) {
+ final int[] vertLengths = new int[shaderSource.length];
for (int i=0; i < vertLengths.length;++i)
vertLengths[i] = shaderSource[i].length();
-
+
return vertLengths;
}
-
+
}
diff --git a/src/net/java/joglutils/lighting/Material.java b/src/net/java/joglutils/lighting/Material.java index f8500b4..f3cad7e 100644 --- a/src/net/java/joglutils/lighting/Material.java +++ b/src/net/java/joglutils/lighting/Material.java @@ -1,21 +1,21 @@ /*
* Copyright (c) 2006 Erik Tollerud ([email protected]) 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.
- *
+ *
* The names of Erik Tollerud, Sun Microsystems, Inc. or the names of
* contributors may not 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
@@ -23,12 +23,12 @@ * SUN MICROSYSTEMS, INC. ("SUN"), AND SUN'S 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 ERIK
- * TOLLERUD, SUN, OR SUN'S LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
+ * TOLLERUD, SUN, OR SUN'S 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 ERIK
* TOLLERUD OR 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.
@@ -36,15 +36,19 @@ package net.java.joglutils.lighting;
-import javax.media.opengl.*;
import java.awt.Color;
-import java.nio.*;
+import java.nio.FloatBuffer;
+
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2;
+import com.jogamp.opengl.GL2ES1;
+import com.jogamp.opengl.fixedfunc.GLLightingFunc;
/**
* This class encapsulates OpenGL material settings in an object-oriented interface.
* The class operates in two modes:
- * <br> 1. If a {@link GL} Context is attached, setter methods apply the settings to the
- * OpenGL state as well as the object. the apply() and retrieve() method can be
+ * <br> 1. If a {@link GL} Context is attached, setter methods apply the settings to the
+ * OpenGL state as well as the object. the apply() and retrieve() method can be
* used for all of the settings
* <br> 2. If no {@link GL} Context is attached, apply(GL) and retrieve(GL) set / get
* the OpenGL state from this object.
@@ -54,27 +58,27 @@ import java.nio.*; public class Material {
GL2 attachedGL;
private int face;
-
+
private float[] ambient;
private float[] diffuse;
private float[] specular;
private float shininess;
private float[] emissive;
-
-
+
+
/** Creates a new instance of Material from the OpenGL default material settings */
public Material() {
attachedGL = null;
- face = GL2.GL_FRONT_AND_BACK;
- float[] localAmb = {0.2f,0.2f,0.2f,1.0f};
+ face = GL.GL_FRONT_AND_BACK;
+ final float[] localAmb = {0.2f,0.2f,0.2f,1.0f};
ambient = localAmb;
- float[] localDiff = {0.8f,0.8f,0.8f,1.0f};
+ final float[] localDiff = {0.8f,0.8f,0.8f,1.0f};
diffuse = localDiff;
- float[] localSpec = {0.0f,0.0f,0.0f,1.0f};
+ final float[] localSpec = {0.0f,0.0f,0.0f,1.0f};
specular = localSpec;
- float[] localEm = {0.0f,0.0f,0.0f,1.0f};
+ final float[] localEm = {0.0f,0.0f,0.0f,1.0f};
emissive = localEm;
-
+
shininess = 0;
}
/**
@@ -82,7 +86,7 @@ public class Material { * @param gl the OpenGL context to attach
* @param face the face to use for configuring the material
*/
- public Material(GL2 gl, int face) {
+ public Material(final GL2 gl, final int face) {
this.attachedGL = gl;
this.face = face;
this.specular = new float[4];
@@ -95,14 +99,14 @@ public class Material { * Creates a new instance of material, with the specified GL context attached. Settings are applied to front and back.
* @param gl the OpenGL context to attach
*/
- public Material(GL2 gl) {
- this(gl,GL2.GL_FRONT_AND_BACK);
+ public Material(final GL2 gl) {
+ this(gl,GL.GL_FRONT_AND_BACK);
}
/**
* Attached the specified OpenGL context to this object
* @param gl the OpenGL context to attach this to
*/
- public void setAttachedGL(GL2 gl) {
+ public void setAttachedGL(final GL2 gl) {
this.attachedGL = gl;
}
/**
@@ -112,7 +116,7 @@ public class Material { public GL getAttachedGL() {
return this.attachedGL;
}
- /**
+ /**
* Detaches the currently attached OpenGL context from this object
*/
public void detachGL() {
@@ -127,38 +131,38 @@ public class Material { return false;
return true;
}
-
+
/**
* Sets the OpenGL State in the supplied context based on the settings in this Material.
* @param gl the OpenGL Context upon which to apply the settings from this Material.
*/
- public void apply(GL2 gl) {
- gl.glMaterialfv(face,GL2.GL_SPECULAR,specular,0);
- gl.glMaterialfv(face,GL2.GL_EMISSION,emissive,0);
- gl.glMaterialfv(face,GL2.GL_AMBIENT,ambient,0);
- gl.glMaterialfv(face,GL2.GL_DIFFUSE,diffuse,0);
- gl.glMaterialf(face,GL2.GL_SHININESS,shininess);
+ public void apply(final GL2 gl) {
+ gl.glMaterialfv(face,GLLightingFunc.GL_SPECULAR,specular,0);
+ gl.glMaterialfv(face,GLLightingFunc.GL_EMISSION,emissive,0);
+ gl.glMaterialfv(face,GLLightingFunc.GL_AMBIENT,ambient,0);
+ gl.glMaterialfv(face,GLLightingFunc.GL_DIFFUSE,diffuse,0);
+ gl.glMaterialf(face,GLLightingFunc.GL_SHININESS,shininess);
}
/**
* Sets the settings in this Material from the specified OpenGL context's state.
* @param gl the OpenGL Context to use in setting this Material's settings.
*/
- public void retrieve(GL2 gl) {
+ public void retrieve(final GL2 gl) {
int retrievalFace = face;
- if (face == GL2.GL_FRONT_AND_BACK)
- retrievalFace = GL2.GL_FRONT;
-
- FloatBuffer buff = FloatBuffer.allocate(17);
-
- gl.glGetMaterialfv(retrievalFace,gl.GL_SPECULAR,buff);
+ if (face == GL.GL_FRONT_AND_BACK)
+ retrievalFace = GL.GL_FRONT;
+
+ final FloatBuffer buff = FloatBuffer.allocate(17);
+
+ gl.glGetMaterialfv(retrievalFace,GLLightingFunc.GL_SPECULAR,buff);
buff.get(this.specular);
- gl.glGetMaterialfv(retrievalFace,gl.GL_EMISSION,buff);
+ gl.glGetMaterialfv(retrievalFace,GLLightingFunc.GL_EMISSION,buff);
buff.get(this.emissive);
- gl.glGetMaterialfv(retrievalFace,gl.GL_AMBIENT,buff);
+ gl.glGetMaterialfv(retrievalFace,GLLightingFunc.GL_AMBIENT,buff);
buff.get(this.ambient);
- gl.glGetMaterialfv(retrievalFace,gl.GL_DIFFUSE,buff);
+ gl.glGetMaterialfv(retrievalFace,GLLightingFunc.GL_DIFFUSE,buff);
buff.get(this.diffuse);
- gl.glGetMaterialfv(retrievalFace,gl.GL_SHININESS,buff);
+ gl.glGetMaterialfv(retrievalFace,GLLightingFunc.GL_SHININESS,buff);
this.shininess = buff.get();
}
/**
@@ -185,17 +189,17 @@ public class Material { * @param face the face to apply material settings upon. Must be GL2.GL_FRONT_AND_BACK, GL2.GL_FRONT, or GL2.GL_BACK
* @throws sddm.lighting.LightingException if an invalid input is provided
*/
- public void setFace(int face) throws LightingException {
- if(face==GL2.GL_FRONT_AND_BACK)
- this.face = GL2.GL_FRONT_AND_BACK;
- else if(face == GL2.GL_FRONT)
- this.face = GL2.GL_FRONT;
- else if(face == GL2.GL_BACK)
- this.face = GL2.GL_BACK;
+ public void setFace(final int face) throws LightingException {
+ if(face==GL.GL_FRONT_AND_BACK)
+ this.face = GL.GL_FRONT_AND_BACK;
+ else if(face == GL.GL_FRONT)
+ this.face = GL.GL_FRONT;
+ else if(face == GL.GL_BACK)
+ this.face = GL.GL_BACK;
else
throw new LightingException("Attempted to set face to an invalid value");
}
-
+
/**
* Determines what face the material settings are applied to or retrieved from.
* @return the face used - can be GL2.GL_FRONT_AND_BACK, GL2.GL_FRONT, or GL2.GL_BACK
@@ -203,17 +207,17 @@ public class Material { public int getFace() {
return face;
}
-
+
/**
* Sets this object's specular color from an input Color. Default is {0,0,0,1}.
* @param specular the color that the specular color is copied from - later changes to the Color object will not be reflected in this Material.
*/
- public void setSpecular(Color specular) {
+ public void setSpecular(final Color specular) {
if (this.attachedGL != null)
- attachedGL.glMaterialfv(face,GL2.GL_SPECULAR,specular.getRGBComponents(null),0);
+ attachedGL.glMaterialfv(face,GLLightingFunc.GL_SPECULAR,specular.getRGBComponents(null),0);
this.specular = specular.getRGBComponents(null);
}
-
+
/**
* Retrieves the specular color from this Material.
* @return a new Color with components copied from this Material.
@@ -221,17 +225,17 @@ public class Material { public Color getSpecular() {
return new Color(specular[0],specular[1],specular[2],specular[3]);
}
-
+
/**
* Sets the shininess for this Material. Defaults to 0.
* @param shininess the value to use for shininess
*/
- public void setShininess(float shininess) {
+ public void setShininess(final float shininess) {
if (this.attachedGL != null)
- attachedGL.glMaterialf(face,GL2.GL_SHININESS,shininess);
+ attachedGL.glMaterialf(face,GLLightingFunc.GL_SHININESS,shininess);
this.shininess = shininess;
}
-
+
/**
* Retrieves the shininess from this Material.
* @return the shininess value
@@ -239,17 +243,17 @@ public class Material { public float getShininess() {
return shininess;
}
-
+
/**
* Sets this object's emissive color from an input Color. Default is {0,0,0,1}.
* @param emissive the color that the specular color is copied from - later changes to the Color object will not be reflected in this Material.
*/
- public void setEmissive(Color emissive) {
+ public void setEmissive(final Color emissive) {
if (this.attachedGL != null)
- attachedGL.glMaterialfv(face,GL2.GL_EMISSION,emissive.getRGBComponents(null),0);
+ attachedGL.glMaterialfv(face,GLLightingFunc.GL_EMISSION,emissive.getRGBComponents(null),0);
this.emissive = emissive.getRGBComponents(null);
}
-
+
/**
* This retrieves the emissive color from this Material.
* @return a new Color with components copied from this Material.
@@ -257,17 +261,17 @@ public class Material { public Color getEmissive() {
return new Color(emissive[0],emissive[1],emissive[2],emissive[3]);
}
-
+
/**
* Sets this object's ambient color from an input Color. Defaults to {0.2,0.2,0.2,1.0}.
* @param ambient the color that the specular color is copied from - later changes to the Color object will not be reflected in this Material.
*/
- public void setAmbient(Color ambient) {
+ public void setAmbient(final Color ambient) {
if (this.attachedGL != null)
- attachedGL.glMaterialfv(face,GL2.GL_AMBIENT,ambient.getRGBComponents(null),0);
+ attachedGL.glMaterialfv(face,GLLightingFunc.GL_AMBIENT,ambient.getRGBComponents(null),0);
this.ambient = ambient.getRGBComponents(null);
}
-
+
/**
* This retrieves the ambient color from this Material.
* @return a new Color with components copied from this Material.
@@ -275,17 +279,17 @@ public class Material { public Color getAmbient() {
return new Color(ambient[0],ambient[1],ambient[2],ambient[3]);
}
-
+
/**
* Sets this object's diffuse color from an input Color. Defaults to {0.8,0.8,0.8,1.0}.
* @param diffuse the color that the specular color is copied from - later changes to the Color object will not be reflected in this Material.
*/
- public void setDiffuse(Color diffuse) {
+ public void setDiffuse(final Color diffuse) {
if (this.attachedGL != null)
- attachedGL.glMaterialfv(face,GL2.GL_DIFFUSE,diffuse.getRGBComponents(null),0);
+ attachedGL.glMaterialfv(face,GLLightingFunc.GL_DIFFUSE,diffuse.getRGBComponents(null),0);
this.diffuse = diffuse.getRGBComponents(null);
}
-
+
/**
* This retrieves the diffuse color from this Material.
* @return a new Color with components copied from this Material.
@@ -298,10 +302,10 @@ public class Material { * @param ambient the ambient color to be applied.
* @throws sddm.lighting.LightingException if no OpenGL Context is attached.
*/
- public void applyGlobalAmbient(Color ambient) throws LightingException {
+ public void applyGlobalAmbient(final Color ambient) throws LightingException {
if (this.attachedGL == null)
throw new LightingException("tried to set global ambient color on object with no attached GL Context");
- this.applyGlobalAmbient(this.attachedGL,ambient);
+ Material.applyGlobalAmbient(this.attachedGL,ambient);
}
/**
* Retrieves the GL_LIGHT_MODEL_AMBIENT color from the attached OpenGL context.
@@ -311,26 +315,26 @@ public class Material { public Color getGlobalAmbient() throws LightingException {
if (this.attachedGL == null)
throw new LightingException("tried to get global ambient color on object with with no attached GL Context");
- return this.getGlobalAmbient(this.attachedGL);
- }
-
+ return Material.getGlobalAmbient(this.attachedGL);
+ }
+
/**
* Sets the light model parameter GL_LIGHT_MODEL_AMBIENT for the specified GL context. This applies for all lighted fragments on this GL context.
* @param gl the OpenGL context to apply this color to.
* @param ambient the ambient color to be applied.
*/
- public static void applyGlobalAmbient(GL2 gl, Color ambient) {
- gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT,ambient.getRGBComponents(null),0);
+ public static void applyGlobalAmbient(final GL2 gl, final Color ambient) {
+ gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT,ambient.getRGBComponents(null),0);
}
/**
* Retrieves the GL_LIGHT_MODEL_AMBIENT color from a specified OpenGL context.
* @param gl the OpenGL Context from which to get the color.
* @return the ambient color in the specified OpenGL Context.
*/
- public static Color getGlobalAmbient(GL2 gl) {
- FloatBuffer buff = FloatBuffer.allocate(4);
- gl.glGetFloatv(gl.GL_LIGHT_MODEL_AMBIENT, buff);
+ public static Color getGlobalAmbient(final GL2 gl) {
+ final FloatBuffer buff = FloatBuffer.allocate(4);
+ gl.glGetFloatv(GL2ES1.GL_LIGHT_MODEL_AMBIENT, buff);
return new Color(buff.get(),buff.get(),buff.get(),buff.get());
}
-
+
}
diff --git a/src/net/java/joglutils/model/ModelFactory.java b/src/net/java/joglutils/model/ModelFactory.java index 778f319..c1e2645 100644 --- a/src/net/java/joglutils/model/ModelFactory.java +++ b/src/net/java/joglutils/model/ModelFactory.java @@ -11,6 +11,7 @@ package net.java.joglutils.model; import java.util.HashMap;
+
import net.java.joglutils.model.geometry.Model;
import net.java.joglutils.model.loader.LoaderFactory;
diff --git a/src/net/java/joglutils/model/ResourceRetriever.java b/src/net/java/joglutils/model/ResourceRetriever.java index 3b81190..566ed9c 100644 --- a/src/net/java/joglutils/model/ResourceRetriever.java +++ b/src/net/java/joglutils/model/ResourceRetriever.java @@ -3,8 +3,8 @@ package net.java.joglutils.model; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.net.URL; import java.net.MalformedURLException; +import java.net.URL; /** * Utility class that allows transparent reading of files from the current diff --git a/src/net/java/joglutils/model/examples/DisplayListRenderer.java b/src/net/java/joglutils/model/examples/DisplayListRenderer.java index 4989356..4f3c63f 100644 --- a/src/net/java/joglutils/model/examples/DisplayListRenderer.java +++ b/src/net/java/joglutils/model/examples/DisplayListRenderer.java @@ -9,164 +9,173 @@ package net.java.joglutils.model.examples;
-import net.java.joglutils.model.*;
-import com.sun.opengl.util.texture.*;
-import com.sun.opengl.util.texture.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
+
import javax.imageio.ImageIO;
-import javax.media.opengl.*;
+
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2;
+import com.jogamp.opengl.GL2GL3;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLProfile;
+import com.jogamp.opengl.fixedfunc.GLLightingFunc;
+import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.opengl.util.texture.Texture;
+import com.jogamp.opengl.util.texture.TextureCoords;
+import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
+
import net.java.joglutils.model.ResourceRetriever;
+import net.java.joglutils.model.iModel3DRenderer;
import net.java.joglutils.model.geometry.Bounds;
import net.java.joglutils.model.geometry.Material;
import net.java.joglutils.model.geometry.Mesh;
import net.java.joglutils.model.geometry.Model;
import net.java.joglutils.model.geometry.Vec4;
-import net.java.joglutils.model.iModel3DRenderer;
/**
*
* @author RodgersGB
- *
+ *
* modifications made by Brian Wood and Z-Knight
*/
public class DisplayListRenderer implements iModel3DRenderer {
private static DisplayListRenderer instance = new DisplayListRenderer();
- private DisplayListCache listCache = new DisplayListCache();
+ private final DisplayListCache listCache = new DisplayListCache();
private HashMap<Integer, Texture> texture;
private int modelBoundsList = -1;
private int objectBoundsList = 1;
private boolean isDebugging = true;
-
+
/** Creates a new instance of DisplayListModel3D */
public DisplayListRenderer() {
}
-
+
public static DisplayListRenderer getInstance() {
return instance;
}
- public void debug(boolean value) {
+ public void debug(final boolean value) {
this.isDebugging = value;
}
-
- public void render(Object context, Model model)
+
+ public void render(final Object context, final Model model)
{
GL2 gl = null;
-
+
if (context instanceof GL2)
gl = (GL2) context;
-
+
else if (context instanceof GLAutoDrawable)
gl = ((GLAutoDrawable) context).getGL().getGL2();
-
+
if (gl == null) {
return;
}
-
+
if (model == null) {
return;
}
-
+
int displayList = listCache.get(model);
-
+
if(displayList < 0) {
displayList = initialize(gl, model);
if (this.isDebugging)
System.out.println("Initialized the display list for model: " + model.getSource());
}
-
+
// save some current state variables
- boolean isTextureEnabled = gl.glIsEnabled(GL2.GL_TEXTURE_2D);
- boolean isLightingEnabled = gl.glIsEnabled(GL2.GL_LIGHTING);
- boolean isMaterialEnabled = gl.glIsEnabled(GL2.GL_COLOR_MATERIAL);
-
+ final boolean isTextureEnabled = gl.glIsEnabled(GL.GL_TEXTURE_2D);
+ final boolean isLightingEnabled = gl.glIsEnabled(GLLightingFunc.GL_LIGHTING);
+ final boolean isMaterialEnabled = gl.glIsEnabled(GLLightingFunc.GL_COLOR_MATERIAL);
+
// check lighting
- if (!model.isUsingLighting()) { gl.glDisable(GL2.GL_LIGHTING); }
-
+ if (!model.isUsingLighting()) { gl.glDisable(GLLightingFunc.GL_LIGHTING); }
+
// check texture
- if (model.isUsingTexture()) { gl.glEnable(GL2.GL_TEXTURE_2D); }
- else { gl.glDisable(GL2.GL_TEXTURE_2D); }
-
+ if (model.isUsingTexture()) { gl.glEnable(GL.GL_TEXTURE_2D); }
+ else { gl.glDisable(GL.GL_TEXTURE_2D); }
+
// check wireframe
- if (model.isRenderingAsWireframe()) { gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE); }
- else { gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL); }
-
- gl.glDisable(GL2.GL_COLOR_MATERIAL);
-
+ if (model.isRenderingAsWireframe()) { gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_LINE); }
+ else { gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL); }
+
+ gl.glDisable(GLLightingFunc.GL_COLOR_MATERIAL);
+
gl.glPushMatrix();
-
+
// check for unit size model
if (model.isUnitizeSize()) {
- float scale = 1.0f/model.getBounds().getRadius();
+ final float scale = 1.0f/model.getBounds().getRadius();
gl.glScalef(scale, scale, scale);
}
-
+
if (model.isCentered()) {
- Vec4 center = model.getCenterPoint();
+ final Vec4 center = model.getCenterPoint();
gl.glTranslatef(-center.x, -center.y, -center.z);
}
-
+
if (model.isRenderModel())
gl.glCallList(displayList);
-
+
// Disabled lighting for drawing the boundary lines so they are all white (or whatever I chose)
- gl.glDisable(GL2.GL_LIGHTING);
+ gl.glDisable(GLLightingFunc.GL_LIGHTING);
if (model.isRenderModelBounds())
gl.glCallList(modelBoundsList);
if (model.isRenderObjectBounds())
gl.glCallList(objectBoundsList);
-
+
gl.glPopMatrix();
// Reset the flags back for lighting and texture
if (isTextureEnabled) {
- gl.glEnable(GL2.GL_TEXTURE_2D);
+ gl.glEnable(GL.GL_TEXTURE_2D);
} else {
- gl.glDisable(GL2.GL_TEXTURE_2D);
+ gl.glDisable(GL.GL_TEXTURE_2D);
}
if (isLightingEnabled) {
- gl.glEnable(GL2.GL_LIGHTING);
+ gl.glEnable(GLLightingFunc.GL_LIGHTING);
} else {
- gl.glDisable(GL2.GL_LIGHTING);
+ gl.glDisable(GLLightingFunc.GL_LIGHTING);
}
if (isMaterialEnabled) {
- gl.glEnable(GL2.GL_COLOR_MATERIAL);
+ gl.glEnable(GLLightingFunc.GL_COLOR_MATERIAL);
} else {
- gl.glDisable(GL2.GL_COLOR_MATERIAL);
+ gl.glDisable(GLLightingFunc.GL_COLOR_MATERIAL);
}
}
-
+
/**
* Load the model and associated materials, etc
- *
+ *
* @param gl
* @param file
* @return
*/
- private int initialize(GL2 gl, Model model)
+ private int initialize(final GL2 gl, final Model model)
{
if (this.isDebugging)
System.out.println("Initialize Model: " + model.getSource());
-
- int numMaterials = model.getNumberOfMaterials();
-
+
+ final int numMaterials = model.getNumberOfMaterials();
+
if (this.isDebugging && numMaterials > 0) {
- System.out.println("\n Loading " + numMaterials + " Materials:");
+ System.out.println("\n Loading " + numMaterials + " Materials:");
}
-
- String file = model.getSource();
+
+ final String file = model.getSource();
texture = new HashMap<Integer, Texture>();
for (int i=0; i<numMaterials; i++) {
// TODO:DELETE THIS OLD LINE loadTexture(materials.get(i).strFile, i);
// TODO:DELETE THIS OLD LINE materials.get(i).texureId = i;
-
+
String subFileName = "";
-
+
// If this is read from a jar file, then try to find the path relative to the model
int index = file.lastIndexOf('/');
if (index != -1) {
@@ -175,118 +184,118 @@ public class DisplayListRenderer implements iModel3DRenderer { // Else, the file path of the model was not from a jar file, so check maybe it
// was from a local file and get that path.
index = file.lastIndexOf('\\');
-
+
if (index != -1) {
subFileName = file.substring(0,index+1);
}
}
-
+
if (model.getMaterial(i).strFile != null) {
if (this.isDebugging)
- System.out.print(" Material: " + subFileName + model.getMaterial(i).strFile);
-
+ System.out.print(" Material: " + subFileName + model.getMaterial(i).strFile);
+
URL result;
try {
result = ResourceRetriever.getResourceAsUrl(subFileName + model.getMaterial(i).strFile);
- } catch(IOException e) {
+ } catch(final IOException e) {
if (this.isDebugging)
System.err.println(" ... failed");
continue;
}
if (result != null && !result.getPath().endsWith("/") && !result.getPath().endsWith("\\")) {
- loadTexture(result, i);
+ loadTexture(gl.getGLProfile(), result, i);
model.getMaterial(i).textureId = i;
if (this.isDebugging)
System.out.println(" ... done. Texture ID: " + i);
} else if (this.isDebugging) {
System.out.println(" ... failed (no result for material)");
- }
- }
+ }
+ }
}
-
+
if (this.isDebugging && numMaterials > 0) {
- System.out.println(" Load Materials: Done");
+ System.out.println(" Load Materials: Done");
}
-
+
if (this.isDebugging)
System.out.println("\n Generate Lists:");
- int compiledList = listCache.generateList(model, gl, 3);
-
+ final int compiledList = listCache.generateList(model, gl, 3);
+
if (this.isDebugging)
- System.out.println(" Model List");
+ System.out.println(" Model List");
gl.glNewList(compiledList, GL2.GL_COMPILE);
genList(gl, model);
gl.glEndList();
-
+
modelBoundsList = compiledList + 1;
if (this.isDebugging)
- System.out.println(" Boundary List");
+ System.out.println(" Boundary List");
gl.glNewList(modelBoundsList, GL2.GL_COMPILE);
genModelBoundsList(gl, model);
gl.glEndList();
-
+
objectBoundsList = compiledList + 2;
-
+
if (this.isDebugging)
- System.out.println(" Object Boundary List");
+ System.out.println(" Object Boundary List");
gl.glNewList(objectBoundsList, GL2.GL_COMPILE);
genObjectBoundsList(gl, model);
gl.glEndList();
-
+
if (this.isDebugging)
{
System.out.println(" Generate Lists: Done");
System.out.println("Load Model: Done");
}
-
+
return compiledList;
}
-
+
/**
* Load a texture given by the specified URL and assign it to the texture
* id that is passed in.
- *
+ *
* @param url
* @param id
*/
- private void loadTexture(URL url, int id) {
+ private void loadTexture(final GLProfile glp, final URL url, final int id) {
if ( url != null ) {
BufferedImage bufferedImage = null;
try {
bufferedImage = ImageIO.read(url);
- } catch (Exception e) {
+ } catch (final Exception e) {
System.err.println(" ... FAILED loading texture with exception: "+e.getMessage());
return;
}
-
- texture.put(id, AWTTextureIO.newTexture(bufferedImage, true));
+
+ texture.put(id, AWTTextureIO.newTexture(glp, bufferedImage, true));
}
}
-
+
/**
* Generate the model display list
- *
+ *
* @param gl
*/
- private void genList(GL2 gl, Model model) {
+ private void genList(final GL2 gl, final Model model) {
TextureCoords coords;
-
+
for (int i=0; i<model.getNumberOfMeshes(); i++) {
- Mesh tempObj = model.getMesh(i);
-
+ final Mesh tempObj = model.getMesh(i);
+
if (tempObj.numOfFaces == 0) {
System.err.println("Mesh: " +tempObj.name + " has no faces");
continue;
}
-
+
if(tempObj.hasTexture && texture.get(tempObj.materialID) != null) {
- Texture t = texture.get(tempObj.materialID);
-
+ final Texture t = texture.get(tempObj.materialID);
+
// switch to texture mode and push a new matrix on the stack
- gl.glMatrixMode(GL2.GL_TEXTURE);
+ gl.glMatrixMode(GL.GL_TEXTURE);
gl.glPushMatrix();
// check to see if the texture needs flipping
@@ -296,26 +305,26 @@ public class DisplayListRenderer implements iModel3DRenderer { }
// switch to modelview matrix and push a new matrix on the stack
- gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glPushMatrix();
// This is required to repeat textures...because some are not and so only
// part of the model gets filled in....Might be a way to check if this is
// required per object but I'm not sure...would need to research this.
- gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
- gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
// enable, bind and get texture coordinates
- t.enable();
- t.bind();
+ t.enable(gl);
+ t.bind(gl);
coords = t.getImageTexCoords();
}
-
+
for (int j=0; j<tempObj.numOfFaces; j++) {
// If the object has a texture, then do nothing till later...else
// apply the material property to it.
- if(tempObj.hasTexture) {
+ if(tempObj.hasTexture) {
// nothing
// Has no texture but has a material instead and this material is
@@ -324,14 +333,14 @@ public class DisplayListRenderer implements iModel3DRenderer { // with a FACE and not an OBJECT
} else {
if (tempObj.faces[j].materialID < model.getNumberOfMaterials()) {
- float[] rgba = new float[4];
-
- Material material = model.getMaterial(tempObj.faces[j].materialID);
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_DIFFUSE, material.diffuseColor.getRGBComponents(rgba), 0);
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT, material.ambientColor.getRGBComponents(rgba), 0);
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, material.specularColor.getRGBComponents(rgba), 0);
- gl.glMaterialf(GL2.GL_FRONT, GL2.GL_SHININESS, material.shininess);
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_EMISSION, material.emissive.getRGBComponents(rgba), 0);
+ final float[] rgba = new float[4];
+
+ final Material material = model.getMaterial(tempObj.faces[j].materialID);
+ gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_DIFFUSE, material.diffuseColor.getRGBComponents(rgba), 0);
+ gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT, material.ambientColor.getRGBComponents(rgba), 0);
+ gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SPECULAR, material.specularColor.getRGBComponents(rgba), 0);
+ gl.glMaterialf(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, material.shininess);
+ gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_EMISSION, material.emissive.getRGBComponents(rgba), 0);
}
}
@@ -346,12 +355,12 @@ public class DisplayListRenderer implements iModel3DRenderer { try {
normalIndex = tempObj.faces[j].normalIndex[whichVertex];
-
+
indexType = 0;
gl.glNormal3f(tempObj.normals[normalIndex].x, tempObj.normals[normalIndex].y, tempObj.normals[normalIndex].z);
if (tempObj.hasTexture) {
- if (tempObj.texCoords != null) {
+ if (tempObj.texCoords != null) {
textureIndex = tempObj.faces[j].coordIndex[whichVertex];
indexType = 1;
gl.glTexCoord2f(tempObj.texCoords[textureIndex].u, tempObj.texCoords[textureIndex].v);
@@ -360,113 +369,113 @@ public class DisplayListRenderer implements iModel3DRenderer { indexType = 2;
gl.glVertex3f(tempObj.vertices[vertexIndex].x, tempObj.vertices[vertexIndex].y, tempObj.vertices[vertexIndex].z);
}
- catch (Exception e) {
+ catch (final Exception e) {
e.printStackTrace();
switch (indexType) {
case 0:
System.err.println("Normal index " + normalIndex + " is out of bounds");
break;
-
+
case 1:
System.err.println("Texture index " + textureIndex + " is out of bounds");
break;
-
+
case 2:
System.err.println("Vertex index " + vertexIndex + " is out of bounds");
break;
}
}
}
- gl.glEnd();
+ gl.glEnd();
}
if (tempObj.hasTexture) {
- Texture t = texture.get(tempObj.materialID);
+ final Texture t = texture.get(tempObj.materialID);
if (t != null)
- t.disable();
-
- gl.glMatrixMode(GL2.GL_TEXTURE);
+ t.disable(gl);
+
+ gl.glMatrixMode(GL.GL_TEXTURE);
gl.glPopMatrix();
- gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glPopMatrix();
}
}
-
+
// Try this clearing of color so it won't use the previous color
gl.glColor3f(1.0f, 1.0f, 1.0f);
}
-
+
/**
- * Render the desired object of the model (specified by an id number of
+ * Render the desired object of the model (specified by an id number of
* the object)
- *
+ *
* @param gl
* @param id
*/
- public void renderBoundsOfObject(GL2 gl, int id, Model model) {
+ public void renderBoundsOfObject(final GL2 gl, final int id, final Model model) {
if (id >=0 && id <= model.getNumberOfMeshes()) {
if (model.getMesh(id).bounds != null) {
drawBounds(gl, model.getMesh(id).bounds);
}
}
}
-
+
/**
- * Draw the boundary of the model (the large box representing the entire
+ * Draw the boundary of the model (the large box representing the entire
* model and not the object in it)
- *
+ *
* @param gLDrawable
*/
- private void genModelBoundsList(GLAutoDrawable gLDrawable, Model model) {
- GL2 gl = gLDrawable.getGL().getGL2();
+ private void genModelBoundsList(final GLAutoDrawable gLDrawable, final Model model) {
+ final GL2 gl = gLDrawable.getGL().getGL2();
drawBounds(gl, model.getBounds());
}
-
+
/**
- * Draw the boundary of the model (the large box representing the entire
+ * Draw the boundary of the model (the large box representing the entire
* model and not the object in it)
- *
+ *
* @param gl
*/
- private void genModelBoundsList(GL2 gl, Model model) {
+ private void genModelBoundsList(final GL2 gl, final Model model) {
drawBounds(gl, model.getBounds());
}
-
+
/**
* Draw the boundaries over all of the objects of the model
*
* @param gLDrawable
*/
- private void genObjectBoundsList(GLAutoDrawable gLDrawable, Model model) {
- GL2 gl = gLDrawable.getGL().getGL2();
+ private void genObjectBoundsList(final GLAutoDrawable gLDrawable, final Model model) {
+ final GL2 gl = gLDrawable.getGL().getGL2();
genObjectBoundsList(gl, model);
- }
-
+ }
+
/**
* Draw the boundaries over all of the objects of the model
- *
+ *
* @param gl
*/
- private void genObjectBoundsList(GL2 gl, Model model) {
+ private void genObjectBoundsList(final GL2 gl, final Model model) {
for (int i=0; i<model.getNumberOfMeshes(); i++) {
if (model.getMesh(i).bounds != null) {
drawBounds(gl, model.getMesh(i).bounds);
}
- }
+ }
}
- /**
- * Draws the bounding box of the object using the max and min extrema
+ /**
+ * Draws the bounding box of the object using the max and min extrema
* points.
*
* @param gl
* @param bounds
*/
- private void drawBounds(GL2 gl, Bounds bounds) {
+ private void drawBounds(final GL2 gl, final Bounds bounds) {
// Front Face
- gl.glBegin(GL2.GL_LINE_LOOP);
+ gl.glBegin(GL.GL_LINE_LOOP);
gl.glVertex3f(bounds.min.x, bounds.min.y, bounds.min.z);
gl.glVertex3f(bounds.max.x, bounds.min.y, bounds.min.z);
gl.glVertex3f(bounds.max.x, bounds.max.y, bounds.min.z);
@@ -474,15 +483,15 @@ public class DisplayListRenderer implements iModel3DRenderer { gl.glEnd();
// Back Face
- gl.glBegin(GL2.GL_LINE_LOOP);
+ gl.glBegin(GL.GL_LINE_LOOP);
gl.glVertex3f(bounds.min.x, bounds.min.y, bounds.max.z);
gl.glVertex3f(bounds.max.x, bounds.min.y, bounds.max.z);
gl.glVertex3f(bounds.max.x, bounds.max.y, bounds.max.z);
gl.glVertex3f(bounds.min.x, bounds.max.y, bounds.max.z);
- gl.glEnd();
+ gl.glEnd();
// Connect the corners between the front and back face.
- gl.glBegin(GL2.GL_LINES);
+ gl.glBegin(GL.GL_LINES);
gl.glVertex3f(bounds.min.x, bounds.min.y, bounds.min.z);
gl.glVertex3f(bounds.min.x, bounds.min.y, bounds.max.z);
@@ -496,29 +505,29 @@ public class DisplayListRenderer implements iModel3DRenderer { gl.glVertex3f(bounds.min.x, bounds.max.y, bounds.max.z);
gl.glEnd();
}
-
+
/**
* Convert an Unsigned byte to integer
- *
+ *
* @param b
* @return
*/
- public int unsignedByteToInt(byte b) {
- return (int) b & 0xFF;
+ public int unsignedByteToInt(final byte b) {
+ return b & 0xFF;
}
-
+
/**
* Convert integer to float
- *
+ *
* @param i
* @return
*/
- public float intToFloat(int i) {
- return (float) i / 255.0f;
+ public float intToFloat(final int i) {
+ return i / 255.0f;
}
-
+
public class DisplayListCache {
- private HashMap <Object, Integer>listCache;
+ private final HashMap <Object, Integer>listCache;
/** Creates a new instance of WWDisplayListCache */
private DisplayListCache() {
@@ -529,37 +538,37 @@ public class DisplayListRenderer implements iModel3DRenderer { listCache.clear();
}
- public int get(Object objID) {
+ public int get(final Object objID) {
if (listCache.containsKey(objID))
return listCache.get(objID);
else
return -1;
}
- public void remove(Object objID, GL2 gl, int howMany) {
- Integer list = listCache.get(objID);
+ public void remove(final Object objID, final GL2 gl, final int howMany) {
+ final Integer list = listCache.get(objID);
if(list != null)
gl.glDeleteLists(list, howMany);
-
+
listCache.remove(objID);
}
/**
- * Returns an integer identifier for an OpenGL display list based on the
- * object being passed in. If the object already has a display list
+ * Returns an integer identifier for an OpenGL display list based on the
+ * object being passed in. If the object already has a display list
* allocated, the existing ID is returned.
*/
- public int generateList(Object objID, GL2 gl, int howMany) {
- Integer list = null;
+ public int generateList(final Object objID, final GL2 gl, final int howMany) {
+ Integer list = null;
list = listCache.get(objID);
if(list == null){
list = new Integer(gl.glGenLists(howMany));
- listCache.put(objID, list);
- }
+ listCache.put(objID, list);
+ }
return list;
- }
+ }
}
}
diff --git a/src/net/java/joglutils/model/examples/ModelTest.java b/src/net/java/joglutils/model/examples/ModelTest.java index f92ebd8..3973216 100644 --- a/src/net/java/joglutils/model/examples/ModelTest.java +++ b/src/net/java/joglutils/model/examples/ModelTest.java @@ -32,77 +32,85 @@ * You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Modifications made by Z-Knight
*/
package net.java.joglutils.model.examples;
-import net.java.joglutils.model.*;
-import com.sun.opengl.util.Animator;
import java.awt.Frame;
+import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
+import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
-import javax.media.opengl.awt.GLCanvas;
-import javax.swing.*;
+
+import javax.swing.SwingUtilities;
import javax.swing.event.MouseInputAdapter;
-import java.awt.event.MouseEvent;
-import javax.media.opengl.*;
-import java.awt.*;
-import javax.media.opengl.glu.GLU;
+
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2;
+import com.jogamp.opengl.GL2ES1;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLEventListener;
+import com.jogamp.opengl.awt.GLCanvas;
+import com.jogamp.opengl.fixedfunc.GLLightingFunc;
+import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.opengl.glu.GLU;
+import com.jogamp.opengl.util.Animator;
+
import net.java.joglutils.model.ModelFactory;
import net.java.joglutils.model.ModelLoadException;
-import net.java.joglutils.model.geometry.Model;
import net.java.joglutils.model.iModel3DRenderer;
+import net.java.joglutils.model.geometry.Model;
public class ModelTest {
-
+
/** Creates a new instance of Main */
public ModelTest() {
}
- public static void main(String[] args)
+ public static void main(final String[] args)
{
- Frame frame = new Frame();
- GLCanvas canvas = new GLCanvas();
+ final Frame frame = new Frame();
+ final GLCanvas canvas = new GLCanvas();
final Renderer renderer = new Renderer();
-
- MouseHandler inputMouseHandler = new MouseHandler(renderer);
- canvas.addMouseListener(inputMouseHandler);
- canvas.addMouseMotionListener(inputMouseHandler);
+
+ final MouseHandler inputMouseHandler = new MouseHandler(renderer);
+ canvas.addMouseListener(inputMouseHandler);
+ canvas.addMouseMotionListener(inputMouseHandler);
canvas.addKeyListener(new KeyListener() {
- public void keyTyped(KeyEvent e) {
- Model model = renderer.getModel();
+ public void keyTyped(final KeyEvent e) {
+ final Model model = renderer.getModel();
if (model == null)
return;
-
+
switch (e.getKeyChar()) {
case 'w':
model.setRenderAsWireframe(!model.isRenderingAsWireframe());
break;
-
+
case 'l':
model.setUseLighting(!model.isUsingLighting());
break;
}
}
- public void keyPressed(KeyEvent e) {
+ public void keyPressed(final KeyEvent e) {
}
- public void keyReleased(KeyEvent e) {
+ public void keyReleased(final KeyEvent e) {
}
});
-
+
canvas.addGLEventListener(renderer);
frame.add(canvas);
frame.add(canvas);
frame.setSize(600, 600);
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
+ public void windowClosing(final WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
@@ -120,71 +128,71 @@ public class ModelTest { static class Renderer implements GLEventListener
{
- private GLU glu = new GLU();
+ private final GLU glu = new GLU();
private Model model;
private iModel3DRenderer modelRenderer;
-
+
/** Scale Factor for zooming */
private float scaleAll = 1.0f;
-
+
/** Rotation factor around X */
private float rotX = 0.0f;
-
- /** Rotation factor around Y */
+
+ /** Rotation factor around Y */
private float rotY = 0.0f;
-
+
/** A mouse point */
- private Point mousePoint = new Point();
-
+ private final Point mousePoint = new Point();
+
/** The closest that one can zoom in to */
private static final float MIN_SCALE = 0.1f;
-
+
/** The farthest that one can zoom out to */
private static final float MAX_SCALE = 10000.9f;
-
+
/** The radius of the boundary of the model that is loaded */
private float radius = 1.0f;
-
+
/** Ambient light array */
float[] lightAmbient = {0.3f, 0.3f, 0.3f, 1.0f};
-
+
/** Diffuse light array */
float[] lightDiffuse = {0.5f, 0.5f, 0.5f, 1.0f};
-
+
/** Specular light array */
float[] lightSpecular = {0.5f, 0.5f, 0.5f, 1.0f};
-
+
/**
* Display method
- *
+ *
* @param gLDrawable
*/
- public void display(GLAutoDrawable gLDrawable)
+ public void display(final GLAutoDrawable gLDrawable)
{
final GL2 gl = gLDrawable.getGL().getGL2();
- gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
-
+
glu.gluLookAt(0,0,10, 0,0,0, 0,1,0);
-
+
// Make sure the rotations don't keep growing
if (Math.abs(rotX) >= 360.0f) rotX = 0.0f;
if (Math.abs(rotY) >= 360.0f) rotY = 0.0f;
-
- // Draw the scene (by default, the lighting, material and textures
+
+ // Draw the scene (by default, the lighting, material and textures
// are enabled/disabled within the renderer for the model)
gl.glPushMatrix();
// Scale the model (used for zooming purposes)
gl.glScalef(scaleAll, scaleAll, scaleAll);
-
+
// Rotate the model based on mouse inputs
gl.glRotatef(rotY, 1.0f, 0.0f, 0.0f);
gl.glRotatef(rotX, 0.0f, 1.0f, 0.0f);
-
+
// Render the model
modelRenderer.render(gl, model);
gl.glPopMatrix();
-
+
gl.glFlush();
}
@@ -194,32 +202,32 @@ public class ModelTest { * @param modeChanged Indicates if the video mode has changed.
* @param deviceChanged Indicates if the video device has changed.
*/
- public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
+ public void displayChanged(final GLAutoDrawable drawable, final boolean modeChanged, final boolean deviceChanged) {}
/** Called by the drawable immediately after the OpenGL context is
* initialized for the first time. Can be used to perform one-time OpenGL
* initialization such as setup of lights and display lists.
* @param gLDrawable The GLDrawable object.
*/
- public void init(GLAutoDrawable gLDrawable)
+ public void init(final GLAutoDrawable gLDrawable)
{
final GL2 gl = gLDrawable.getGL().getGL2();
-
+
try
{
// Get an instance of the display list renderer a renderer
modelRenderer = DisplayListRenderer.getInstance();
-
+
// Turn on debugging
modelRenderer.debug(true);
-
+
// Call the factory for a model from a local file
//model = ModelFactory.createModel("C:\\models\\apollo.3ds");
-
+
// Call the factory for a model from a jar file
model = ModelFactory.createModel("net/java/joglutils/model/examples/models/max3ds/apollo.3ds");
//model = ModelFactory.createModel("net/java/joglutils/model/examples/models/obj/penguin.obj");
-
+
// When loading the model, adjust the center to the boundary center
model.centerModelOnPosition(true);
@@ -236,37 +244,37 @@ public class ModelTest { // Get the radius of the model to use for lighting and view presetting
radius = model.getBounds().getRadius();
-
+
}
- catch (ModelLoadException ex)
+ catch (final ModelLoadException ex)
{
ex.printStackTrace();
}
-
+
// Set the light
- float lightPosition[] = { 0, 50000000, 0, 1.0f };
- float[] model_ambient = {0.5f, 0.5f, 0.5f, 1.0f};
-
- gl.glLightModelfv(GL2.GL_LIGHT_MODEL_AMBIENT, model_ambient, 0);
- gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, lightPosition, 0);
- gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, lightDiffuse, 0);
- gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, lightAmbient, 0);
- gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, lightSpecular, 0);
-
- gl.glEnable(GL2.GL_LIGHT0);
- gl.glEnable(GL2.GL_LIGHTING);
- gl.glEnable(GL2.GL_NORMALIZE);
-
- gl.glEnable(GL2.GL_CULL_FACE);
- gl.glShadeModel(GL2.GL_SMOOTH);
+ final float lightPosition[] = { 0, 50000000, 0, 1.0f };
+ final float[] model_ambient = {0.5f, 0.5f, 0.5f, 1.0f};
+
+ gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT, model_ambient, 0);
+ gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_POSITION, lightPosition, 0);
+ gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_DIFFUSE, lightDiffuse, 0);
+ gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_AMBIENT, lightAmbient, 0);
+ gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_SPECULAR, lightSpecular, 0);
+
+ gl.glEnable(GLLightingFunc.GL_LIGHT0);
+ gl.glEnable(GLLightingFunc.GL_LIGHTING);
+ gl.glEnable(GLLightingFunc.GL_NORMALIZE);
+
+ gl.glEnable(GL.GL_CULL_FACE);
+ gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.glClearDepth(1.0f);
- gl.glEnable(GL2.GL_DEPTH_TEST);
- gl.glDepthFunc(GL2.GL_LEQUAL);
- gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ gl.glDepthFunc(GL.GL_LEQUAL);
+ gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
//gl.glLightModeli(GL2.GL_LIGHT_MODEL_TWO_SIDE, 0);
-
- gl.glMatrixMode(GL2.GL_MODELVIEW);
+
+ gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glPushMatrix();
}
@@ -284,7 +292,7 @@ public class ModelTest { * @param width The new width of the window.
* @param height The new height of the window.
*/
- public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height)
+ public void reshape(final GLAutoDrawable gLDrawable, final int x, final int y, final int width, int height)
{
final GL2 gl = gLDrawable.getGL().getGL2();
@@ -292,32 +300,32 @@ public class ModelTest { height = 1;
final float h = (float)width / (float)height;
gl.glViewport(0, 0, width, height);
- gl.glMatrixMode(GL2.GL_PROJECTION);
+ gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(-1, 1, -1, 1, -50, 50);
- gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity();
}
-
- public void dispose(GLAutoDrawable drawable) {
+
+ public void dispose(final GLAutoDrawable drawable) {
}
- /**
+ /**
* Get the point at the start of the mouse drag
- *
+ *
* @param MousePt
*/
- void startDrag( Point MousePt ) {
+ void startDrag( final Point MousePt ) {
mousePoint.x = MousePt.x;
- mousePoint.y = MousePt.y;
- }
-
+ mousePoint.y = MousePt.y;
+ }
+
/**
* Calculate the delta and rotation values for the dragging of the mouse
* @param MousePt
*/
- void drag( Point MousePt ) {
- Point delta = new Point();
+ void drag( final Point MousePt ) {
+ final Point delta = new Point();
delta.x = MousePt.x - mousePoint.x;
delta.y = MousePt.y - mousePoint.y;
@@ -327,64 +335,64 @@ public class ModelTest { rotX += delta.x * 2.0f / scaleAll;
rotY += delta.y * 2.0f / scaleAll;
}
-
- /**
+
+ /**
* Get the point at the start of the mouse zoom action
* @param MousePt
*/
- void startZoom( Point MousePt ) {
+ void startZoom( final Point MousePt ) {
mousePoint.x = MousePt.x;
mousePoint.y = MousePt.y;
}
-
- /**
+
+ /**
* Caclaulte the scaling parameters for zooming while the zoom drag
* is ongoing
- *
+ *
* @param MousePt
*/
- void zoom( Point MousePt ) {
- Point delta = new Point();
+ void zoom( final Point MousePt ) {
+ final Point delta = new Point();
delta.x = MousePt.x - mousePoint.x;
delta.y = MousePt.y - mousePoint.y;
mousePoint.x = MousePt.x;
mousePoint.y = MousePt.y;
- float addition = -(delta.x + delta.y) / 250.0f;
+ final float addition = -(delta.x + delta.y) / 250.0f;
if (addition < 0.0 && (scaleAll+addition) > MIN_SCALE) {
- scaleAll += addition;
- }
+ scaleAll += addition;
+ }
if (addition > 0.0 && (scaleAll+addition) < MAX_SCALE) {
scaleAll += addition;
- }
+ }
}
public Model getModel() {
return model;
}
- public void setModel(Model model) {
+ public void setModel(final Model model) {
this.model = model;
}
}
-
+
/**
* Moue handler class that allows the user to rotate and zoom on the model
- *
- *
+ *
+ *
*/
static class MouseHandler extends MouseInputAdapter {
- private Renderer renderer;
+ private final Renderer renderer;
/**
* Creates a new instance of the moouse handler
- *
+ *
* @param renderer
*/
- public MouseHandler(Renderer renderer) {
+ public MouseHandler(final Renderer renderer) {
//System.out.println(" Mouse Handler ");
this.renderer = renderer;
}
@@ -392,10 +400,10 @@ public class ModelTest { /**
* Handles the mouse click events
- *
+ *
* @param e
*/
- public void mouseClicked(MouseEvent e) {
+ public void mouseClicked(final MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
//System.out.println(" ---> RIGHT MOUSE BUTTON CLICKED ");
}
@@ -404,15 +412,15 @@ public class ModelTest { /**
* Handles the mouse press events
- *
+ *
* @param mouseEvent
*/
- public void mousePressed(MouseEvent mouseEvent) {
+ public void mousePressed(final MouseEvent mouseEvent) {
if (SwingUtilities.isLeftMouseButton(mouseEvent)) {
- //System.out.println(" ---> LEFT MOUSE BUTTON PRESSED ");
+ //System.out.println(" ---> LEFT MOUSE BUTTON PRESSED ");
renderer.startDrag(mouseEvent.getPoint());
} else if (SwingUtilities.isMiddleMouseButton(mouseEvent)) {
- //System.out.println(" ---> MIDDLE MOUSE BUTTON PRESSED ");
+ //System.out.println(" ---> MIDDLE MOUSE BUTTON PRESSED ");
renderer.startZoom(mouseEvent.getPoint());
}
}
@@ -420,15 +428,15 @@ public class ModelTest { /**
* Handles the mouse drag events
- *
+ *
* @param mouseEvent
*/
- public void mouseDragged(MouseEvent mouseEvent) {
+ public void mouseDragged(final MouseEvent mouseEvent) {
if (SwingUtilities.isLeftMouseButton(mouseEvent)) {
- //System.out.println(" ---> LEFT MOUSE BUTTON DRAGGED ");
+ //System.out.println(" ---> LEFT MOUSE BUTTON DRAGGED ");
renderer.drag(mouseEvent.getPoint());
} else if (SwingUtilities.isMiddleMouseButton(mouseEvent)) {
- //System.out.println(" ---> MIDDLE MOUSE BUTTON DRAGGED ");
+ //System.out.println(" ---> MIDDLE MOUSE BUTTON DRAGGED ");
renderer.zoom(mouseEvent.getPoint());
}
}
diff --git a/src/net/java/joglutils/model/geometry/Mesh.java b/src/net/java/joglutils/model/geometry/Mesh.java index 76af31e..57a3bf3 100644 --- a/src/net/java/joglutils/model/geometry/Mesh.java +++ b/src/net/java/joglutils/model/geometry/Mesh.java @@ -36,8 +36,6 @@ package net.java.joglutils.model.geometry;
-import java.util.Vector;
-
public class Mesh
{
public int numOfVerts = 0;
diff --git a/src/net/java/joglutils/model/loader/MaxLoader.java b/src/net/java/joglutils/model/loader/MaxLoader.java index d71baeb..7ba6887 100644 --- a/src/net/java/joglutils/model/loader/MaxLoader.java +++ b/src/net/java/joglutils/model/loader/MaxLoader.java @@ -41,6 +41,7 @@ import java.io.DataInputStream; import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+
import net.java.joglutils.model.ResourceRetriever;
import net.java.joglutils.model.geometry.Bounds;
import net.java.joglutils.model.geometry.Face;
diff --git a/src/net/java/joglutils/model/loader/WaveFrontLoader.java b/src/net/java/joglutils/model/loader/WaveFrontLoader.java index 2f9c1b1..e21539d 100644 --- a/src/net/java/joglutils/model/loader/WaveFrontLoader.java +++ b/src/net/java/joglutils/model/loader/WaveFrontLoader.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Vector;
+
import net.java.joglutils.model.ModelLoadException;
import net.java.joglutils.model.ResourceRetriever;
import net.java.joglutils.model.geometry.Bounds;
diff --git a/src/net/java/joglutils/msg/actions/Action.java b/src/net/java/joglutils/msg/actions/Action.java index b206cdb..1d3abf8 100644 --- a/src/net/java/joglutils/msg/actions/Action.java +++ b/src/net/java/joglutils/msg/actions/Action.java @@ -37,10 +37,12 @@ package net.java.joglutils.msg.actions; -import java.lang.reflect.*; +import java.lang.reflect.Method; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.ActionTable; +import net.java.joglutils.msg.misc.Path; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.nodes.Node; /** The base class of all actions, which are applied to nodes in the scene graph to implement operations such as rendering. <P> diff --git a/src/net/java/joglutils/msg/actions/GLRenderAction.java b/src/net/java/joglutils/msg/actions/GLRenderAction.java index b65c515..3fcad13 100644 --- a/src/net/java/joglutils/msg/actions/GLRenderAction.java +++ b/src/net/java/joglutils/msg/actions/GLRenderAction.java @@ -37,13 +37,14 @@ package net.java.joglutils.msg.actions; -import java.lang.reflect.*; +import java.lang.reflect.Method; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.ActionTable; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.nodes.Node; /** An action which performs rendering of a scene graph via OpenGL. <P> diff --git a/src/net/java/joglutils/msg/actions/GLResetAction.java b/src/net/java/joglutils/msg/actions/GLResetAction.java index e04d866..fef612e 100644 --- a/src/net/java/joglutils/msg/actions/GLResetAction.java +++ b/src/net/java/joglutils/msg/actions/GLResetAction.java @@ -37,10 +37,13 @@ package net.java.joglutils.msg.actions; -import java.lang.reflect.*; +import java.lang.reflect.Method; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.ActionTable; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.nodes.Node; +import net.java.joglutils.msg.nodes.ShaderNode; +import net.java.joglutils.msg.nodes.Texture2; /** An action which resets the OpenGL state of notes holding on to server-side OpenGL objects. This is needed to clear out for diff --git a/src/net/java/joglutils/msg/actions/RayPickAction.java b/src/net/java/joglutils/msg/actions/RayPickAction.java index ee2528a..0b32f47 100644 --- a/src/net/java/joglutils/msg/actions/RayPickAction.java +++ b/src/net/java/joglutils/msg/actions/RayPickAction.java @@ -38,12 +38,18 @@ package net.java.joglutils.msg.actions; import java.awt.Component; -import java.lang.reflect.*; -import java.util.*; - -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.java.joglutils.msg.math.Line; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.misc.ActionTable; +import net.java.joglutils.msg.misc.PickedPoint; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.nodes.Camera; +import net.java.joglutils.msg.nodes.Node; public class RayPickAction extends Action { // Boilerplate diff --git a/src/net/java/joglutils/msg/collections/Vec2fCollection.java b/src/net/java/joglutils/msg/collections/Vec2fCollection.java index d0dadc1..bf4ebb8 100644 --- a/src/net/java/joglutils/msg/collections/Vec2fCollection.java +++ b/src/net/java/joglutils/msg/collections/Vec2fCollection.java @@ -37,10 +37,10 @@ package net.java.joglutils.msg.collections; -import java.nio.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.impl.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.impl.BufferFactory; +import net.java.joglutils.msg.math.Vec2f; /** Provides the abstraction of a collection of Vec2f objects while allowing access to the backing store in the form of a direct diff --git a/src/net/java/joglutils/msg/collections/Vec3fCollection.java b/src/net/java/joglutils/msg/collections/Vec3fCollection.java index 887b4c9..5714d91 100644 --- a/src/net/java/joglutils/msg/collections/Vec3fCollection.java +++ b/src/net/java/joglutils/msg/collections/Vec3fCollection.java @@ -37,10 +37,10 @@ package net.java.joglutils.msg.collections; -import java.nio.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.impl.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.impl.BufferFactory; +import net.java.joglutils.msg.math.Vec3f; /** Provides the abstraction of a collection of Vec3f objects while allowing access to the backing store in the form of a direct diff --git a/src/net/java/joglutils/msg/collections/Vec4fCollection.java b/src/net/java/joglutils/msg/collections/Vec4fCollection.java index 2f940cd..1be28ef 100644 --- a/src/net/java/joglutils/msg/collections/Vec4fCollection.java +++ b/src/net/java/joglutils/msg/collections/Vec4fCollection.java @@ -37,10 +37,10 @@ package net.java.joglutils.msg.collections; -import java.nio.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.impl.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.impl.BufferFactory; +import net.java.joglutils.msg.math.Vec4f; /** Provides the abstraction of a collection of Vec4f objects while allowing access to the backing store in the form of a direct diff --git a/src/net/java/joglutils/msg/elements/BlendElement.java b/src/net/java/joglutils/msg/elements/BlendElement.java index 422811f..9df19c2 100644 --- a/src/net/java/joglutils/msg/elements/BlendElement.java +++ b/src/net/java/joglutils/msg/elements/BlendElement.java @@ -37,12 +37,10 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; - -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.math.Vec4f; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; +import net.java.joglutils.msg.nodes.Blend; /** Represents the blending state of the OpenGL fixed-function pipeline. */ diff --git a/src/net/java/joglutils/msg/elements/ColorElement.java b/src/net/java/joglutils/msg/elements/ColorElement.java index a3a92d4..117e026 100644 --- a/src/net/java/joglutils/msg/elements/ColorElement.java +++ b/src/net/java/joglutils/msg/elements/ColorElement.java @@ -37,10 +37,10 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents the current set of colors, which are applied on a per-vertex basis to any drawn geometry. */ diff --git a/src/net/java/joglutils/msg/elements/CoordinateElement.java b/src/net/java/joglutils/msg/elements/CoordinateElement.java index 58a57c7..383726b 100644 --- a/src/net/java/joglutils/msg/elements/CoordinateElement.java +++ b/src/net/java/joglutils/msg/elements/CoordinateElement.java @@ -37,10 +37,10 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents the current set of coordinates, which are assembled to draw geometry. */ diff --git a/src/net/java/joglutils/msg/elements/DepthTestElement.java b/src/net/java/joglutils/msg/elements/DepthTestElement.java index 36a21dd..e502414 100644 --- a/src/net/java/joglutils/msg/elements/DepthTestElement.java +++ b/src/net/java/joglutils/msg/elements/DepthTestElement.java @@ -36,11 +36,8 @@ package net.java.joglutils.msg.elements; -import javax.media.opengl.*; - -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents the depth test state of the OpenGL fixed-function pipeline. */ diff --git a/src/net/java/joglutils/msg/elements/Element.java b/src/net/java/joglutils/msg/elements/Element.java index 5937b65..11f2980 100644 --- a/src/net/java/joglutils/msg/elements/Element.java +++ b/src/net/java/joglutils/msg/elements/Element.java @@ -37,7 +37,8 @@ package net.java.joglutils.msg.elements; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents an element in the global {@link net.java.joglutils.msg.misc.State state}, such as the current 3D diff --git a/src/net/java/joglutils/msg/elements/GLBlendElement.java b/src/net/java/joglutils/msg/elements/GLBlendElement.java index 16e2266..78d67b5 100644 --- a/src/net/java/joglutils/msg/elements/GLBlendElement.java +++ b/src/net/java/joglutils/msg/elements/GLBlendElement.java @@ -37,13 +37,12 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.math.Vec4f; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.nodes.Blend; /** Represents the blending state of the OpenGL fixed-function pipeline and causes side-effects in OpenGL for rendering. */ diff --git a/src/net/java/joglutils/msg/elements/GLColorElement.java b/src/net/java/joglutils/msg/elements/GLColorElement.java index 0503e9a..16341ee 100644 --- a/src/net/java/joglutils/msg/elements/GLColorElement.java +++ b/src/net/java/joglutils/msg/elements/GLColorElement.java @@ -37,11 +37,12 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.misc.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; + +import net.java.joglutils.msg.misc.State; /** Represents the current set of colors, which are applied on a per-vertex basis to any drawn geometry, and causes side-effects in diff --git a/src/net/java/joglutils/msg/elements/GLCoordinateElement.java b/src/net/java/joglutils/msg/elements/GLCoordinateElement.java index aa59690..9af15b1 100644 --- a/src/net/java/joglutils/msg/elements/GLCoordinateElement.java +++ b/src/net/java/joglutils/msg/elements/GLCoordinateElement.java @@ -37,11 +37,12 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.misc.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; + +import net.java.joglutils.msg.misc.State; /** Represents the current set of coordinates, which are assembled to draw geometry, and causes side-effects in OpenGL. */ diff --git a/src/net/java/joglutils/msg/elements/GLDepthTestElement.java b/src/net/java/joglutils/msg/elements/GLDepthTestElement.java index 80840d1..89eec47 100644 --- a/src/net/java/joglutils/msg/elements/GLDepthTestElement.java +++ b/src/net/java/joglutils/msg/elements/GLDepthTestElement.java @@ -37,13 +37,10 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import com.jogamp.opengl.GL; +import com.jogamp.opengl.glu.GLU; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.State; /** Represents the depth test state of the OpenGL fixed-function pipeline and causes side-effects in OpenGL for rendering. */ diff --git a/src/net/java/joglutils/msg/elements/GLModelMatrixElement.java b/src/net/java/joglutils/msg/elements/GLModelMatrixElement.java index c10e436..93cdd72 100644 --- a/src/net/java/joglutils/msg/elements/GLModelMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/GLModelMatrixElement.java @@ -37,12 +37,11 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.misc.State; /** Represents the model matrix, which is the transformation applied to objects in the scene, and causes side-effects in OpenGL. */ diff --git a/src/net/java/joglutils/msg/elements/GLProjectionMatrixElement.java b/src/net/java/joglutils/msg/elements/GLProjectionMatrixElement.java index c811ba4..f1a7a64 100644 --- a/src/net/java/joglutils/msg/elements/GLProjectionMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/GLProjectionMatrixElement.java @@ -37,12 +37,11 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.misc.State; /** Represents the projection matrix, which transforms view-space coordinates into screen-space coordinates, and performs diff --git a/src/net/java/joglutils/msg/elements/GLShaderElement.java b/src/net/java/joglutils/msg/elements/GLShaderElement.java index 178a8f2..b939e41 100644 --- a/src/net/java/joglutils/msg/elements/GLShaderElement.java +++ b/src/net/java/joglutils/msg/elements/GLShaderElement.java @@ -36,14 +36,12 @@ package net.java.joglutils.msg.elements; -import java.util.*; +import com.jogamp.opengl.GL; +import com.jogamp.opengl.glu.GLU; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; - -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.Shader; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.nodes.ShaderNode; /** Represents the current shader, which is applied to any drawn geometry, and performs side-effects in OpenGL. */ diff --git a/src/net/java/joglutils/msg/elements/GLTextureCoordinateElement.java b/src/net/java/joglutils/msg/elements/GLTextureCoordinateElement.java index 50a871c..a5d793c 100644 --- a/src/net/java/joglutils/msg/elements/GLTextureCoordinateElement.java +++ b/src/net/java/joglutils/msg/elements/GLTextureCoordinateElement.java @@ -37,11 +37,12 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.misc.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; + +import net.java.joglutils.msg.misc.State; /** Represents the current set of texture coordinates, which are applied on a per-vertex basis to any drawn geometry, and performs diff --git a/src/net/java/joglutils/msg/elements/GLTextureElement.java b/src/net/java/joglutils/msg/elements/GLTextureElement.java index 7f903c3..e5259bc 100644 --- a/src/net/java/joglutils/msg/elements/GLTextureElement.java +++ b/src/net/java/joglutils/msg/elements/GLTextureElement.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - 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,22 +28,23 @@ * 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. - * + * */ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; -import com.sun.opengl.util.texture.*; +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.GL2ES1; +import com.jogamp.opengl.glu.GLU; +import com.jogamp.opengl.util.texture.Texture; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.nodes.Texture2; /** Represents the current texture, which is applied to any drawn geometry if texture coordinates are also supplied, and performs @@ -54,54 +55,54 @@ public class GLTextureElement extends TextureElement { public Element newInstance() { return new GLTextureElement(); } - public static GLTextureElement getInstance(State state) { + public static GLTextureElement getInstance(final State state) { return (GLTextureElement) TextureElement.getInstance(state); } - public static void enable(State defaultState) { - Element tmp = new GLTextureElement(); + public static void enable(final State defaultState) { + final Element tmp = new GLTextureElement(); defaultState.setElement(tmp.getStateIndex(), tmp); } - public void pop(State state, Element previousTopElement) { + public void pop(final State state, final Element previousTopElement) { // Put things back the way they were switchTextures(((GLTextureElement) previousTopElement).texture, texture); } - public void setElt(Texture2 texture) { - Texture2 prev = this.texture; + public void setElt(final Texture2 texture) { + final Texture2 prev = this.texture; super.setElt(texture); switchTextures(prev, texture); } - private void switchTextures(Texture2 prev, Texture2 texture) { - GL2 gl = GLU.getCurrentGL().getGL2(); + private void switchTextures(final Texture2 prev, final Texture2 texture) { + final GL2 gl = GLU.getCurrentGL().getGL2(); Texture prevTexture = null; Texture curTexture = null; int texEnvMode = 0; if (prev != null) { - prevTexture = prev.getTexture(); + prevTexture = prev.getTexture(gl); } if (texture != null) { - curTexture = texture.getTexture(); + curTexture = texture.getTexture(gl); texEnvMode = texture.getTexEnvMode(); } // FIXME: should be smarter about this; if the target is the same // for the previous and current textures, just bind the new one if (prevTexture != null) { - prevTexture.disable(); + prevTexture.disable(gl); } if (curTexture != null) { - curTexture.enable(); - curTexture.bind(); + curTexture.enable(gl); + curTexture.bind(gl); int glEnvMode = 0; switch (texEnvMode) { - case Texture2.MODULATE: glEnvMode = GL2.GL_MODULATE; break; - case Texture2.DECAL: glEnvMode = GL2.GL_DECAL; break; - case Texture2.BLEND: glEnvMode = GL2.GL_BLEND; break; - case Texture2.REPLACE: glEnvMode = GL2.GL_REPLACE; break; + case Texture2.MODULATE: glEnvMode = GL2ES1.GL_MODULATE; break; + case Texture2.DECAL: glEnvMode = GL2ES1.GL_DECAL; break; + case Texture2.BLEND: glEnvMode = GL.GL_BLEND; break; + case Texture2.REPLACE: glEnvMode = GL.GL_REPLACE; break; } - gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, glEnvMode); + gl.glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, glEnvMode); } } } diff --git a/src/net/java/joglutils/msg/elements/GLViewingMatrixElement.java b/src/net/java/joglutils/msg/elements/GLViewingMatrixElement.java index cff9fe3..ae5c0eb 100644 --- a/src/net/java/joglutils/msg/elements/GLViewingMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/GLViewingMatrixElement.java @@ -37,12 +37,11 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; -import javax.media.opengl.glu.*; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.glu.GLU; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.misc.State; /** Represents the viewing matrix, which contains the transformation between the camera and the model, and performs side-effects in diff --git a/src/net/java/joglutils/msg/elements/ModelMatrixElement.java b/src/net/java/joglutils/msg/elements/ModelMatrixElement.java index e4cdbb0..35b0cfc 100644 --- a/src/net/java/joglutils/msg/elements/ModelMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/ModelMatrixElement.java @@ -37,8 +37,9 @@ package net.java.joglutils.msg.elements; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents the model matrix, which is the transformation applied to objects in the scene. */ diff --git a/src/net/java/joglutils/msg/elements/ProjectionMatrixElement.java b/src/net/java/joglutils/msg/elements/ProjectionMatrixElement.java index 4635a83..ce12598 100644 --- a/src/net/java/joglutils/msg/elements/ProjectionMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/ProjectionMatrixElement.java @@ -37,8 +37,9 @@ package net.java.joglutils.msg.elements; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents the projection matrix, which transforms view-space coordinates into screen-space coordinates. */ diff --git a/src/net/java/joglutils/msg/elements/ShaderElement.java b/src/net/java/joglutils/msg/elements/ShaderElement.java index 8b1a3fe..a7fde42 100644 --- a/src/net/java/joglutils/msg/elements/ShaderElement.java +++ b/src/net/java/joglutils/msg/elements/ShaderElement.java @@ -37,8 +37,9 @@ package net.java.joglutils.msg.elements; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; +import net.java.joglutils.msg.nodes.ShaderNode; /** Represents the current vertex/fragment shader, which is applied to any drawn geometry. */ diff --git a/src/net/java/joglutils/msg/elements/TextureCoordinateElement.java b/src/net/java/joglutils/msg/elements/TextureCoordinateElement.java index 8d24bfc..579bcbd 100644 --- a/src/net/java/joglutils/msg/elements/TextureCoordinateElement.java +++ b/src/net/java/joglutils/msg/elements/TextureCoordinateElement.java @@ -37,10 +37,10 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; +import java.nio.FloatBuffer; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents the current set of texture coordinates, which are applied on a per-vertex basis to any drawn geometry. */ diff --git a/src/net/java/joglutils/msg/elements/TextureElement.java b/src/net/java/joglutils/msg/elements/TextureElement.java index 413be67..9107ef9 100644 --- a/src/net/java/joglutils/msg/elements/TextureElement.java +++ b/src/net/java/joglutils/msg/elements/TextureElement.java @@ -37,11 +37,9 @@ package net.java.joglutils.msg.elements; -import java.nio.*; -import javax.media.opengl.*; - -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; +import net.java.joglutils.msg.nodes.Texture2; /** Represents the current texture, which is applied to any drawn geometry if texture coordinates are also supplied. */ diff --git a/src/net/java/joglutils/msg/elements/ViewingMatrixElement.java b/src/net/java/joglutils/msg/elements/ViewingMatrixElement.java index b561bd8..4c0001b 100644 --- a/src/net/java/joglutils/msg/elements/ViewingMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/ViewingMatrixElement.java @@ -37,8 +37,9 @@ package net.java.joglutils.msg.elements; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.StateIndex; /** Represents the viewing matrix, which contains the transformation between the camera and the model. */ diff --git a/src/net/java/joglutils/msg/impl/BufferFactory.java b/src/net/java/joglutils/msg/impl/BufferFactory.java index 191c5c7..3ad80dd 100644 --- a/src/net/java/joglutils/msg/impl/BufferFactory.java +++ b/src/net/java/joglutils/msg/impl/BufferFactory.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - 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,18 +28,22 @@ * 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. - * + * */ package net.java.joglutils.msg.impl; -import java.nio.*; -import java.util.*; -import com.sun.opengl.util.*; +import java.nio.ByteBuffer; +import java.nio.DoubleBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; + +import com.jogamp.common.nio.Buffers; /** Assists in allocation of direct Buffers. On some platforms when a small direct Buffer is allocated there is a large amount of @@ -57,82 +61,82 @@ public class BufferFactory { // I believe the rounding-up size of direct Buffers on Unix platforms is 8K private static final int CHUNK_SIZE = 8 * 1024; - public static synchronized ByteBuffer newByteBuffer(int numElements) { - int sz = numElements * BufferUtil.SIZEOF_BYTE; + public static synchronized ByteBuffer newByteBuffer(final int numElements) { + final int sz = numElements * Buffers.SIZEOF_BYTE; if (sz > CHUNK_SIZE) { // Just allocate a fresh ByteBuffer and don't worry about // rounding up its allocation size and re-using the end portion - return BufferUtil.newByteBuffer(numElements); + return Buffers.newDirectByteBuffer(numElements); } if (curByteBuf == null || curByteBuf.remaining() < numElements) { - curByteBuf = BufferUtil.newByteBuffer(CHUNK_SIZE / BufferUtil.SIZEOF_BYTE); + curByteBuf = Buffers.newDirectByteBuffer(CHUNK_SIZE / Buffers.SIZEOF_BYTE); } curByteBuf.limit(curByteBuf.position() + numElements); - ByteBuffer res = curByteBuf.slice(); + final ByteBuffer res = curByteBuf.slice(); curByteBuf.position(curByteBuf.limit()); return res; } - public static synchronized ShortBuffer newShortBuffer(int numElements) { - int sz = numElements * BufferUtil.SIZEOF_SHORT; + public static synchronized ShortBuffer newShortBuffer(final int numElements) { + final int sz = numElements * Buffers.SIZEOF_SHORT; if (sz > CHUNK_SIZE) { // Just allocate a fresh ShortBuffer and don't worry about // rounding up its allocation size and re-using the end portion - return BufferUtil.newShortBuffer(numElements); + return Buffers.newDirectShortBuffer(numElements); } if (curShortBuf == null || curShortBuf.remaining() < numElements) { - curShortBuf = BufferUtil.newShortBuffer(CHUNK_SIZE / BufferUtil.SIZEOF_SHORT); + curShortBuf = Buffers.newDirectShortBuffer(CHUNK_SIZE / Buffers.SIZEOF_SHORT); } curShortBuf.limit(curShortBuf.position() + numElements); - ShortBuffer res = curShortBuf.slice(); + final ShortBuffer res = curShortBuf.slice(); curShortBuf.position(curShortBuf.limit()); return res; } - public static synchronized IntBuffer newIntBuffer(int numElements) { - int sz = numElements * BufferUtil.SIZEOF_INT; + public static synchronized IntBuffer newIntBuffer(final int numElements) { + final int sz = numElements * Buffers.SIZEOF_INT; if (sz > CHUNK_SIZE) { // Just allocate a fresh IntBuffer and don't worry about // rounding up its allocation size and re-using the end portion - return BufferUtil.newIntBuffer(numElements); + return Buffers.newDirectIntBuffer(numElements); } if (curIntBuf == null || curIntBuf.remaining() < numElements) { - curIntBuf = BufferUtil.newIntBuffer(CHUNK_SIZE / BufferUtil.SIZEOF_INT); + curIntBuf = Buffers.newDirectIntBuffer(CHUNK_SIZE / Buffers.SIZEOF_INT); } curIntBuf.limit(curIntBuf.position() + numElements); - IntBuffer res = curIntBuf.slice(); + final IntBuffer res = curIntBuf.slice(); curIntBuf.position(curIntBuf.limit()); return res; } - public static synchronized FloatBuffer newFloatBuffer(int numElements) { - int sz = numElements * BufferUtil.SIZEOF_FLOAT; + public static synchronized FloatBuffer newFloatBuffer(final int numElements) { + final int sz = numElements * Buffers.SIZEOF_FLOAT; if (sz > CHUNK_SIZE) { // Just allocate a fresh FloatBuffer and don't worry about // rounding up its allocation size and re-using the end portion - return BufferUtil.newFloatBuffer(numElements); + return Buffers.newDirectFloatBuffer(numElements); } if (curFloatBuf == null || curFloatBuf.remaining() < numElements) { - curFloatBuf = BufferUtil.newFloatBuffer(CHUNK_SIZE / BufferUtil.SIZEOF_FLOAT); + curFloatBuf = Buffers.newDirectFloatBuffer(CHUNK_SIZE / Buffers.SIZEOF_FLOAT); } curFloatBuf.limit(curFloatBuf.position() + numElements); - FloatBuffer res = curFloatBuf.slice(); + final FloatBuffer res = curFloatBuf.slice(); curFloatBuf.position(curFloatBuf.limit()); return res; } - public static synchronized DoubleBuffer newDoubleBuffer(int numElements) { - int sz = numElements * BufferUtil.SIZEOF_DOUBLE; + public static synchronized DoubleBuffer newDoubleBuffer(final int numElements) { + final int sz = numElements * Buffers.SIZEOF_DOUBLE; if (sz > CHUNK_SIZE) { // Just allocate a fresh DoubleBuffer and don't worry about // rounding up its allocation size and re-using the end portion - return BufferUtil.newDoubleBuffer(numElements); + return Buffers.newDirectDoubleBuffer(numElements); } if (curDoubleBuf == null || curDoubleBuf.remaining() < numElements) { - curDoubleBuf = BufferUtil.newDoubleBuffer(CHUNK_SIZE / BufferUtil.SIZEOF_DOUBLE); + curDoubleBuf = Buffers.newDirectDoubleBuffer(CHUNK_SIZE / Buffers.SIZEOF_DOUBLE); } curDoubleBuf.limit(curDoubleBuf.position() + numElements); - DoubleBuffer res = curDoubleBuf.slice(); + final DoubleBuffer res = curDoubleBuf.slice(); curDoubleBuf.position(curDoubleBuf.limit()); return res; } diff --git a/src/net/java/joglutils/msg/impl/RayTriangleIntersection.java b/src/net/java/joglutils/msg/impl/RayTriangleIntersection.java index 13d49e9..7af420c 100644 --- a/src/net/java/joglutils/msg/impl/RayTriangleIntersection.java +++ b/src/net/java/joglutils/msg/impl/RayTriangleIntersection.java @@ -37,7 +37,8 @@ package net.java.joglutils.msg.impl; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.math.Line; +import net.java.joglutils.msg.math.Vec3f; /** Intersection of ray with triangle. Computes parameteric t along with barycentric coordinates (u, v) indicating weight of vert1 and diff --git a/src/net/java/joglutils/msg/math/Mat4f.java b/src/net/java/joglutils/msg/math/Mat4f.java index bc7cee0..efaa417 100644 --- a/src/net/java/joglutils/msg/math/Mat4f.java +++ b/src/net/java/joglutils/msg/math/Mat4f.java @@ -37,7 +37,7 @@ package net.java.joglutils.msg.math; -import java.nio.*; +import java.nio.FloatBuffer; /** A (very incomplete) 4x4 matrix class. Representation assumes row-major order and multiplication by column vectors on the diff --git a/src/net/java/joglutils/msg/misc/ActionTable.java b/src/net/java/joglutils/msg/misc/ActionTable.java index d8b185b..5045eab 100644 --- a/src/net/java/joglutils/msg/misc/ActionTable.java +++ b/src/net/java/joglutils/msg/misc/ActionTable.java @@ -37,11 +37,13 @@ package net.java.joglutils.msg.misc; -import java.lang.reflect.*; -import java.util.*; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.Map; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.nodes.Node; /** Keeps track of methods which are attached to a particular Action type for a given set of Node types. This mechanism is different diff --git a/src/net/java/joglutils/msg/misc/Path.java b/src/net/java/joglutils/msg/misc/Path.java index 0743e86..811e3a4 100644 --- a/src/net/java/joglutils/msg/misc/Path.java +++ b/src/net/java/joglutils/msg/misc/Path.java @@ -37,9 +37,9 @@ package net.java.joglutils.msg.misc; -import java.util.*; +import java.util.ArrayList; -import net.java.joglutils.msg.nodes.*; +import net.java.joglutils.msg.nodes.Node; /** Represents a path through the scene graph. The topmost node is at index 0 and subsequent child nodes are at later indices. */ diff --git a/src/net/java/joglutils/msg/misc/PrimitiveVertex.java b/src/net/java/joglutils/msg/misc/PrimitiveVertex.java index 24b9e46..aab636b 100644 --- a/src/net/java/joglutils/msg/misc/PrimitiveVertex.java +++ b/src/net/java/joglutils/msg/misc/PrimitiveVertex.java @@ -37,7 +37,9 @@ package net.java.joglutils.msg.misc; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.math.Vec3f; +import net.java.joglutils.msg.math.Vec4f; /** Represents a vertex on a primitive, including pieces of relevant information such as location, surface normal and texture diff --git a/src/net/java/joglutils/msg/misc/Shader.java b/src/net/java/joglutils/msg/misc/Shader.java index cf32fc6..da0c9ac 100644 --- a/src/net/java/joglutils/msg/misc/Shader.java +++ b/src/net/java/joglutils/msg/misc/Shader.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - 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,7 +28,7 @@ * 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. @@ -36,9 +36,11 @@ package net.java.joglutils.msg.misc; -import javax.media.opengl.*; -import javax.media.opengl.glu.GLU; -import static javax.media.opengl.GL2.*; +import static com.jogamp.opengl.GL2.*; + +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.GLException; +import com.jogamp.opengl.glu.GLU; /** * Represents an OpenGL shader program object, which can be constructed from @@ -69,61 +71,61 @@ import static javax.media.opengl.GL2.*; * @author Chris Campbell */ public class Shader { - + /** * The handle to the OpenGL fragment program object. */ private int id; - + /** * Creates a new shader program object and compiles/links the provided * fragment shader code into that object. - * + * * @param fragmentCode a {@code String} representing the fragment shader * source code to be compiled and linked - * + * * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public Shader(String fragmentCode) + public Shader(final String fragmentCode) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); + final GL2 gl = GLU.getCurrentGL().getGL2(); id = createProgram(gl, null, fragmentCode); } - + /** * Creates a new shader program object and compiles/links the provided * vertex shader and fragment shader code into that object. - * + * * @param vertexCode a {@code String} representing the vertex shader * source code to be compiled and linked; this may be null if only a * fragment shader is going to be needed * @param fragmentCode a {@code String} representing the fragment shader * source code to be compiled and linked; this may be null if only a * vertex shader is going to be needed - * + * * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public Shader(String vertexCode, String fragmentCode) + public Shader(final String vertexCode, final String fragmentCode) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); + final GL2 gl = GLU.getCurrentGL().getGL2(); id = createProgram(gl, vertexCode, fragmentCode); } - + /** * Compiles and links a new shader program using the given sources. If * successful, this function returns a handle to the newly created shader * program; otherwise returns 0. - * + * * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - private static int createProgram(GL2 gl, - String vertexShaderSource, - String fragmentShaderSource) + private static int createProgram(final GL2 gl, + final String vertexShaderSource, + final String fragmentShaderSource) throws GLException { if (vertexShaderSource == null && fragmentShaderSource == null) { @@ -131,12 +133,12 @@ public class Shader { "Either vertexShaderSource or fragmentShaderSource " + "must be specified"); } - + int shaderProgram; int vertexShader = 0; int fragmentShader = 0; - int[] success = new int[1]; - int[] infoLogLength = new int[1]; + final int[] success = new int[1]; + final int[] infoLogLength = new int[1]; if (vertexShaderSource != null) { vertexShader = compileShader(gl, vertexShaderSource, true); @@ -144,7 +146,7 @@ public class Shader { return 0; } } - + if (fragmentShaderSource != null) { fragmentShader = compileShader(gl, fragmentShaderSource, false); if (fragmentShader == 0) { @@ -156,7 +158,7 @@ public class Shader { } // create the program object and attach it to the shader - shaderProgram = gl.glCreateProgramObjectARB(); + shaderProgram = (int) gl.glCreateProgramObjectARB(); // FIXME int-cast old ARM if (vertexShader != 0) { gl.glAttachObjectARB(shaderProgram, vertexShader); // it is now safe to delete the shader object @@ -179,7 +181,7 @@ public class Shader { GL_OBJECT_INFO_LOG_LENGTH_ARB, infoLogLength, 0); if (infoLogLength[0] > 1) { - byte[] infoLog = new byte[1024]; + final byte[] infoLog = new byte[1024]; gl.glGetInfoLogARB(shaderProgram, 1024, null, 0, infoLog, 0); System.err.println("Linker message: " + new String(infoLog)); @@ -192,24 +194,24 @@ public class Shader { return shaderProgram; } - + /** * Compiles the given shader program. If successful, this function returns * a handle to the newly created shader object; otherwise returns 0. - * + * * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - private static int compileShader(GL2 gl, String shaderSource, boolean vertex) + private static int compileShader(final GL2 gl, final String shaderSource, final boolean vertex) throws GLException { - int kind = vertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER; + final int kind = vertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER; int shader; - int[] success = new int[1]; - int[] infoLogLength = new int[1]; - + final int[] success = new int[1]; + final int[] infoLogLength = new int[1]; + // create the shader object and compile the shader source code - shader = gl.glCreateShaderObjectARB(kind); + shader = (int) gl.glCreateShaderObjectARB(kind); // FIXME int-cast old ARM gl.glShaderSourceARB(shader, 1, new String[] { shaderSource }, null, 0); gl.glCompileShaderARB(shader); gl.glGetObjectParameterivARB(shader, @@ -221,7 +223,7 @@ public class Shader { GL_OBJECT_INFO_LOG_LENGTH_ARB, infoLogLength, 0); if (infoLogLength[0] > 1) { - byte[] infoLog = new byte[1024]; + final byte[] infoLog = new byte[1024]; gl.glGetInfoLogARB(shader, 1024, null, 0, infoLog, 0); System.err.println((vertex ? "Vertex" : "Fragment") + " compile message: " + @@ -232,43 +234,43 @@ public class Shader { gl.glDeleteObjectARB(shader); return 0; } - + return shader; } - + /** * Returns the underlying OpenGL program object handle for this fragment * shader. Most applications will not need to access this, since it is * handled automatically by the enable() and dispose() methods. - * + * * @return the OpenGL program object handle for this fragment shader */ public int getProgramObject() { return id; } - + /** * Enables this shader program in the current GL context's state. - * + * * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ public void enable() throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); + final GL2 gl = GLU.getCurrentGL().getGL2(); gl.glUseProgramObjectARB(id); } - + /** * Disables this shader program in the current GL context's state. - * + * * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ public void disable() throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); + final GL2 gl = GLU.getCurrentGL().getGL2(); gl.glUseProgramObjectARB(0); } - + /** * Disposes the native resources used by this program object. * @@ -276,7 +278,7 @@ public class Shader { * OpenGL-related errors occurred */ public void dispose() throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); + final GL2 gl = GLU.getCurrentGL().getGL2(); gl.glDeleteObjectARB(id); id = 0; } @@ -290,14 +292,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, int i0) + public void setUniform(final String name, final int i0) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform1iARB(loc, i0); } - + /** * Sets the uniform variable of the given name with the provided * integer values. @@ -308,14 +310,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, int i0, int i1) + public void setUniform(final String name, final int i0, final int i1) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform2iARB(loc, i0, i1); } - + /** * Sets the uniform variable of the given name with the provided * integer values. @@ -327,14 +329,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, int i0, int i1, int i2) + public void setUniform(final String name, final int i0, final int i1, final int i2) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform3iARB(loc, i0, i1, i2); } - + /** * Sets the uniform variable of the given name with the provided * integer values. @@ -347,14 +349,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, int i0, int i1, int i2, int i3) + public void setUniform(final String name, final int i0, final int i1, final int i2, final int i3) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform4iARB(loc, i0, i1, i2, i3); } - + /** * Sets the uniform variable of the given name with the provided * float value. @@ -364,14 +366,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, float f0) + public void setUniform(final String name, final float f0) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform1fARB(loc, f0); } - + /** * Sets the uniform variable of the given name with the provided * float values. @@ -382,14 +384,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, float f0, float f1) + public void setUniform(final String name, final float f0, final float f1) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform2fARB(loc, f0, f1); } - + /** * Sets the uniform variable of the given name with the provided * float values. @@ -401,14 +403,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, float f0, float f1, float f2) + public void setUniform(final String name, final float f0, final float f1, final float f2) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform3fARB(loc, f0, f1, f2); } - + /** * Sets the uniform variable of the given name with the provided * float values. @@ -421,14 +423,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniform(String name, float f0, float f1, float f2, float f3) + public void setUniform(final String name, final float f0, final float f1, final float f2, final float f3) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform4fARB(loc, f0, f1, f2, f3); } - + /** * Sets the uniform array variable of the given name with the provided * int array values. @@ -440,14 +442,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray1i(String name, int count, int[] vals, int off) + public void setUniformArray1i(final String name, final int count, final int[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform1ivARB(loc, count, vals, off); } - + /** * Sets the uniform array variable of the given name with the provided * int array values. @@ -459,14 +461,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray2i(String name, int count, int[] vals, int off) + public void setUniformArray2i(final String name, final int count, final int[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform2ivARB(loc, count, vals, off); } - + /** * Sets the uniform array variable of the given name with the provided * int array values. @@ -478,14 +480,14 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray3i(String name, int count, int[] vals, int off) + public void setUniformArray3i(final String name, final int count, final int[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform3ivARB(loc, count, vals, off); } - + /** * Sets the uniform array variable of the given name with the provided * int array values. @@ -497,11 +499,11 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray4i(String name, int count, int[] vals, int off) + public void setUniformArray4i(final String name, final int count, final int[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform4ivARB(loc, count, vals, off); } @@ -516,15 +518,15 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray1f(String name, - int count, float[] vals, int off) + public void setUniformArray1f(final String name, + final int count, final float[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform1fvARB(loc, count, vals, off); } - + /** * Sets the uniform array variable of the given name with the provided * float array values. @@ -536,15 +538,15 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray2f(String name, - int count, float[] vals, int off) + public void setUniformArray2f(final String name, + final int count, final float[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform2fvARB(loc, count, vals, off); } - + /** * Sets the uniform array variable of the given name with the provided * float array values. @@ -556,15 +558,15 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray3f(String name, - int count, float[] vals, int off) + public void setUniformArray3f(final String name, + final int count, final float[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform3fvARB(loc, count, vals, off); } - + /** * Sets the uniform array variable of the given name with the provided * float array values. @@ -576,12 +578,12 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformArray4f(String name, - int count, float[] vals, int off) + public void setUniformArray4f(final String name, + final int count, final float[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform4fvARB(loc, count, vals, off); } @@ -598,13 +600,13 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformMatrices2f(String name, - int count, boolean transpose, - float[] vals, int off) + public void setUniformMatrices2f(final String name, + final int count, final boolean transpose, + final float[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniformMatrix2fvARB(loc, count, transpose, vals, off); } @@ -621,13 +623,13 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformMatrices3f(String name, - int count, boolean transpose, - float[] vals, int off) + public void setUniformMatrices3f(final String name, + final int count, final boolean transpose, + final float[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniformMatrix3fvARB(loc, count, transpose, vals, off); } @@ -644,13 +646,13 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setUniformMatrices4f(String name, - int count, boolean transpose, - float[] vals, int off) + public void setUniformMatrices4f(final String name, + final int count, final boolean transpose, + final float[] vals, final int off) throws GLException { - GL2 gl = GLU.getCurrentGL().getGL2(); - int loc = gl.glGetUniformLocationARB(id, name); + final GL2 gl = GLU.getCurrentGL().getGL2(); + final int loc = gl.glGetUniformLocationARB(id, name); gl.glUniformMatrix4fvARB(loc, count, transpose, vals, off); } } diff --git a/src/net/java/joglutils/msg/misc/State.java b/src/net/java/joglutils/msg/misc/State.java index b0279b7..948c99a 100644 --- a/src/net/java/joglutils/msg/misc/State.java +++ b/src/net/java/joglutils/msg/misc/State.java @@ -37,9 +37,10 @@ package net.java.joglutils.msg.misc; -import java.util.*; +import java.util.ArrayList; +import java.util.List; -import net.java.joglutils.msg.elements.*; +import net.java.joglutils.msg.elements.Element; /** Represents a collection of state elements, which are updated by actions during scene graph traversal. */ diff --git a/src/net/java/joglutils/msg/nodes/Blend.java b/src/net/java/joglutils/msg/nodes/Blend.java index af95e00..2a8383e 100644 --- a/src/net/java/joglutils/msg/nodes/Blend.java +++ b/src/net/java/joglutils/msg/nodes/Blend.java @@ -37,9 +37,11 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.elements.BlendElement; +import net.java.joglutils.msg.elements.GLBlendElement; +import net.java.joglutils.msg.math.Vec4f; /** Provides control over OpenGL blending modes. */ diff --git a/src/net/java/joglutils/msg/nodes/Camera.java b/src/net/java/joglutils/msg/nodes/Camera.java index 250d3d1..42f70c4 100644 --- a/src/net/java/joglutils/msg/nodes/Camera.java +++ b/src/net/java/joglutils/msg/nodes/Camera.java @@ -37,9 +37,22 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.RayPickAction; +import net.java.joglutils.msg.elements.GLModelMatrixElement; +import net.java.joglutils.msg.elements.GLProjectionMatrixElement; +import net.java.joglutils.msg.elements.GLViewingMatrixElement; +import net.java.joglutils.msg.elements.ModelMatrixElement; +import net.java.joglutils.msg.elements.ProjectionMatrixElement; +import net.java.joglutils.msg.elements.ViewingMatrixElement; +import net.java.joglutils.msg.math.Line; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.math.Rotf; +import net.java.joglutils.msg.math.SingularMatrixException; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.math.Vec3f; +import net.java.joglutils.msg.math.Vec4f; /** Represents a camera which is used to view the scene. The camera should be added to the scene graph before the geometry it is diff --git a/src/net/java/joglutils/msg/nodes/Color4.java b/src/net/java/joglutils/msg/nodes/Color4.java index 8d6696f..7659926 100644 --- a/src/net/java/joglutils/msg/nodes/Color4.java +++ b/src/net/java/joglutils/msg/nodes/Color4.java @@ -37,9 +37,11 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.collections.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.collections.Vec4fCollection; +import net.java.joglutils.msg.elements.ColorElement; +import net.java.joglutils.msg.elements.GLColorElement; /** Represents a set of 4-valued colors which are applied on a per-vertex basis to any drawn polygons. Currently the color can diff --git a/src/net/java/joglutils/msg/nodes/Coordinate3.java b/src/net/java/joglutils/msg/nodes/Coordinate3.java index 7cae14b..2d36636 100644 --- a/src/net/java/joglutils/msg/nodes/Coordinate3.java +++ b/src/net/java/joglutils/msg/nodes/Coordinate3.java @@ -37,9 +37,12 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.collections.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.RayPickAction; +import net.java.joglutils.msg.collections.Vec3fCollection; +import net.java.joglutils.msg.elements.CoordinateElement; +import net.java.joglutils.msg.elements.GLCoordinateElement; /** Represents a set of 3-dimensional vertices which can be assembled into shapes. */ diff --git a/src/net/java/joglutils/msg/nodes/DepthTest.java b/src/net/java/joglutils/msg/nodes/DepthTest.java index 7d3963f..cdd420b 100644 --- a/src/net/java/joglutils/msg/nodes/DepthTest.java +++ b/src/net/java/joglutils/msg/nodes/DepthTest.java @@ -36,10 +36,10 @@ package net.java.joglutils.msg.nodes; -import javax.media.opengl.*; - -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.elements.DepthTestElement; +import net.java.joglutils.msg.elements.GLDepthTestElement; /** Represents depth test state. */ public class DepthTest extends Node { diff --git a/src/net/java/joglutils/msg/nodes/Group.java b/src/net/java/joglutils/msg/nodes/Group.java index 05486ab..61522ed 100644 --- a/src/net/java/joglutils/msg/nodes/Group.java +++ b/src/net/java/joglutils/msg/nodes/Group.java @@ -37,9 +37,11 @@ package net.java.joglutils.msg.nodes; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; -import net.java.joglutils.msg.actions.*; +import net.java.joglutils.msg.actions.Action; /** A node which manages other Node instances. */ diff --git a/src/net/java/joglutils/msg/nodes/IndexedTriangleSet.java b/src/net/java/joglutils/msg/nodes/IndexedTriangleSet.java index e244f17..3a79f6a 100644 --- a/src/net/java/joglutils/msg/nodes/IndexedTriangleSet.java +++ b/src/net/java/joglutils/msg/nodes/IndexedTriangleSet.java @@ -37,10 +37,10 @@ package net.java.joglutils.msg.nodes; -import java.nio.*; +import java.nio.IntBuffer; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.misc.TriangleCallback; /** An IndexedTriangleSet assembles the coordinates specified by a Coordinate3 node, and any auxiliary nodes such as a diff --git a/src/net/java/joglutils/msg/nodes/Node.java b/src/net/java/joglutils/msg/nodes/Node.java index f2ab658..8761735 100644 --- a/src/net/java/joglutils/msg/nodes/Node.java +++ b/src/net/java/joglutils/msg/nodes/Node.java @@ -37,7 +37,9 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.RayPickAction; /** The base class for all nodes in the scene graph. */ diff --git a/src/net/java/joglutils/msg/nodes/OrthographicCamera.java b/src/net/java/joglutils/msg/nodes/OrthographicCamera.java index 28c657a..4eb09d7 100644 --- a/src/net/java/joglutils/msg/nodes/OrthographicCamera.java +++ b/src/net/java/joglutils/msg/nodes/OrthographicCamera.java @@ -37,8 +37,10 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.math.Vec3f; public class OrthographicCamera extends Camera { private static final float DEFAULT_HEIGHT = 2.0f; diff --git a/src/net/java/joglutils/msg/nodes/PerspectiveCamera.java b/src/net/java/joglutils/msg/nodes/PerspectiveCamera.java index d2eb082..bb634aa 100644 --- a/src/net/java/joglutils/msg/nodes/PerspectiveCamera.java +++ b/src/net/java/joglutils/msg/nodes/PerspectiveCamera.java @@ -37,8 +37,10 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.math.Vec3f; /** Represents a camera utilizing a perspective projection. <P> diff --git a/src/net/java/joglutils/msg/nodes/Separator.java b/src/net/java/joglutils/msg/nodes/Separator.java index fdebece..49c6f12 100644 --- a/src/net/java/joglutils/msg/nodes/Separator.java +++ b/src/net/java/joglutils/msg/nodes/Separator.java @@ -37,8 +37,8 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.misc.State; /** Represents a push / pop of OpenGL state, "separating" the sub-graph below this separator from the nodes which follow it in diff --git a/src/net/java/joglutils/msg/nodes/ShaderNode.java b/src/net/java/joglutils/msg/nodes/ShaderNode.java index c066079..fd9771d 100644 --- a/src/net/java/joglutils/msg/nodes/ShaderNode.java +++ b/src/net/java/joglutils/msg/nodes/ShaderNode.java @@ -36,17 +36,19 @@ package net.java.joglutils.msg.nodes; -import java.awt.image.*; -import java.io.*; -import java.net.*; -import java.util.*; - -import javax.media.opengl.*; - -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.jogamp.opengl.GLException; + +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.GLResetAction; +import net.java.joglutils.msg.elements.GLShaderElement; +import net.java.joglutils.msg.elements.ShaderElement; +import net.java.joglutils.msg.misc.Shader; /** Represents a vertex/fragment shader. */ public class ShaderNode extends Node { diff --git a/src/net/java/joglutils/msg/nodes/Texture2.java b/src/net/java/joglutils/msg/nodes/Texture2.java index 9c4cb60..1d171c9 100644 --- a/src/net/java/joglutils/msg/nodes/Texture2.java +++ b/src/net/java/joglutils/msg/nodes/Texture2.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - 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,27 +28,38 @@ * 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. - * + * */ package net.java.joglutils.msg.nodes; -import java.awt.image.*; -import java.io.*; -import java.net.*; -import java.util.*; - -import javax.media.opengl.*; -import com.sun.opengl.util.awt.*; -import com.sun.opengl.util.texture.*; -import com.sun.opengl.util.texture.awt.*; - -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GLException; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.util.awt.TextureRenderer; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.TextureIO; +import com.jogamp.opengl.util.texture.awt.AWTTextureIO; + +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.GLResetAction; +import net.java.joglutils.msg.actions.RayPickAction; +import net.java.joglutils.msg.elements.GLTextureElement; +import net.java.joglutils.msg.elements.TextureElement; /** Represents a two-dimensional texture which can be set up from all of the image sources supported by the JOGL TextureIO classes or @@ -77,8 +88,8 @@ public class Texture2 extends Node { // Disposed Textures and TextureRenderers, used to allow app to be // oblivious and switch back and forth between them - private List<Texture> disposedTextures = new ArrayList<Texture>(); - private List<TextureRenderer> disposedRenderers = new ArrayList<TextureRenderer>(); + private final List<Texture> disposedTextures = new ArrayList<Texture>(); + private final List<TextureRenderer> disposedRenderers = new ArrayList<TextureRenderer>(); static { // Enable the elements this node affects for known actions @@ -99,43 +110,43 @@ public class Texture2 extends Node { /** Initializes this texture from the given file. No OpenGL work is done during this call; it is done lazily when the Texture is fetched. */ - public void setTexture(File file, boolean mipmap, String fileSuffix) throws IOException { + public void setTexture(final GLProfile glp, final File file, final boolean mipmap, final String fileSuffix) throws IOException { disposeTextureRenderer(); - data = TextureIO.newTextureData(file, mipmap, fileSuffix); + data = TextureIO.newTextureData(glp, file, mipmap, fileSuffix); dirty = true; } /** Initializes this texture from the given InputStream. No OpenGL work is done during this call; it is done lazily when the Texture is fetched. */ - public void setTexture(InputStream stream, boolean mipmap, String fileSuffix) throws IOException { + public void setTexture(final GLProfile glp, final InputStream stream, final boolean mipmap, final String fileSuffix) throws IOException { disposeTextureRenderer(); - data = TextureIO.newTextureData(stream, mipmap, fileSuffix); + data = TextureIO.newTextureData(glp, stream, mipmap, fileSuffix); dirty = true; } /** Initializes this texture from the given URL. No OpenGL work is done during this call; it is done lazily when the Texture is fetched. */ - public void setTexture(URL url, boolean mipmap, String fileSuffix) throws IOException { + public void setTexture(final GLProfile glp, final URL url, final boolean mipmap, final String fileSuffix) throws IOException { disposeTextureRenderer(); - data = TextureIO.newTextureData(url, mipmap, fileSuffix); + data = TextureIO.newTextureData(glp, url, mipmap, fileSuffix); dirty = true; } /** Initializes this texture from the given BufferedImage. No OpenGL work is done during this call; it is done lazily when the Texture is fetched. */ - public void setTexture(BufferedImage image, boolean mipmap) { + public void setTexture(final GLProfile glp, final BufferedImage image, final boolean mipmap) { disposeTextureRenderer(); - data = AWTTextureIO.newTextureData(image, mipmap); + data = AWTTextureIO.newTextureData(glp, image, mipmap); dirty = true; } - + /** Initializes this texture from the given TextureData. No OpenGL work is done during this call; it is done lazily when the Texture is fetched. */ - public void setTexture(TextureData data) { + public void setTexture(final TextureData data) { disposeTextureRenderer(); this.data = data; dirty = true; @@ -202,10 +213,10 @@ public class Texture2 extends Node { * @param width the width (in pixels) of the rectangle to be updated * @param height the height (in pixels) of the rectangle to be updated */ - public void updateSubImage(TextureData data, int mipmapLevel, - int dstx, int dsty, - int srcx, int srcy, - int width, int height) { + public void updateSubImage(final TextureData data, final int mipmapLevel, + final int dstx, final int dsty, + final int srcx, final int srcy, + final int width, final int height) { if (textureRenderer != null) { throw new IllegalStateException("May not call updateSubImage if a TextureRenderer has been set"); } @@ -225,7 +236,7 @@ public class Texture2 extends Node { Updates to the TextureRenderer are automatically propagated to the texture as long as <CODE>TextureRenderer.markDirty()</CODE> is used properly. */ - public void initTextureRenderer(int width, int height, boolean alpha) { + public void initTextureRenderer(final int width, final int height, final boolean alpha) { disposeTexture(); textureRenderer = new TextureRenderer(width, height, alpha); } @@ -241,8 +252,8 @@ public class Texture2 extends Node { each frame during rendering. An OpenGL context must be current at the time this method is called or a GLException will be thrown. */ - public Texture getTexture() throws GLException { - lazyDispose(); + public Texture getTexture(final GL gl) throws GLException { + lazyDispose(gl); if (textureRenderer != null) { return textureRenderer.getTexture(); @@ -250,7 +261,7 @@ public class Texture2 extends Node { if (dirty) { if (texture != null) { - texture.dispose(); + texture.destroy(gl); texture = null; } texture = TextureIO.newTexture(data); @@ -258,7 +269,7 @@ public class Texture2 extends Node { dirty = false; } if (subImageDirty) { - texture.updateSubImage(subImageData, + texture.updateSubImage(gl, subImageData, subImageMipmapLevel, subImageDstX, subImageDstY, @@ -272,7 +283,7 @@ public class Texture2 extends Node { } /** Sets the texture environment mode. Default is MODULATE. */ - public void setTexEnvMode(int mode) { + public void setTexEnvMode(final int mode) { if (mode < MODULATE || mode > REPLACE) { throw new IllegalArgumentException("Illegal texture environment mode"); } @@ -285,7 +296,7 @@ public class Texture2 extends Node { return texEnvMode; } - public void doAction(Action action) { + public void doAction(final Action action) { if (TextureElement.isEnabled(action.getState())) { TextureElement.set(action.getState(), this); } @@ -294,10 +305,10 @@ public class Texture2 extends Node { /** Disposes of the OpenGL texture and/or TextureRenderer this Texture2 node refers to. An OpenGL context must be current at the point this method is called. */ - public void dispose() throws GLException { + public void dispose(final GL gl) throws GLException { disposeTexture(); disposeTextureRenderer(); - lazyDispose(); + lazyDispose(gl); data = null; subImageData = null; dirty = false; @@ -309,7 +320,7 @@ public class Texture2 extends Node { know you are using this Texture2 node across the destruction and re-creation of OpenGL contexts and know how to re-initialize the Texture2 from its previous state. */ - public void resetGL(GLResetAction action) { + public void resetGL(final GLResetAction action) { disposeTexture(); disposeTextureRenderer(); synchronized(this) { @@ -340,13 +351,13 @@ public class Texture2 extends Node { } } - private void lazyDispose() { + private void lazyDispose(final GL gl) { while (!disposedTextures.isEmpty()) { Texture t = null; synchronized (this) { t = disposedTextures.remove(disposedTextures.size() - 1); } - t.dispose(); + t.destroy(gl); } while (!disposedRenderers.isEmpty()) { diff --git a/src/net/java/joglutils/msg/nodes/TextureCoordinate2.java b/src/net/java/joglutils/msg/nodes/TextureCoordinate2.java index 2782da1..bf8a952 100644 --- a/src/net/java/joglutils/msg/nodes/TextureCoordinate2.java +++ b/src/net/java/joglutils/msg/nodes/TextureCoordinate2.java @@ -37,9 +37,12 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.collections.*; -import net.java.joglutils.msg.elements.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.RayPickAction; +import net.java.joglutils.msg.collections.Vec2fCollection; +import net.java.joglutils.msg.elements.GLTextureCoordinateElement; +import net.java.joglutils.msg.elements.TextureCoordinateElement; /** Represents a set of 2-dimensional texture coordinates which can be used to texture geometric shapes. */ diff --git a/src/net/java/joglutils/msg/nodes/Transform.java b/src/net/java/joglutils/msg/nodes/Transform.java index 044c1b7..f48ff67 100644 --- a/src/net/java/joglutils/msg/nodes/Transform.java +++ b/src/net/java/joglutils/msg/nodes/Transform.java @@ -37,9 +37,16 @@ package net.java.joglutils.msg.nodes; -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.RayPickAction; +import net.java.joglutils.msg.elements.GLModelMatrixElement; +import net.java.joglutils.msg.elements.GLProjectionMatrixElement; +import net.java.joglutils.msg.elements.GLViewingMatrixElement; +import net.java.joglutils.msg.elements.ModelMatrixElement; +import net.java.joglutils.msg.elements.ProjectionMatrixElement; +import net.java.joglutils.msg.elements.ViewingMatrixElement; +import net.java.joglutils.msg.math.Mat4f; /** Represents a generalized 4x4 matrix transformation. */ diff --git a/src/net/java/joglutils/msg/nodes/TriangleBasedShape.java b/src/net/java/joglutils/msg/nodes/TriangleBasedShape.java index c234695..47457cb 100644 --- a/src/net/java/joglutils/msg/nodes/TriangleBasedShape.java +++ b/src/net/java/joglutils/msg/nodes/TriangleBasedShape.java @@ -37,13 +37,16 @@ package net.java.joglutils.msg.nodes; -import java.util.*; - -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.impl.*; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.RayPickAction; +import net.java.joglutils.msg.elements.ModelMatrixElement; +import net.java.joglutils.msg.impl.RayTriangleIntersection; +import net.java.joglutils.msg.math.Line; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.math.Vec3f; +import net.java.joglutils.msg.misc.PickedPoint; +import net.java.joglutils.msg.misc.PrimitiveVertex; +import net.java.joglutils.msg.misc.TriangleCallback; /** The abstract base class for all shapes in the scene graph which render themselves as a collection of triangles. */ diff --git a/src/net/java/joglutils/msg/nodes/TriangleSet.java b/src/net/java/joglutils/msg/nodes/TriangleSet.java index 4659a19..0dcad68 100644 --- a/src/net/java/joglutils/msg/nodes/TriangleSet.java +++ b/src/net/java/joglutils/msg/nodes/TriangleSet.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - 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,25 +28,39 @@ * 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. - * + * */ package net.java.joglutils.msg.nodes; -import java.nio.*; -import java.util.*; - -import javax.media.opengl.*; -import com.sun.opengl.util.texture.*; - -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.elements.*; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; +import java.nio.FloatBuffer; + +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.fixedfunc.GLMatrixFunc; +import com.jogamp.opengl.fixedfunc.GLPointerFunc; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureCoords; + +import net.java.joglutils.msg.actions.Action; +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.elements.ColorElement; +import net.java.joglutils.msg.elements.CoordinateElement; +import net.java.joglutils.msg.elements.GLTextureCoordinateElement; +import net.java.joglutils.msg.elements.GLTextureElement; +import net.java.joglutils.msg.elements.TextureCoordinateElement; +import net.java.joglutils.msg.elements.TextureElement; +import net.java.joglutils.msg.math.Mat4f; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.math.Vec3f; +import net.java.joglutils.msg.math.Vec4f; +import net.java.joglutils.msg.misc.PrimitiveVertex; +import net.java.joglutils.msg.misc.State; +import net.java.joglutils.msg.misc.TriangleCallback; /** A TriangleSet assembles the coordinates specified by a Coordinate3 node, and any auxiliary nodes such as a TextureCoordinate2 node, @@ -56,7 +70,7 @@ public class TriangleSet extends TriangleBasedShape { private int numTriangles; /** Sets the number of triangles this TriangleSet references. */ - public void setNumTriangles(int numTriangles) { + public void setNumTriangles(final int numTriangles) { this.numTriangles = numTriangles; } @@ -65,65 +79,65 @@ public class TriangleSet extends TriangleBasedShape { return numTriangles; } - public void render(GLRenderAction action) { - State state = action.getState(); + public void render(final GLRenderAction action) { + final State state = action.getState(); if (!CoordinateElement.isEnabled(state)) return; if (CoordinateElement.get(state) != null) { // OK, we have coordinates to send down, at least - GL2 gl = action.getGL(); + final GL2 gl = action.getGL(); Texture tex = null; boolean haveTexCoords = false; - if (GLTextureElement.isEnabled(state) && - GLTextureCoordinateElement.isEnabled(state)) { - Texture2 texNode = GLTextureElement.get(state); + if (TextureElement.isEnabled(state) && + TextureCoordinateElement.isEnabled(state)) { + final Texture2 texNode = TextureElement.get(state); if (texNode != null) { - tex = texNode.getTexture(); + tex = texNode.getTexture(gl); } - haveTexCoords = (GLTextureCoordinateElement.get(state) != null); + haveTexCoords = (TextureCoordinateElement.get(state) != null); } if (tex != null) { // Set up the texture matrix to uniformly map [0..1] to the used // portion of the texture image - gl.glMatrixMode(GL2.GL_TEXTURE); + gl.glMatrixMode(GL.GL_TEXTURE); gl.glPushMatrix(); if (gl.isExtensionAvailable("GL_VERSION_1_3")) { gl.glLoadTransposeMatrixf(getTextureMatrix(tex).getRowMajorData(), 0); } else { - float[] tmp = new float[16]; + final float[] tmp = new float[16]; getTextureMatrix(tex).getColumnMajorData(tmp); gl.glLoadMatrixf(tmp, 0); } - gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); } else if (haveTexCoords) { // Want to turn off the use of texture coordinates to avoid errors // FIXME: not 100% sure whether we need to do this, but think we should - gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); + gl.glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY); } // For now, assume the triangle set and the number of available // coordinates match -- may want to add debugging information // for this later - gl.glDrawArrays(GL2.GL_TRIANGLES, 0, 3 * getNumTriangles()); + gl.glDrawArrays(GL.GL_TRIANGLES, 0, 3 * getNumTriangles()); if (tex != null) { - gl.glMatrixMode(GL2.GL_TEXTURE); + gl.glMatrixMode(GL.GL_TEXTURE); gl.glPopMatrix(); - gl.glMatrixMode(GL2.GL_MODELVIEW); + gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); } else if (haveTexCoords) { // Might want this the next time we render a shape - gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); + gl.glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY); } } } - public void generateTriangles(Action action, TriangleCallback cb) { - State state = action.getState(); + public void generateTriangles(final Action action, final TriangleCallback cb) { + final State state = action.getState(); FloatBuffer coords = null; FloatBuffer texCoords = null; // FIXME: normals and lighting not supported yet @@ -144,9 +158,9 @@ public class TriangleSet extends TriangleBasedShape { if (ColorElement.isEnabled(state)) { colors = ColorElement.get(state); } - PrimitiveVertex v0 = new PrimitiveVertex(); - PrimitiveVertex v1 = new PrimitiveVertex(); - PrimitiveVertex v2 = new PrimitiveVertex(); + final PrimitiveVertex v0 = new PrimitiveVertex(); + final PrimitiveVertex v1 = new PrimitiveVertex(); + final PrimitiveVertex v2 = new PrimitiveVertex(); v0.setCoord(new Vec3f()); v1.setCoord(new Vec3f()); v2.setCoord(new Vec3f()); @@ -220,14 +234,14 @@ public class TriangleSet extends TriangleBasedShape { // Helper routine for setting up a texture matrix to allow texture // coords in the scene graph to always be specified from (0..1) - private Mat4f textureMatrix = new Mat4f(); - private Mat4f getTextureMatrix(Texture texture) { + private final Mat4f textureMatrix = new Mat4f(); + private Mat4f getTextureMatrix(final Texture texture) { textureMatrix.makeIdent(); - TextureCoords coords = texture.getImageTexCoords(); + final TextureCoords coords = texture.getImageTexCoords(); // Horizontal scale textureMatrix.set(0, 0, coords.right() - coords.left()); // Vertical scale (may be negative if texture needs to be flipped vertically) - float vertScale = coords.top() - coords.bottom(); + final float vertScale = coords.top() - coords.bottom(); textureMatrix.set(1, 1, vertScale); textureMatrix.set(0, 3, coords.left()); textureMatrix.set(1, 3, coords.bottom()); diff --git a/src/net/java/joglutils/msg/test/BasicFetcher.java b/src/net/java/joglutils/msg/test/BasicFetcher.java index 277e7fb..fb6f02b 100644 --- a/src/net/java/joglutils/msg/test/BasicFetcher.java +++ b/src/net/java/joglutils/msg/test/BasicFetcher.java @@ -31,12 +31,22 @@ package net.java.joglutils.msg.test; import java.awt.EventQueue; -import java.awt.image.*; -import java.io.*; -import java.net.*; -import java.util.*; -import java.util.concurrent.*; -import javax.imageio.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.FutureTask; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +import javax.imageio.ImageIO; /** * Basic implementation of Fetcher using ImageIO and a single-threaded diff --git a/src/net/java/joglutils/msg/test/DisplayShelf.java b/src/net/java/joglutils/msg/test/DisplayShelf.java index 1e3bab7..72ca8c8 100644 --- a/src/net/java/joglutils/msg/test/DisplayShelf.java +++ b/src/net/java/joglutils/msg/test/DisplayShelf.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - 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. - * + * */ package net.java.joglutils.msg.test; @@ -42,13 +42,15 @@ import java.awt.DisplayMode; import java.awt.Frame; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; -import java.awt.event.*; -import java.net.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.net.URL; -import javax.swing.*; +import javax.swing.DefaultListModel; -import javax.media.opengl.*; -import javax.media.opengl.awt.*; +import com.jogamp.opengl.GLCapabilities; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.awt.GLCanvas; /** * A test implementing a 3D display shelf component. @@ -57,11 +59,11 @@ import javax.media.opengl.awt.*; */ public class DisplayShelf { - public static void main(String[] args) { - Frame f = new Frame("Display Shelf test"); + public static void main(final String[] args) { + final Frame f = new Frame("Display Shelf test"); f.setLayout(new BorderLayout()); f.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { + public void windowClosing(final WindowEvent e) { new Thread(new Runnable() { public void run() { System.exit(0); @@ -71,7 +73,7 @@ public class DisplayShelf { }); // The images to configure the shelf with - String[] images = { + final String[] images = { "http://download.java.net/media/jogl/builds/ds_tmp/mzi.jsepedzf.200x200-75.jpg", "http://download.java.net/media/jogl/builds/ds_tmp/dj.wvbmknhn.200x200-75.jpg", "http://download.java.net/media/jogl/builds/ds_tmp/mzi.oorrjicu.200x200-75.jpg", @@ -125,23 +127,23 @@ public class DisplayShelf { "http://download.java.net/media/jogl/builds/ds_tmp/dj.zfqfgoas.200x200-75.jpg", "http://download.java.net/media/jogl/builds/ds_tmp/mzi.uswlslxx.200x200-75.jpg" }; - DefaultListModel model = new DefaultListModel(); - for (String str : images) { + final DefaultListModel model = new DefaultListModel(); + for (final String str : images) { try { model.addElement(new URL(str)); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } - DisplayShelfRenderer renderer = new DisplayShelfRenderer(model); - GLCanvas canvas = new GLCanvas(new GLCapabilities(GLProfile.getDefault()), null, renderer.getSharedContext(), null); + final DisplayShelfRenderer renderer = new DisplayShelfRenderer(model); + final GLCanvas canvas = new GLCanvas(new GLCapabilities(GLProfile.getDefault()), null, null); canvas.setFocusable(true); canvas.addGLEventListener(renderer); f.add(canvas); - GraphicsDevice dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); - DisplayMode curMode = dev.getDisplayMode(); - int height = (int) (0.5f * curMode.getWidth()); + final GraphicsDevice dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + final DisplayMode curMode = dev.getDisplayMode(); + final int height = (int) (0.5f * curMode.getWidth()); f.setSize(curMode.getWidth(), height); f.setLocation(0, (curMode.getHeight() - height) / 2); f.setVisible(true); diff --git a/src/net/java/joglutils/msg/test/DisplayShelfRenderer.java b/src/net/java/joglutils/msg/test/DisplayShelfRenderer.java index 5cdffc1..b868a83 100644 --- a/src/net/java/joglutils/msg/test/DisplayShelfRenderer.java +++ b/src/net/java/joglutils/msg/test/DisplayShelfRenderer.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - 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. - * + * */ package net.java.joglutils.msg.test; @@ -40,23 +40,48 @@ package net.java.joglutils.msg.test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; -import java.awt.event.*; -import java.awt.image.*; -import java.net.*; -import java.util.*; - -import javax.swing.*; -import javax.swing.event.*; - -import javax.media.opengl.*; -import javax.media.opengl.awt.*; -import com.sun.opengl.util.awt.*; - -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.collections.*; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.misc.*; -import net.java.joglutils.msg.nodes.*; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.ListModel; + +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GLAutoDrawable; +import com.jogamp.opengl.GLCapabilities; +import com.jogamp.opengl.GLContext; +import com.jogamp.opengl.GLDrawableFactory; +import com.jogamp.opengl.GLEventListener; +import com.jogamp.opengl.GLOffscreenAutoDrawable; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.awt.AWTGLAutoDrawable; +import com.jogamp.opengl.util.awt.TextureRenderer; + +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.actions.RayPickAction; +import net.java.joglutils.msg.collections.Vec2fCollection; +import net.java.joglutils.msg.collections.Vec3fCollection; +import net.java.joglutils.msg.collections.Vec4fCollection; +import net.java.joglutils.msg.math.Rotf; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.math.Vec3f; +import net.java.joglutils.msg.math.Vec4f; +import net.java.joglutils.msg.misc.Path; +import net.java.joglutils.msg.misc.PickedPoint; +import net.java.joglutils.msg.misc.SystemTime; +import net.java.joglutils.msg.nodes.Blend; +import net.java.joglutils.msg.nodes.Color4; +import net.java.joglutils.msg.nodes.Coordinate3; +import net.java.joglutils.msg.nodes.PerspectiveCamera; +import net.java.joglutils.msg.nodes.Separator; +import net.java.joglutils.msg.nodes.Texture2; +import net.java.joglutils.msg.nodes.TextureCoordinate2; +import net.java.joglutils.msg.nodes.Transform; +import net.java.joglutils.msg.nodes.TriangleSet; /** * A test implementing a 3D display shelf component. This renderer is @@ -66,22 +91,22 @@ import net.java.joglutils.msg.nodes.*; */ public class DisplayShelfRenderer implements GLEventListener { - private float DEFAULT_ASPECT_RATIO = 0.665f; + private final float DEFAULT_ASPECT_RATIO = 0.665f; // This also affects the spacing - private float DEFAULT_HEIGHT = 1.5f; - private float DEFAULT_ON_SCREEN_FRAC = 0.5f; - private float EDITING_ON_SCREEN_FRAC = 0.95f; - private float offsetFrac; + private final float DEFAULT_HEIGHT = 1.5f; + private final float DEFAULT_ON_SCREEN_FRAC = 0.5f; + private final float EDITING_ON_SCREEN_FRAC = 0.95f; + private final float offsetFrac; - private float STACKED_SPACING_FRAC = 0.3f; - private float SELECTED_SPACING_FRAC = 0.6f; - private float EDITED_SPACING_FRAC = 1.5f; + private final float STACKED_SPACING_FRAC = 0.3f; + private final float SELECTED_SPACING_FRAC = 0.6f; + private final float EDITED_SPACING_FRAC = 1.5f; // This is how much we raise the geometry above the floor in single image mode - private float SINGLE_IMAGE_MODE_RAISE_FRAC = 2.0f; + private final float SINGLE_IMAGE_MODE_RAISE_FRAC = 2.0f; // The camera - private PerspectiveCamera camera; + private final PerspectiveCamera camera; static class TitleGraph { Object imageDescriptor; @@ -90,24 +115,24 @@ public class DisplayShelfRenderer implements GLEventListener { Texture2 texture = new Texture2(); Coordinate3 coords = new Coordinate3(); - TitleGraph(Object imageDescriptor) { + TitleGraph(final Object imageDescriptor) { this.imageDescriptor = imageDescriptor; } } // This is used to avoid having to re-initialize textures during // resizes of Swing components - private GLPbuffer sharedPbuffer; + private final GLOffscreenAutoDrawable sharedPbuffer; private boolean firstInit = true; private AWTGLAutoDrawable drawable; - private Separator root; + private final Separator root; private Separator imageRoot; - private Fetcher<Integer> fetcher; - private ListModel model; - private List<TitleGraph> titles = new ArrayList<TitleGraph>(); - private GLRenderAction ra = new GLRenderAction(); + private final Fetcher<Integer> fetcher; + private final ListModel model; + private final List<TitleGraph> titles = new ArrayList<TitleGraph>(); + private final GLRenderAction ra = new GLRenderAction(); private int targetIndex; // This encodes both the current position and the horizontal animation alpha private float currentIndex; @@ -116,7 +141,7 @@ public class DisplayShelfRenderer implements GLEventListener { private float currentZ; private float targetZ; // This is effectively a constant - private float viewingZ; + private final float viewingZ; // This is also currently effectively a constant, though we need to // compute it dynamically for each picture to get it to show up // centered @@ -128,7 +153,7 @@ public class DisplayShelfRenderer implements GLEventListener { // If the difference between the current and target values of any of // the above are > EPSILON, then we will continue repainting private static final float EPSILON = 1.0e-3f; - private SystemTime time; + private final SystemTime time; private boolean animating; private boolean forceRecompute; // Single image mode toggle @@ -144,18 +169,19 @@ public class DisplayShelfRenderer implements GLEventListener { private volatile boolean doneLoading; class DownloadListener implements ProgressListener<Integer> { - public void progressStart(ProgressEvent<Integer> evt) {} - public void progressUpdate(ProgressEvent<Integer> evt) {} - public void progressEnd(ProgressEvent<Integer> evt) { - updateImage(evt.getClientIdentifier()); + public void progressStart(final ProgressEvent<Integer> evt) {} + public void progressUpdate(final ProgressEvent<Integer> evt) {} + public void progressEnd(final ProgressEvent<Integer> evt) { + updateImage(glp, evt.getClientIdentifier()); } } - public DisplayShelfRenderer(ListModel model) { + public DisplayShelfRenderer(final ListModel model) { // Create a small pbuffer with which we share textures and display // lists to avoid having to reload textures during repeated calls // to init() - sharedPbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createGLPbuffer(new GLCapabilities(GLProfile.getDefault()), null, 1, 1, null); + final GLCapabilities glcaps = new GLCapabilities(GLProfile.getDefault()); + sharedPbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createOffscreenAutoDrawable(null, glcaps, null, 8, 8); sharedPbuffer.display(); this.fetcher = new BasicFetcher<Integer>(); @@ -184,7 +210,7 @@ public class DisplayShelfRenderer implements GLEventListener { return sharedPbuffer.getContext(); } - public void setSingleImageMode(boolean singleImageMode, boolean animateTransition) { + public void setSingleImageMode(final boolean singleImageMode, final boolean animateTransition) { this.singleImageMode = singleImageMode; if (!animating) { time.rebase(); @@ -204,7 +230,7 @@ public class DisplayShelfRenderer implements GLEventListener { return titles.size(); } - public void setTargetIndex(int index) { + public void setTargetIndex(final int index) { if (targetIndex == index) return; @@ -222,12 +248,15 @@ public class DisplayShelfRenderer implements GLEventListener { return targetIndex; } - public void init(GLAutoDrawable d) { + private GLProfile glp = null; + + public void init(final GLAutoDrawable d) { this.drawable = (AWTGLAutoDrawable) d; - GL gl = drawable.getGL(); + final GL gl = drawable.getGL(); if (firstInit) { firstInit = false; + glp = gl.getGLProfile(); // Build the scene graph @@ -241,45 +270,45 @@ public class DisplayShelfRenderer implements GLEventListener { imageRoot = new Separator(); // The mirrored images under the floor - Separator mirrorRoot = new Separator(); + final Separator mirrorRoot = new Separator(); - Transform mirrorXform = new Transform(); + final Transform mirrorXform = new Transform(); // Mirror vertically mirrorXform.getTransform().set(1, 1, -1.0f); mirrorRoot.addChild(mirrorXform); // Assume we know what we're doing here with setting per-vertex // colors for each piece of geometry in one shot - Color4 colorNode = new Color4(); - Vec4fCollection colors = new Vec4fCollection(); - Vec4f fadeTop = new Vec4f(0.75f, 0.75f, 0.75f, 0.75f); - Vec4f fadeBot = new Vec4f(0.25f, 0.25f, 0.25f, 0.25f); + final Color4 colorNode = new Color4(); + final Vec4fCollection colors = new Vec4fCollection(); + final Vec4f fadeTop = new Vec4f(0.75f, 0.75f, 0.75f, 0.75f); + final Vec4f fadeBot = new Vec4f(0.25f, 0.25f, 0.25f, 0.25f); // First triangle colors.add(fadeTop); colors.add(fadeTop); colors.add(fadeBot); - // Second triangle + // Second triangle colors.add(fadeTop); colors.add(fadeBot); colors.add(fadeBot); colorNode.setData(colors); mirrorRoot.addChild(colorNode); - TriangleSet tris = new TriangleSet(); + final TriangleSet tris = new TriangleSet(); tris.setNumTriangles(2); for (int i = 0; i < model.getSize(); i++) { - Object obj = model.getElementAt(i); - TitleGraph graph = new TitleGraph(obj); + final Object obj = model.getElementAt(i); + final TitleGraph graph = new TitleGraph(obj); titles.add(graph); computeCoords(graph.coords, DEFAULT_ASPECT_RATIO); graph.xform.getTransform().setTranslation(new Vec3f(i, 0, 0)); - Separator sep = graph.sep; + final Separator sep = graph.sep; sep.addChild(graph.xform); sep.addChild(graph.coords); // Add in the clock texture at the beginning sep.addChild(clockTexture); - TextureCoordinate2 texCoordNode = new TextureCoordinate2(); - Vec2fCollection texCoords = new Vec2fCollection(); + final TextureCoordinate2 texCoordNode = new TextureCoordinate2(); + final Vec2fCollection texCoords = new Vec2fCollection(); // Texture coordinates for two triangles // First triangle texCoords.add(new Vec2f( 1, 1)); @@ -300,46 +329,46 @@ public class DisplayShelfRenderer implements GLEventListener { } // Now produce the floor geometry - float maxSpacing = DEFAULT_HEIGHT * Math.max(STACKED_SPACING_FRAC, Math.max(SELECTED_SPACING_FRAC, EDITED_SPACING_FRAC)); - int i = model.getSize(); - float minx = -i * maxSpacing; - float maxx = 2 * i * maxSpacing; + final float maxSpacing = DEFAULT_HEIGHT * Math.max(STACKED_SPACING_FRAC, Math.max(SELECTED_SPACING_FRAC, EDITED_SPACING_FRAC)); + final int i = model.getSize(); + final float minx = -i * maxSpacing; + final float maxx = 2 * i * maxSpacing; // Furthest back from the camera - float minz = -2 * DEFAULT_HEIGHT; + final float minz = -2 * DEFAULT_HEIGHT; // Assume this will be close enough to cover all of the mirrored geometry - float maxz = DEFAULT_HEIGHT; - Separator floorRoot = new Separator(); - Blend blend = new Blend(); + final float maxz = DEFAULT_HEIGHT; + final Separator floorRoot = new Separator(); + final Blend blend = new Blend(); blend.setEnabled(true); blend.setSourceFunc(Blend.ONE); blend.setDestFunc(Blend.ONE_MINUS_SRC_ALPHA); floorRoot.addChild(blend); - Coordinate3 floorCoords = new Coordinate3(); + final Coordinate3 floorCoords = new Coordinate3(); floorCoords.setData(new Vec3fCollection()); // First triangle floorCoords.getData().add(new Vec3f(maxx, 0, minz)); floorCoords.getData().add(new Vec3f(minx, 0, minz)); floorCoords.getData().add(new Vec3f(minx, 0, maxz)); - // Second triangle + // Second triangle floorCoords.getData().add(new Vec3f(maxx, 0, minz)); floorCoords.getData().add(new Vec3f(minx, 0, maxz)); floorCoords.getData().add(new Vec3f(maxx, 0, maxz)); floorRoot.addChild(floorCoords); // Colors - Vec4f gray = new Vec4f(0.4f, 0.4f, 0.4f, 0.4f); - Vec4f clearGray = new Vec4f(0.0f, 0.0f, 0.0f, 0.0f); - Color4 floorColors = new Color4(); + final Vec4f gray = new Vec4f(0.4f, 0.4f, 0.4f, 0.4f); + final Vec4f clearGray = new Vec4f(0.0f, 0.0f, 0.0f, 0.0f); + final Color4 floorColors = new Color4(); floorColors.setData(new Vec4fCollection()); // First triangle floorColors.getData().add(gray); floorColors.getData().add(gray); floorColors.getData().add(clearGray); - // Second triangle + // Second triangle floorColors.getData().add(gray); floorColors.getData().add(clearGray); floorColors.getData().add(clearGray); floorRoot.addChild(floorColors); - + floorRoot.addChild(tris); // Now set up the overall scene graph @@ -351,7 +380,7 @@ public class DisplayShelfRenderer implements GLEventListener { // Attach listeners (this is only for testing for now) drawable.addMouseListener(new MListener()); drawable.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { + public void keyPressed(final KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_SPACE: setSingleImageMode(!getSingleImageMode(), true); @@ -379,22 +408,22 @@ public class DisplayShelfRenderer implements GLEventListener { // Get the loading started for (int j = 0; j < titles.size(); j++) { - updateImage(j); + updateImage(glp, j); } } } - public void display(GLAutoDrawable drawable) { + public void display(final GLAutoDrawable drawable) { // Recompute position of camera and orientation of images - boolean repaintAgain = recompute(); + final boolean repaintAgain = recompute(); if (!doneLoading) { if (!repaintAgain) { time.update(); } - TextureRenderer rend = clockTexture.getTextureRenderer(); - Graphics2D g = rend.createGraphics(); + final TextureRenderer rend = clockTexture.getTextureRenderer(); + final Graphics2D g = rend.createGraphics(); drawClock(g, (int) (time.time() * 30), 0, 0, rend.getWidth(), rend.getHeight()); g.dispose(); @@ -402,7 +431,7 @@ public class DisplayShelfRenderer implements GLEventListener { } // Redraw - GL gl = drawable.getGL(); + final GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); ra.apply(root); @@ -414,30 +443,30 @@ public class DisplayShelfRenderer implements GLEventListener { } } - public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { } - public void dispose(GLAutoDrawable drawable) {} + public void dispose(final GLAutoDrawable drawable) {} //---------------------------------------------------------------------- // Internals only below this point // - private void computeCoords(Coordinate3 coordNode, float aspectRatio) { + private void computeCoords(final Coordinate3 coordNode, final float aspectRatio) { Vec3fCollection coords = coordNode.getData(); if (coords == null) { coords = new Vec3fCollection(); - Vec3f zero = new Vec3f(); + final Vec3f zero = new Vec3f(); for (int i = 0; i < 6; i++) { coords.add(zero); } coordNode.setData(coords); } // Now compute the actual values - Vec3f lowerLeft = new Vec3f(-0.5f * DEFAULT_HEIGHT * aspectRatio, 0, 0); - Vec3f lowerRight = new Vec3f( 0.5f * DEFAULT_HEIGHT * aspectRatio, 0, 0); - Vec3f upperLeft = new Vec3f(-0.5f * DEFAULT_HEIGHT * aspectRatio, DEFAULT_HEIGHT, 0); - Vec3f upperRight = new Vec3f( 0.5f * DEFAULT_HEIGHT * aspectRatio, DEFAULT_HEIGHT, 0); + final Vec3f lowerLeft = new Vec3f(-0.5f * DEFAULT_HEIGHT * aspectRatio, 0, 0); + final Vec3f lowerRight = new Vec3f( 0.5f * DEFAULT_HEIGHT * aspectRatio, 0, 0); + final Vec3f upperLeft = new Vec3f(-0.5f * DEFAULT_HEIGHT * aspectRatio, DEFAULT_HEIGHT, 0); + final Vec3f upperRight = new Vec3f( 0.5f * DEFAULT_HEIGHT * aspectRatio, DEFAULT_HEIGHT, 0); // First triangle coords.set(0, upperRight); coords.set(1, upperLeft); @@ -448,27 +477,27 @@ public class DisplayShelfRenderer implements GLEventListener { coords.set(5, lowerRight); } - private static void drawClock(Graphics2D g, int minsPastMidnight, - int x, int y, int width, int height) { + private static void drawClock(final Graphics2D g, final int minsPastMidnight, + final int x, final int y, final int width, final int height) { g.setColor(Color.DARK_GRAY); g.fillRect(x, y, width, height); g.setColor(Color.GRAY); - int midx = (int) (x + (width / 2.0f)); - int midy = (int) (y + (height / 2.0f)); - int sz = (int) (0.8f * Math.min(width, height)); + final int midx = (int) (x + (width / 2.0f)); + final int midy = (int) (y + (height / 2.0f)); + final int sz = (int) (0.8f * Math.min(width, height)); g.setStroke(new BasicStroke(sz / 20.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER)); - int arcSz = (int) (0.4f * sz); - int smallHandSz = (int) (0.3f * sz); - int bigHandSz = (int) (0.4f * sz); + final int arcSz = (int) (0.4f * sz); + final int smallHandSz = (int) (0.3f * sz); + final int bigHandSz = (int) (0.4f * sz); g.drawRoundRect(midx - (sz / 2), midy - (sz / 2), sz, sz, arcSz, arcSz); - float hour = minsPastMidnight / 60.0f; - int min = minsPastMidnight % 60; - float hourAngle = hour * 2.0f * (float) Math.PI / 12; - float minAngle = min * 2.0f * (float) Math.PI / 60; + final float hour = minsPastMidnight / 60.0f; + final int min = minsPastMidnight % 60; + final float hourAngle = hour * 2.0f * (float) Math.PI / 12; + final float minAngle = min * 2.0f * (float) Math.PI / 60; g.drawLine(midx, midy, midx + (int) (smallHandSz * Math.cos(hourAngle)), @@ -479,13 +508,13 @@ public class DisplayShelfRenderer implements GLEventListener { } private void startClockAnimation() { - Thread clockAnimThread = new Thread(new Runnable() { + final Thread clockAnimThread = new Thread(new Runnable() { public void run() { while (!doneLoading) { drawable.repaint(); try { Thread.sleep(100); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { } } } @@ -493,19 +522,19 @@ public class DisplayShelfRenderer implements GLEventListener { clockAnimThread.start(); } - private void updateImage(int id) { - TitleGraph graph = titles.get(id); + private void updateImage(final GLProfile glp, final int id) { + final TitleGraph graph = titles.get(id); // Re-fetch - BufferedImage img = fetcher.getImage(graph.imageDescriptor, + final BufferedImage img = fetcher.getImage(graph.imageDescriptor, Integer.valueOf(id), -1); if (img != null) { // We don't need the image descriptor any more graph.imageDescriptor = null; graph.sep.replaceChild(clockTexture, graph.texture); - graph.texture.setTexture(img, false); + graph.texture.setTexture(glp, img, false); // Figure out the new aspect ratio based on the image's width and height - float aspectRatio = (float) img.getWidth() / (float) img.getHeight(); + final float aspectRatio = (float) img.getWidth() / (float) img.getHeight(); // Compute new coordinates computeCoords(graph.coords, aspectRatio); // Schedule a repaint @@ -514,7 +543,7 @@ public class DisplayShelfRenderer implements GLEventListener { // See whether we're completely done loading boolean done = true; - for (TitleGraph cur : titles) { + for (final TitleGraph cur : titles) { if (cur.imageDescriptor != null) { done = false; break; @@ -525,7 +554,7 @@ public class DisplayShelfRenderer implements GLEventListener { } } - private void recomputeTargetYZ(boolean animate) { + private void recomputeTargetYZ(final boolean animate) { if (singleImageMode) { // Compute a target Y and Z depth based on the image we want to view @@ -558,7 +587,7 @@ public class DisplayShelfRenderer implements GLEventListener { forceRecompute = false; time.update(); - float deltaT = (float) time.deltaT(); + final float deltaT = (float) time.deltaT(); // Make the animation speed independent of frame rate currentIndex = currentIndex + (targetIndex - currentIndex) * deltaT * ANIM_SCALE_FACTOR; @@ -566,32 +595,32 @@ public class DisplayShelfRenderer implements GLEventListener { currentY = currentY + (targetY - currentY) * deltaT * ANIM_SCALE_FACTOR; // An alpha of 0 indicates we're fully in viewing mode // An alpha of 1 indicates we're fully in editing mode - float zAlpha = (currentZ - viewingZ) / (editingZ - viewingZ); + final float zAlpha = (currentZ - viewingZ) / (editingZ - viewingZ); // Recompute the positions and orientations of each title, and the position of the camera - int firstIndex = (int) Math.floor(currentIndex); + final int firstIndex = (int) Math.floor(currentIndex); int secondIndex = (int) Math.ceil(currentIndex); if (secondIndex == firstIndex) { secondIndex = firstIndex + 1; } - float alpha = currentIndex - firstIndex; + final float alpha = currentIndex - firstIndex; int idx = 0; float curPos = 0.0f; - float stackedSpacing = DEFAULT_HEIGHT * (zAlpha * EDITED_SPACING_FRAC + (1.0f - zAlpha) * STACKED_SPACING_FRAC); - float selectedSpacing = DEFAULT_HEIGHT * (zAlpha * EDITED_SPACING_FRAC + (1.0f - zAlpha) * SELECTED_SPACING_FRAC); - float angle = (1.0f - zAlpha) * ROT_ANGLE; - float y = zAlpha * DEFAULT_HEIGHT * SINGLE_IMAGE_MODE_RAISE_FRAC; - Rotf posAngle = new Rotf(Vec3f.Y_AXIS, angle); - Rotf negAngle = new Rotf(Vec3f.Y_AXIS, -angle); + final float stackedSpacing = DEFAULT_HEIGHT * (zAlpha * EDITED_SPACING_FRAC + (1.0f - zAlpha) * STACKED_SPACING_FRAC); + final float selectedSpacing = DEFAULT_HEIGHT * (zAlpha * EDITED_SPACING_FRAC + (1.0f - zAlpha) * SELECTED_SPACING_FRAC); + final float angle = (1.0f - zAlpha) * ROT_ANGLE; + final float y = zAlpha * DEFAULT_HEIGHT * SINGLE_IMAGE_MODE_RAISE_FRAC; + final Rotf posAngle = new Rotf(Vec3f.Y_AXIS, angle); + final Rotf negAngle = new Rotf(Vec3f.Y_AXIS, -angle); float offset = 0; // Only bump the selected title out of the list if we're in viewing mode and close to it if (Math.abs(targetIndex - currentIndex) < 3.0) { offset = (1.0f - zAlpha) * offsetFrac * DEFAULT_HEIGHT; } - for (TitleGraph graph : titles) { + for (final TitleGraph graph : titles) { if (idx < firstIndex) { graph.xform.getTransform().setRotation(posAngle); graph.xform.getTransform().setTranslation(new Vec3f(curPos, y, 0)); @@ -605,7 +634,7 @@ public class DisplayShelfRenderer implements GLEventListener { curPos += (1.0f - alpha) * (selectedSpacing - stackedSpacing); // The camera is glued to this position - float cameraPos = curPos + alpha * selectedSpacing; + final float cameraPos = curPos + alpha * selectedSpacing; // Interpolate graph.xform.getTransform().setRotation(new Rotf(Vec3f.Y_AXIS, alpha * angle)); @@ -636,16 +665,16 @@ public class DisplayShelfRenderer implements GLEventListener { class MListener extends MouseAdapter { RayPickAction ra = new RayPickAction(); - public void mousePressed(MouseEvent e) { + public void mousePressed(final MouseEvent e) { ra.setPoint(e.getX(), e.getY(), e.getComponent()); // Apply to the scene root ra.apply(root); - List<PickedPoint> pickedPoints = ra.getPickedPoints(); + final List<PickedPoint> pickedPoints = ra.getPickedPoints(); Path p = null; if (!pickedPoints.isEmpty()) p = pickedPoints.get(0).getPath(); if (p != null && p.size() > 1) { - int idx = imageRoot.findChild(p.get(p.size() - 2)); + final int idx = imageRoot.findChild(p.get(p.size() - 2)); if (idx >= 0) { setTargetIndex(idx); // Need to keep the slider and this mechanism in sync diff --git a/src/net/java/joglutils/msg/test/Fetcher.java b/src/net/java/joglutils/msg/test/Fetcher.java index d37967c..e8c361c 100644 --- a/src/net/java/joglutils/msg/test/Fetcher.java +++ b/src/net/java/joglutils/msg/test/Fetcher.java @@ -30,7 +30,7 @@ package net.java.joglutils.msg.test; -import java.awt.image.*; +import java.awt.image.BufferedImage; /** * Defines how elements in the ListModel associated with the diff --git a/src/net/java/joglutils/msg/test/Test.java b/src/net/java/joglutils/msg/test/Test.java index d54d31b..da2a6ef 100644 --- a/src/net/java/joglutils/msg/test/Test.java +++ b/src/net/java/joglutils/msg/test/Test.java @@ -1,21 +1,21 @@ /* * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * - 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,40 +28,51 @@ * 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. - * + * */ package net.java.joglutils.msg.test; import java.awt.Frame; -import java.awt.event.*; -import java.io.*; - -import javax.media.opengl.*; -import javax.media.opengl.awt.*; -import com.sun.opengl.util.texture.*; - -import net.java.joglutils.msg.actions.*; -import net.java.joglutils.msg.collections.*; -import net.java.joglutils.msg.math.*; -import net.java.joglutils.msg.nodes.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GLAutoDrawable; +import com.jogamp.opengl.GLEventListener; +import com.jogamp.opengl.awt.GLCanvas; + +import net.java.joglutils.msg.actions.GLRenderAction; +import net.java.joglutils.msg.collections.Vec2fCollection; +import net.java.joglutils.msg.collections.Vec3fCollection; +import net.java.joglutils.msg.collections.Vec4fCollection; +import net.java.joglutils.msg.math.Vec2f; +import net.java.joglutils.msg.math.Vec3f; +import net.java.joglutils.msg.math.Vec4f; +import net.java.joglutils.msg.nodes.Color4; +import net.java.joglutils.msg.nodes.Coordinate3; +import net.java.joglutils.msg.nodes.PerspectiveCamera; +import net.java.joglutils.msg.nodes.Separator; +import net.java.joglutils.msg.nodes.TextureCoordinate2; +import net.java.joglutils.msg.nodes.Transform; +import net.java.joglutils.msg.nodes.TriangleSet; /** A very basic test of the Minimal Scene Graph library. */ public class Test { - public static void main(String[] args) { - Frame frame = new Frame("Minimal Scene Graph (MSG) Test"); - GLCanvas canvas = new GLCanvas(); + public static void main(final String[] args) { + final Frame frame = new Frame("Minimal Scene Graph (MSG) Test"); + final GLCanvas canvas = new GLCanvas(); canvas.addGLEventListener(new Listener()); frame.add(canvas); frame.setSize(512, 512); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { + public void windowClosing(final WindowEvent e) { new Thread(new Runnable() { public void run() { System.exit(0); @@ -75,13 +86,13 @@ public class Test { private Separator root; private GLRenderAction renderAction; - public void init(GLAutoDrawable drawable) { + public void init(final GLAutoDrawable drawable) { root = new Separator(); - PerspectiveCamera cam = new PerspectiveCamera(); + final PerspectiveCamera cam = new PerspectiveCamera(); cam.setPosition(new Vec3f(0, 0, 2)); root.addChild(cam); - Coordinate3 coordNode = new Coordinate3(); - Vec3fCollection coords = new Vec3fCollection(); + final Coordinate3 coordNode = new Coordinate3(); + final Vec3fCollection coords = new Vec3fCollection(); // First triangle coords.add(new Vec3f( 1, 1, 0)); coords.add(new Vec3f(-1, 1, 0)); @@ -94,8 +105,8 @@ public class Test { root.addChild(coordNode); // Texture coordinates - TextureCoordinate2 texCoordNode = new TextureCoordinate2(); - Vec2fCollection texCoords = new Vec2fCollection(); + final TextureCoordinate2 texCoordNode = new TextureCoordinate2(); + final Vec2fCollection texCoords = new Vec2fCollection(); // First triangle texCoords.add(new Vec2f( 1, 1)); texCoords.add(new Vec2f( 0, 1)); @@ -108,8 +119,8 @@ public class Test { root.addChild(texCoordNode); // Colors - Color4 colorNode = new Color4(); - Vec4fCollection colors = new Vec4fCollection(); + final Color4 colorNode = new Color4(); + final Vec4fCollection colors = new Vec4fCollection(); // First triangle colors.add(new Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); colors.add(new Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); @@ -121,31 +132,31 @@ public class Test { colorNode.setData(colors); root.addChild(colorNode); - TriangleSet tris = new TriangleSet(); + final TriangleSet tris = new TriangleSet(); tris.setNumTriangles(2); root.addChild(tris); // Testing transforms - Transform xform = new Transform(); + final Transform xform = new Transform(); xform.getTransform().setTranslation(new Vec3f(2, -2, 0)); // xform.getTransform().setRotation(new Rotf(new Vec3f(0, 1, 0), (float) (-Math.PI / 4))); root.addChild(xform); root.addChild(tris); - GL gl = drawable.getGL(); + final GL gl = drawable.getGL(); gl.glEnable(GL.GL_DEPTH_TEST); renderAction = new GLRenderAction(); } - public void display(GLAutoDrawable drawable) { - GL gl = drawable.getGL(); + public void display(final GLAutoDrawable drawable) { + final GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); renderAction.apply(root); } - public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {} - public void dispose(GLAutoDrawable drawable) {} + public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int w, final int h) {} + public void dispose(final GLAutoDrawable drawable) {} } } diff --git a/src/net/java/joglutils/test3ds/Main.java b/src/net/java/joglutils/test3ds/Main.java index 593c1a4..fcb9a4d 100644 --- a/src/net/java/joglutils/test3ds/Main.java +++ b/src/net/java/joglutils/test3ds/Main.java @@ -36,29 +36,35 @@ package net.java.joglutils.test3ds;
-import com.sun.opengl.util.Animator;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
-import javax.media.opengl.*;
-import javax.media.opengl.awt.*;
-import javax.media.opengl.glu.GLU;
+
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2;
+import com.jogamp.opengl.GL2ES1;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLEventListener;
+import com.jogamp.opengl.awt.GLCanvas;
+import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.opengl.glu.GLU;
+import com.jogamp.opengl.util.Animator;
public class Main {
/** Creates a new instance of Main */
public Main() {
}
- public static void main(String[] args)
+ public static void main(final String[] args)
{
- Frame frame = new Frame();
- GLCanvas canvas = new GLCanvas();
+ final Frame frame = new Frame();
+ final GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(new Renderer());
frame.add(canvas);
frame.setSize(600, 600);
final Animator animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
+ public void windowClosing(final WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
@@ -76,12 +82,12 @@ public class Main { static class Renderer implements GLEventListener
{
- private MyModel model = new MyModel();
+ private final MyModel model = new MyModel();
- public void display(GLAutoDrawable gLDrawable)
+ public void display(final GLAutoDrawable gLDrawable)
{
final GL2 gl = gLDrawable.getGL().getGL2();
- gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glPushMatrix();
@@ -93,22 +99,22 @@ public class Main { }
- public void dispose(GLAutoDrawable drawable) {}
+ public void dispose(final GLAutoDrawable drawable) {}
/** Called by the drawable immediately after the OpenGL context is
* initialized for the first time. Can be used to perform one-time OpenGL
* initialization such as setup of lights and display lists.
* @param gLDrawable The GLDrawable object.
*/
- public void init(GLAutoDrawable gLDrawable)
+ public void init(final GLAutoDrawable gLDrawable)
{
final GL2 gl = gLDrawable.getGL().getGL2();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.3f);
gl.glClearDepth(1.0f);
- gl.glEnable(GL2.GL_DEPTH_TEST);
- gl.glDepthFunc(GL2.GL_LEQUAL);
- gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ gl.glDepthFunc(GL.GL_LEQUAL);
+ gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
if (!model.isLoaded())
model.load(gLDrawable, "globe.3ds");
@@ -128,7 +134,7 @@ public class Main { * @param width The new width of the window.
* @param height The new height of the window.
*/
- public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height)
+ public void reshape(final GLAutoDrawable gLDrawable, final int x, final int y, final int width, int height)
{
final GL2 gl = gLDrawable.getGL().getGL2();
final GLU glu = new GLU();
@@ -137,10 +143,10 @@ public class Main { height = 1;
final float h = (float)width / (float)height;
gl.glViewport(0, 0, width, height);
- gl.glMatrixMode(GL2.GL_PROJECTION);
+ gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(-1000, 1000, -1000, 1000, -10000, 10000);
- gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity();
}
}
diff --git a/src/net/java/joglutils/test3ds/MyModel.java b/src/net/java/joglutils/test3ds/MyModel.java index fbdca36..31ce989 100644 --- a/src/net/java/joglutils/test3ds/MyModel.java +++ b/src/net/java/joglutils/test3ds/MyModel.java @@ -1,34 +1,34 @@ /*
* Copyright (c) 2006 Greg Rodgers 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.
- *
+ *
* The names of Greg Rodgers, Sun Microsystems, Inc. or the names of
* contributors may not 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. GREG RODGERS,
* SUN MICROSYSTEMS, INC. ("SUN"), AND SUN'S 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 GREG
- * RODGERS, SUN, OR SUN'S LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL GREG
+ * RODGERS, SUN, OR SUN'S 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 GREG
* RODGERS OR 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.
@@ -36,13 +36,18 @@ package net.java.joglutils.test3ds;
-import net.java.joglutils.ThreeDS.*;
-import com.sun.opengl.util.texture.Texture;
-import com.sun.opengl.util.texture.TextureCoords;
-import com.sun.opengl.util.texture.TextureIO;
import java.io.File;
import java.io.IOException;
-import javax.media.opengl.*;
+
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.util.texture.Texture;
+import com.jogamp.opengl.util.texture.TextureCoords;
+import com.jogamp.opengl.util.texture.TextureIO;
+
+import net.java.joglutils.ThreeDS.Model3DS;
+import net.java.joglutils.ThreeDS.Obj;
public class MyModel extends Model3DS
{
@@ -50,76 +55,76 @@ public class MyModel extends Model3DS private TextureCoords[] textureCoords;
private int compiledList;
private boolean loaded = false;
-
+
// Constructor
public MyModel()
{
}
-
+
public boolean isLoaded()
{
return loaded;
}
-
- public boolean load(GLAutoDrawable gLDrawable, String file)
+
+ public boolean load(final GLAutoDrawable gLDrawable, final String file)
{
if (!super.load(file))
return false;
-
- GL2 gl = gLDrawable.getGL().getGL2();
- int numMaterials = materials.size();
-
+
+ final GL2 gl = gLDrawable.getGL().getGL2();
+ final int numMaterials = materials.size();
+
texture = new Texture[numMaterials];
for (int i=0; i<numMaterials; i++) {
loadTexture(materials.get(i).strFile, i);
materials.get(i).texureId = i;
}
-
+
compiledList = gl.glGenLists(1);
gl.glNewList(compiledList, GL2.GL_COMPILE);
genList(gLDrawable);
gl.glEndList();
-
+
loaded = true;
-
+
return loaded;
}
-
- public void render(GLAutoDrawable gLDrawable)
+
+ public void render(final GLAutoDrawable gLDrawable)
{
- GL2 gl = gLDrawable.getGL().getGL2();
+ final GL2 gl = gLDrawable.getGL().getGL2();
gl.glCallList(compiledList);
}
- private void loadTexture(String strFile, int id)
+ private void loadTexture(final String strFile, final int id)
{
- File file = new File(strFile);
+ final File file = new File(strFile);
try {
texture[id] = TextureIO.newTexture(file, true);
}
- catch (IOException e) {
+ catch (final IOException e) {
System.err.println(e.getMessage());
return;
}
}
-
- private void genList(GLAutoDrawable gLDrawable)
+
+ private void genList(final GLAutoDrawable gLDrawable)
{
- GL2 gl = gLDrawable.getGL().getGL2();
+ final GL2 gl = gLDrawable.getGL().getGL2();
TextureCoords coords;
-
+
for (int i=0; i<objects.size(); i++) {
- Obj tempObj = objects.get(i);
+ final Obj tempObj = objects.get(i);
if(tempObj.hasTexture) {
- texture[tempObj.materialID].enable();
- texture[tempObj.materialID].bind();
+ texture[tempObj.materialID].enable(gl);
+ texture[tempObj.materialID].bind(gl);
coords = texture[tempObj.materialID].getImageTexCoords();
}
-
- gl.glBegin(GL2.GL_TRIANGLES);
+
+ gl.glBegin(GL.GL_TRIANGLES);
for (int j=0; j<tempObj.numOfFaces; j++) {
for (int whichVertex=0; whichVertex<3; whichVertex++) {
- int index = tempObj.faces[j].vertIndex[whichVertex];
+ final int index = tempObj.faces[j].vertIndex[whichVertex];
gl.glNormal3f(tempObj.normals[index].x, tempObj.normals[index].y, tempObj.normals[index].z);
if (tempObj.hasTexture) {
if (tempObj.texVerts != null)
@@ -127,7 +132,7 @@ public class MyModel extends Model3DS }
else {
if (materials.size() < tempObj.materialID) {
- byte pColor[] = materials.get(tempObj.materialID).color;
+ final byte pColor[] = materials.get(tempObj.materialID).color;
// Do something with the color
}
}
@@ -135,9 +140,9 @@ public class MyModel extends Model3DS }
}
gl.glEnd();
-
+
if (tempObj.hasTexture)
- texture[tempObj.materialID].disable();
+ texture[tempObj.materialID].disable(gl);
}
}
}
|