From cd09b499eb9069dc5f7a83d229c318ccf144b56c Mon Sep 17 00:00:00 2001 From: jada Date: Fri, 3 Mar 2006 03:23:40 +0000 Subject: 1) Added VertexAttrTestCg and converted more programs to use JFrame instead of MainFrame 2) Cleanup and rename. --- .../j3d/examples/cg_shader/VertexAttrTestCg.form | 203 +++++++++++ .../j3d/examples/cg_shader/VertexAttrTestCg.java | 396 ++++++++++++++++++++ .../j3d/examples/cg_shader/vertexshader_vp.cg | 77 ++++ .../j3d/examples/fps_counter/FPSCounterDemo.form | 36 ++ .../j3d/examples/fps_counter/FPSCounterDemo.java | 153 ++++---- .../org/jdesktop/j3d/examples/gears/GearBox.form | 36 ++ .../org/jdesktop/j3d/examples/gears/GearBox.java | 168 +++++---- .../org/jdesktop/j3d/examples/gears/GearTest.form | 36 ++ .../org/jdesktop/j3d/examples/gears/GearTest.java | 153 +++++--- .../j3d/examples/glsl_shader/VertexAttrTest.form | 203 ----------- .../j3d/examples/glsl_shader/VertexAttrTest.java | 401 --------------------- .../examples/glsl_shader/VertexAttrTestGLSL.form | 203 +++++++++++ .../examples/glsl_shader/VertexAttrTestGLSL.java | 397 ++++++++++++++++++++ src/classes/org/jdesktop/j3d/examples/lod/LOD.form | 36 ++ src/classes/org/jdesktop/j3d/examples/lod/LOD.java | 107 ++++-- .../jdesktop/j3d/examples/morphing/Morphing.form | 36 ++ .../jdesktop/j3d/examples/morphing/Morphing.java | 145 ++++---- .../j3d/examples/morphing/Pyramid2Cube.form | 36 ++ .../j3d/examples/morphing/Pyramid2Cube.java | 92 +++-- 19 files changed, 1998 insertions(+), 916 deletions(-) create mode 100644 src/classes/org/jdesktop/j3d/examples/cg_shader/VertexAttrTestCg.form create mode 100644 src/classes/org/jdesktop/j3d/examples/cg_shader/VertexAttrTestCg.java create mode 100644 src/classes/org/jdesktop/j3d/examples/cg_shader/vertexshader_vp.cg create mode 100644 src/classes/org/jdesktop/j3d/examples/fps_counter/FPSCounterDemo.form create mode 100644 src/classes/org/jdesktop/j3d/examples/gears/GearBox.form create mode 100644 src/classes/org/jdesktop/j3d/examples/gears/GearTest.form delete mode 100644 src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTest.form delete mode 100644 src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTest.java create mode 100644 src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTestGLSL.form create mode 100644 src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTestGLSL.java create mode 100644 src/classes/org/jdesktop/j3d/examples/lod/LOD.form create mode 100644 src/classes/org/jdesktop/j3d/examples/morphing/Morphing.form create mode 100644 src/classes/org/jdesktop/j3d/examples/morphing/Pyramid2Cube.form (limited to 'src/classes/org') diff --git a/src/classes/org/jdesktop/j3d/examples/cg_shader/VertexAttrTestCg.form b/src/classes/org/jdesktop/j3d/examples/cg_shader/VertexAttrTestCg.form new file mode 100644 index 0000000..736b93c --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/cg_shader/VertexAttrTestCg.form @@ -0,0 +1,203 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/classes/org/jdesktop/j3d/examples/cg_shader/VertexAttrTestCg.java b/src/classes/org/jdesktop/j3d/examples/cg_shader/VertexAttrTestCg.java new file mode 100644 index 0000000..b724efa --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/cg_shader/VertexAttrTestCg.java @@ -0,0 +1,396 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ +package org.jdesktop.j3d.examples.cg_shader; + +import com.sun.j3d.utils.universe.*; +import com.sun.j3d.utils.shader.StringIO; +import javax.media.j3d.*; +import java.awt.GraphicsConfiguration; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.vecmath.Color3f; +import javax.vecmath.Point3d; +import org.jdesktop.j3d.examples.Resources; + + +public class VertexAttrTestCg extends javax.swing.JFrame { + + SimpleUniverse u = null; + BranchGroup scene = null; + + public BranchGroup createSceneGraph(boolean hasVertexAttrs) { + + // Bounds for BG and behavior + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + + // Create the root of the branch graph + BranchGroup objRoot = new BranchGroup(); + objRoot.setCapability(BranchGroup.ALLOW_DETACH); + + // Set up the background + Color3f bgColor = new Color3f(0.1f, 0.1f, 0.1f); + Background bg = new Background(bgColor); + bg.setApplicationBounds(bounds); + objRoot.addChild(bg); + + // Create the TransformGroup node and initialize it to the + // identity. Enable the TRANSFORM_WRITE capability so that + // our behavior code can modify it at run time. Add it to + // the root of the subgraph. + TransformGroup objTrans = new TransformGroup(); + objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + objRoot.addChild(objTrans); + + // Create a simple Shape3D node; add it to the scene graph. + objTrans.addChild(new MyShape(this, hasVertexAttrs)); + + return objRoot; + } + + private Canvas3D initScene() { + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + + Canvas3D c = new Canvas3D(config); + + u = new SimpleUniverse(c); + + ViewingPlatform viewingPlatform = u.getViewingPlatform(); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + viewingPlatform.setNominalViewingTransform(); + + return c; + } + + /** + * Creates new form VertexAttrTestCg + */ + public VertexAttrTestCg() { + // Initialize the GUI components + initComponents(); + + // Create the scene and add the Canvas3D to the drawing panel + Canvas3D c = initScene(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + } + + static class MyShape extends Shape3D { + // Coordinate data + private static final float[] coords = { + 0.0f, 0.0f, 0.0f, + 0.5f, 0.0f, 0.0f, + 0.0f, 0.5f, 0.0f, + }; + + private static final int[] sizes = { 1, 3 }; + private static final float[] weights = { + 0.45f, + 0.15f, + 0.95f, + }; + private static final float[] temps = { + 1.0f, 0.5f, 0.5f, + 0.5f, 1.0f, 0.5f, + 0.5f, 0.5f, 1.0f, + }; + + private static final String[] vaNames = { "weight", "temperature" }; + + J3DBuffer createDirectFloatBuffer(float[] arr) { + ByteOrder order = ByteOrder.nativeOrder(); + + FloatBuffer nioBuf = ByteBuffer.allocateDirect(arr.length * 4).order(order).asFloatBuffer(); + nioBuf.put(arr); + return new J3DBuffer(nioBuf); + } + + + MyShape(JFrame frame, boolean hasVertexAttrs) { + + int vertexFormat = GeometryArray.COORDINATES; + int vertexAttrCount = 0; + int[] vertexAttrSizes = null; + String[] vertexAttrNames = null; + String[] shaderAttrNames = null; + + if (hasVertexAttrs) { + vertexFormat |= GeometryArray.VERTEX_ATTRIBUTES; + vertexAttrCount = vaNames.length; + vertexAttrSizes = sizes; + vertexAttrNames = vaNames; + } + + TriangleArray tri = new TriangleArray(6, vertexFormat, 0, null, vertexAttrCount, vertexAttrSizes); + tri.setValidVertexCount(3); + tri.setCoordinates(0, coords); + + if (hasVertexAttrs) { + tri.setVertexAttrs(0, 0, weights); + tri.setVertexAttrs(1, 0, temps); + + + String vertexProgram = null; + try { + vertexProgram = StringIO.readFully(Resources.getResource("cg_shader/myshader_vp.cg")); + } catch (IOException e) { + throw new RuntimeException(e); + } + + Shader[] shaders = new Shader[1]; + shaders[0] = new SourceCodeShader(Shader.SHADING_LANGUAGE_CG, + Shader.SHADER_TYPE_VERTEX, + vertexProgram); + ShaderProgram shaderProgram = new CgShaderProgram(); + shaderProgram.setShaders(shaders); + shaderProgram.setVertexAttrNames(vertexAttrNames); + + ShaderAppearance app = new ShaderAppearance(); + app.setShaderProgram(shaderProgram); + + this.setGeometry(tri); + this.setAppearance(app); + + } else { + this.setGeometry(tri); + this.setAppearance(new Appearance()); + } + } + } + + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + mainPanel = new javax.swing.JPanel(); + guiPanel = new javax.swing.JPanel(); + vertexCheckBoxPanel = new javax.swing.JPanel(); + jPanel1 = new javax.swing.JPanel(); + jSeparator1 = new javax.swing.JSeparator(); + jSeparator2 = new javax.swing.JSeparator(); + jPanel2 = new javax.swing.JPanel(); + vertexAttrsBox = new javax.swing.JCheckBox(); + geometryPanel = new javax.swing.JPanel(); + createButton = new javax.swing.JButton(); + destroyButton = new javax.swing.JButton(); + drawingPanel = new javax.swing.JPanel(); + jMenuBar1 = new javax.swing.JMenuBar(); + fileMenu = new javax.swing.JMenu(); + exitMenuItem = new javax.swing.JMenuItem(); + + setTitle("Vertex Attribute Test"); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent evt) { + exitForm(evt); + } + }); + + mainPanel.setLayout(new java.awt.BorderLayout()); + + guiPanel.setLayout(new java.awt.GridBagLayout()); + + guiPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); + vertexCheckBoxPanel.setLayout(new java.awt.GridBagLayout()); + + vertexCheckBoxPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "vertexFormat", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Sans", 0, 10))); + jPanel1.setLayout(new java.awt.GridBagLayout()); + + jSeparator1.setPreferredSize(new java.awt.Dimension(0, 4)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + jPanel1.add(jSeparator1, gridBagConstraints); + + jSeparator2.setPreferredSize(new java.awt.Dimension(0, 4)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 3; + jPanel1.add(jSeparator2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; + vertexCheckBoxPanel.add(jPanel1, gridBagConstraints); + + jPanel2.setLayout(new java.awt.GridBagLayout()); + + vertexAttrsBox.setSelected(true); + vertexAttrsBox.setText("VertexAttrs"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 4; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + jPanel2.add(vertexAttrsBox, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; + vertexCheckBoxPanel.add(jPanel2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); + guiPanel.add(vertexCheckBoxPanel, gridBagConstraints); + + geometryPanel.setLayout(new java.awt.GridBagLayout()); + + createButton.setText("Create Geometry"); + createButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + createButtonActionPerformed(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + geometryPanel.add(createButton, gridBagConstraints); + + destroyButton.setText("Destroy Geometry"); + destroyButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + destroyButtonActionPerformed(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0); + geometryPanel.add(destroyButton, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); + guiPanel.add(geometryPanel, gridBagConstraints); + + mainPanel.add(guiPanel, java.awt.BorderLayout.NORTH); + + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(500, 500)); + mainPanel.add(drawingPanel, java.awt.BorderLayout.CENTER); + + getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER); + + fileMenu.setText("File"); + exitMenuItem.setText("Exit"); + exitMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + exitMenuItemActionPerformed(evt); + } + }); + + fileMenu.add(exitMenuItem); + + jMenuBar1.add(fileMenu); + + setJMenuBar(jMenuBar1); + + pack(); + }// //GEN-END:initComponents + + private void destroyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_destroyButtonActionPerformed + if (scene != null) { + u.getLocale().removeBranchGraph(scene); + scene = null; + } + }//GEN-LAST:event_destroyButtonActionPerformed + + private void createButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createButtonActionPerformed + if (scene == null) { + boolean hasVertexAttrs = vertexAttrsBox.isSelected(); + scene = createSceneGraph(hasVertexAttrs); + u.addBranchGraph(scene); + } + }//GEN-LAST:event_createButtonActionPerformed + + private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed + System.exit(0); + }//GEN-LAST:event_exitMenuItemActionPerformed + + /** Exit the Application */ + private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm + System.exit(0); + }//GEN-LAST:event_exitForm + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new VertexAttrTestCg().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton createButton; + private javax.swing.JButton destroyButton; + private javax.swing.JPanel drawingPanel; + private javax.swing.JMenuItem exitMenuItem; + private javax.swing.JMenu fileMenu; + private javax.swing.JPanel geometryPanel; + private javax.swing.JPanel guiPanel; + private javax.swing.JMenuBar jMenuBar1; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel2; + private javax.swing.JSeparator jSeparator1; + private javax.swing.JSeparator jSeparator2; + private javax.swing.JPanel mainPanel; + private javax.swing.JCheckBox vertexAttrsBox; + private javax.swing.JPanel vertexCheckBoxPanel; + // End of variables declaration//GEN-END:variables + +} diff --git a/src/classes/org/jdesktop/j3d/examples/cg_shader/vertexshader_vp.cg b/src/classes/org/jdesktop/j3d/examples/cg_shader/vertexshader_vp.cg new file mode 100644 index 0000000..0e44251 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/cg_shader/vertexshader_vp.cg @@ -0,0 +1,77 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + + +// define inputs from application +struct appin +{ + float4 Position : POSITION; + float4 Normal : NORMAL; +}; + +// define outputs from vertex shader +struct vertout +{ + float4 Position : POSITION; + float4 Color0 : COLOR0; +}; + + +vertout main(appin IN, + float3 temperature, + float weight, + uniform float4x4 ModelViewProj) +{ + vertout OUT; + + ModelViewProj = glstate.matrix.mvp; + + // transform vertex position into homogenous clip-space + OUT.Position = mul(ModelViewProj, IN.Position); + + // Compute color from temperature, weight + OUT.Color0 = float4(temperature * weight, 1.0); + + return OUT; +} diff --git a/src/classes/org/jdesktop/j3d/examples/fps_counter/FPSCounterDemo.form b/src/classes/org/jdesktop/j3d/examples/fps_counter/FPSCounterDemo.form new file mode 100644 index 0000000..0a6a276 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/fps_counter/FPSCounterDemo.form @@ -0,0 +1,36 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/classes/org/jdesktop/j3d/examples/fps_counter/FPSCounterDemo.java b/src/classes/org/jdesktop/j3d/examples/fps_counter/FPSCounterDemo.java index f73be9d..d7f8ee9 100644 --- a/src/classes/org/jdesktop/j3d/examples/fps_counter/FPSCounterDemo.java +++ b/src/classes/org/jdesktop/j3d/examples/fps_counter/FPSCounterDemo.java @@ -44,31 +44,29 @@ package org.jdesktop.j3d.examples.fps_counter; -import java.applet.Applet; -import java.awt.BorderLayout; -import java.awt.event.*; -import java.awt.GraphicsConfiguration; -import com.sun.j3d.utils.applet.JMainFrame; -import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.*; +import com.sun.j3d.utils.geometry.ColorCube; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; import javax.swing.JOptionPane; -/** This program demonstrates the use of the frames per second counter. +/** + * This program demonstrates the use of the frames per second counter. * The program displays a rotating cube and sets up the FPSCounter to compute * the frame rate. The FPSCounter is set up with default values: * - run indefinitely - * - 2 sec. warmup time - * - display average frame rate every fifth sampling interval. + * - 2 sec. warmup time + * - display average frame rate every fifth sampling interval. * The default values can be changed through the command line - * arguments. Use FPSCounterDemo -h for help on the various arguments. + * arguments. Use FPSCounterDemo1 -h for help on the various arguments. */ +public class FPSCounterDemo extends javax.swing.JFrame { -public class FPSCounterDemo extends Applet { - private SimpleUniverse u = null; + private SimpleUniverse univ = null; + private BranchGroup scene = null; private FPSCounter fpsCounter = new FPSCounter(); - + BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); @@ -105,60 +103,53 @@ public class FPSCounterDemo extends Applet { return objRoot; } + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public FPSCounterDemo(String args[]) { - } - - public FPSCounterDemo() { - } - - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); - - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - - // Parse the command line to set the various parameters + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - // Have Java 3D perform optimizations on this scene graph. - scene.compile(); - u = new SimpleUniverse(c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - u.addBranchGraph(scene); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - JOptionPane.showMessageDialog(this, - ("This program measures the number of frames rendered per second.\n" + - "Note that the frame rate is limited by the refresh rate of the monitor.\n" + - "To get the true frame rate you need to disable vertical retrace.\n\n" + - "On Windows(tm) you do this through the Control Panel.\n\n" + - "On Solaris set the environment variable OGL_NO_VBLANK"), - "Frame Counter", - JOptionPane.INFORMATION_MESSAGE); - } - - public void destroy() { - u.cleanup(); - } - - // - // The following allows FPSCounterDemo to be run as an application - // as well as an applet - // - public static void main(String[] args) { - FPSCounterDemo fp = new FPSCounterDemo(); - fp.parseArgs(args); - JMainFrame frame = new JMainFrame(fp, 256, 256); - } + return c; + } + /** + * Creates new form FPSCounterDemo + */ + public FPSCounterDemo() { + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); + + JOptionPane.showMessageDialog(this, + ("This program measures the number of frames rendered per second.\n" + + "Note that the frame rate is limited by the refresh rate of the monitor.\n" + + "To get the true frame rate you need to disable vertical retrace.\n\n" + + "On Windows(tm) you do this through the Control Panel.\n\n" + + "On Solaris set the environment variable OGL_NO_VBLANK"), + "Frame Counter", + JOptionPane.INFORMATION_MESSAGE); + + } + /** Parses the commandline for the various switches to set the FPSCounter * variables. * All arguments are of the form -name value. @@ -217,5 +208,43 @@ public class FPSCounterDemo extends Applet { } } } - + + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("FPSCounterDemo"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(250, 250)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + FPSCounterDemo fp = new FPSCounterDemo(); + fp.parseArgs(args); + fp.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/gears/GearBox.form b/src/classes/org/jdesktop/j3d/examples/gears/GearBox.form new file mode 100644 index 0000000..840732c --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/gears/GearBox.form @@ -0,0 +1,36 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/classes/org/jdesktop/j3d/examples/gears/GearBox.java b/src/classes/org/jdesktop/j3d/examples/gears/GearBox.java index a3b0a84..ba18906 100644 --- a/src/classes/org/jdesktop/j3d/examples/gears/GearBox.java +++ b/src/classes/org/jdesktop/j3d/examples/gears/GearBox.java @@ -45,23 +45,23 @@ package org.jdesktop.j3d.examples.gears; import com.sun.j3d.utils.behaviors.mouse.*; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import java.lang.Integer; import com.sun.j3d.utils.behaviors.vp.*; +import java.awt.GraphicsConfiguration; -public class GearBox extends Applet { +/** + * Simple Java 3D example program to display a spinning cube. + */ +public class GearBox extends javax.swing.JFrame { - static final int defaultToothCount = 48; - private int toothCount; - private SimpleUniverse u = null; + private SimpleUniverse univ = null; + private BranchGroup scene = null; + private int toothCount = 48; - public BranchGroup createGearBox(int toothCount) { + public BranchGroup createSceneGraph() { Transform3D tempTransform = new Transform3D(); // Create the root of the branch graph @@ -177,7 +177,7 @@ public class GearBox extends Applet { } // Define the gear base information. Again, these arrays exist to - // make the process of changing the GearBox via an editor faster + // make the process of changing the GearBox1 via an editor faster int gearCount = 5; float valleyToCircularPitchRatio = .15f; float pitchCircleRadius = 1.0f; @@ -282,75 +282,113 @@ public class GearBox extends Applet { return branchRoot; } - public GearBox() { - this(defaultToothCount); - } + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public GearBox(int toothCount) { - this.toothCount = toothCount; - } - - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); - - // Create the gearbox and attach it to the virtual universe - BranchGroup scene = createGearBox(toothCount); - u = new SimpleUniverse(c); + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); + // Create simple universe with view branch + univ = new SimpleUniverse(c); + // add mouse behaviors to the ViewingPlatform - ViewingPlatform viewingPlatform = u.getViewingPlatform(); - - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - viewingPlatform.setNominalViewingTransform(); + ViewingPlatform viewingPlatform = univ.getViewingPlatform(); - // add orbit behavior to the ViewingPlatform + // add orbit behavior to the ViewingPlatform OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); orbit.setSchedulingBounds(bounds); viewingPlatform.setViewPlatformBehavior(orbit); - u.addBranchGraph(scene); - } + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - public void destroy() { - u.cleanup(); - } + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - // - // The following allows GearBox to be run as an application - // as well as an applet - // - public static void main(String[] args) { + return c; + } + + + /** + * Creates new form GearBox + */ + public GearBox(String args[]) { int value; if (args.length > 1) { - System.out.println("Usage: java GearBox #teeth (LCD 4)"); - System.exit(0); - } else if (args.length == 0) { - new MainFrame(new GearBox(), 700, 700); - } else - { - try{ - value = Integer.parseInt(args[0]); - } catch (NumberFormatException e) { - System.out.println("Illegal integer specified"); - System.out.println("Usage: java GearBox #teeth (LCD 4)"); - value = 0; - System.exit(0); - } - if (value <= 0 | (value % 4) != 0) { - System.out.println("Integer not a positive multiple of 4"); - System.out.println("Usage: java GearBox #teeth (LCD 4)"); - System.exit(0); - } - new MainFrame(new GearBox(value), 700, 700); - } + System.out.println("Usage: java GearBox #teeth (LCD 4)"); + System.exit(0); + } else if (args.length == 1) { + { + try{ + value = Integer.parseInt(args[0]); + } catch (NumberFormatException e) { + System.out.println("Illegal integer specified"); + System.out.println("Usage: java GearBox #teeth (LCD 4)"); + value = 0; + System.exit(0); + } + if (value <= 0 | (value % 4) != 0) { + System.out.println("Integer not a positive multiple of 4"); + System.out.println("Usage: java GearBox #teeth (LCD 4)"); + System.exit(0); + } + toothCount = value; + } + } + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } + + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("GearBox"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + GearBox gb = new GearBox(args); + gb.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/gears/GearTest.form b/src/classes/org/jdesktop/j3d/examples/gears/GearTest.form new file mode 100644 index 0000000..0ba2e64 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/gears/GearTest.form @@ -0,0 +1,36 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/classes/org/jdesktop/j3d/examples/gears/GearTest.java b/src/classes/org/jdesktop/j3d/examples/gears/GearTest.java index 29ecca9..b6ffc85 100644 --- a/src/classes/org/jdesktop/j3d/examples/gears/GearTest.java +++ b/src/classes/org/jdesktop/j3d/examples/gears/GearTest.java @@ -44,23 +44,22 @@ package org.jdesktop.j3d.examples.gears; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; +import com.sun.j3d.utils.geometry.ColorCube; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; -public class GearTest extends Applet { - - static final int defaultToothCount = 24; - - private int toothCount; +/** + * Simple Java 3D example program to display a spinning cube. + */ +public class GearTest extends javax.swing.JFrame { - private SimpleUniverse u = null; + private int toothCount = 24; + private SimpleUniverse univ = null; + private BranchGroup scene = null; - public BranchGroup createSceneGraph(int toothCount) { + public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); @@ -144,65 +143,101 @@ public class GearTest extends Applet { return objRoot; } - public GearTest() { - this(defaultToothCount); - } - - public GearTest(int toothCount) { - this.toothCount = toothCount; - } - - public void init() { - setLayout(new BorderLayout()); + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(toothCount); - u = new SimpleUniverse(c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - u.addBranchGraph(scene); - } + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - public void destroy() { - u.cleanup(); + return c; } - // - // The following allows GearTest to be run as an application - // as well as an applet - // - public static void main(String[] args) { + /** + * Creates new form GearTest + */ + public GearTest(String args[]) { int value; if (args.length > 1) { - System.out.println("Usage: java GearTest [#teeth]"); - System.exit(0); - } else if (args.length == 0) { - new MainFrame(new GearTest(), 700, 700); - } else - { - try { - value = Integer.parseInt(args[0]); - } catch (NumberFormatException e) { - System.out.println("Illegal integer specified"); - System.out.println("Usage: java GearTest [#teeth]"); - value = 0; - System.exit(0); - } - if (value <= 0) { - System.out.println("Integer must be positive (> 0)"); - System.out.println("Usage: java GearBox [#teeth]"); - System.exit(0); - } - new MainFrame(new GearTest(value), 700, 700); - } + System.out.println("Usage: java GearTest [#teeth]"); + System.exit(0); + } else if (args.length == 1) { + try { + value = Integer.parseInt(args[0]); + } catch (NumberFormatException e) { + System.out.println("Illegal integer specified"); + System.out.println("Usage: java GearTest [#teeth]"); + value = 0; + System.exit(0); + } + if (value <= 0) { + System.out.println("Integer must be positive (> 0)"); + System.out.println("Usage: java GearBox [#teeth]"); + System.exit(0); + } + toothCount = value; + + } + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); + } + + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("GearTest"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + GearTest gt = new GearTest(args); + gt.setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTest.form b/src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTest.form deleted file mode 100644 index 736b93c..0000000 --- a/src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTest.form +++ /dev/null @@ -1,203 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTest.java b/src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTest.java deleted file mode 100644 index ae8c664..0000000 --- a/src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTest.java +++ /dev/null @@ -1,401 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any - * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND - * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY - * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL - * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF - * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR - * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, - * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND - * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR - * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed, licensed or - * intended for use in the design, construction, operation or - * maintenance of any nuclear facility. - * - * $Revision$ - * $Date$ - * $State$ - */ -package org.jdesktop.j3d.examples.glsl_shader; - -import com.sun.j3d.utils.universe.*; -import com.sun.j3d.utils.shader.StringIO; -import javax.media.j3d.*; -import java.awt.GraphicsConfiguration; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.FloatBuffer; -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.vecmath.Color3f; -import javax.vecmath.Point3d; -import org.jdesktop.j3d.examples.Resources; - -public class VertexAttrTest extends javax.swing.JFrame { - - SimpleUniverse universe = null; - BranchGroup scene = null; - boolean attached = false; - - public BranchGroup createSceneGraph( boolean hasVertexAttrs ) { - - // Bounds for BG and behavior - BoundingSphere bounds = - new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); - - // Create the root of the branch graph - BranchGroup objRoot = new BranchGroup(); - objRoot.setCapability(BranchGroup.ALLOW_DETACH); - - // Set up the background - Color3f bgColor = new Color3f(0.1f, 0.1f, 0.1f); - Background bg = new Background(bgColor); - bg.setApplicationBounds(bounds); - objRoot.addChild(bg); - - // Create the TransformGroup node and initialize it to the - // identity. Enable the TRANSFORM_WRITE capability so that - // our behavior code can modify it at run time. Add it to - // the root of the subgraph. - TransformGroup objTrans = new TransformGroup(); - objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); - objRoot.addChild(objTrans); - - // Create a simple Shape3D node; add it to the scene graph. - objTrans.addChild(new MyShape(this, hasVertexAttrs)); - - return objRoot; - } - - private Canvas3D initScene() { - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - universe = new SimpleUniverse(c); - - ViewingPlatform viewingPlatform = universe.getViewingPlatform(); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - viewingPlatform.setNominalViewingTransform(); - - return c; - } - - /** - * Creates new form VertexAttrTest - */ - public VertexAttrTest() { - // Initialize the GUI components - initComponents(); - - // Create the scene and add the Canvas3D to the drawing panel - Canvas3D c = initScene(); - drawingPanel.add(c, java.awt.BorderLayout.CENTER); - } - - static class MyShape extends Shape3D { - private static String vertexProgName = "glsl_shader/vertexshader.vert"; - - // Coordinate data - private static final float[] coords = { - 0.0f, 0.0f, 0.0f, - 0.5f, 0.0f, 0.0f, - 0.0f, 0.5f, 0.0f, - }; - - private static final int[] sizes = { 1, 3 }; - private static final float[] weights = { - 0.45f, - 0.15f, - 0.95f, - }; - private static final float[] temps = { - 1.0f, 0.5f, 0.5f, - 0.5f, 1.0f, 0.5f, - 0.5f, 0.5f, 1.0f, - }; - - private static final String[] vaNames = { "weight", "temperature" }; - - J3DBuffer createDirectFloatBuffer(float[] arr) { - ByteOrder order = ByteOrder.nativeOrder(); - - FloatBuffer nioBuf = ByteBuffer.allocateDirect(arr.length * 4).order(order).asFloatBuffer(); - nioBuf.put(arr); - return new J3DBuffer(nioBuf); - } - - - MyShape(JFrame frame, boolean hasVertexAttrs) { - - int vertexFormat = GeometryArray.COORDINATES; - int vertexAttrCount = 0; - int[] vertexAttrSizes = null; - String[] vertexAttrNames = null; - String[] shaderAttrNames = null; - - if (hasVertexAttrs) { - vertexFormat |= GeometryArray.VERTEX_ATTRIBUTES; - vertexAttrCount = vaNames.length; - vertexAttrSizes = sizes; - vertexAttrNames = vaNames; - } - - TriangleArray tri = new TriangleArray(6, vertexFormat, 0, null, vertexAttrCount, vertexAttrSizes); - tri.setValidVertexCount(3); - tri.setCoordinates(0, coords); - - if (hasVertexAttrs) { - tri.setVertexAttrs(0, 0, weights); - tri.setVertexAttrs(1, 0, temps); - - String vertexProgram = null; - try { - vertexProgram = StringIO.readFully(Resources.getResource(vertexProgName)); - } catch (IOException e) { - throw new RuntimeException(e); - } - - Shader[] shaders = new Shader[1]; - shaders[0] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, - Shader.SHADER_TYPE_VERTEX, - vertexProgram); - - ShaderProgram shaderProgram = new GLSLShaderProgram(); - shaderProgram.setShaders(shaders); - shaderProgram.setVertexAttrNames(vertexAttrNames); - shaderProgram.setShaderAttrNames(shaderAttrNames); - - ShaderAppearance app = new ShaderAppearance(); - app.setShaderProgram(shaderProgram); - - this.setGeometry(tri); - - this.setAppearance(app); - } else { - this.setGeometry(tri); - this.setAppearance(new Appearance()); - } - } - } - - // ---------------------------------------------------------------- - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { - java.awt.GridBagConstraints gridBagConstraints; - - mainPanel = new javax.swing.JPanel(); - guiPanel = new javax.swing.JPanel(); - vertexCheckBoxPanel = new javax.swing.JPanel(); - jPanel1 = new javax.swing.JPanel(); - jSeparator1 = new javax.swing.JSeparator(); - jSeparator2 = new javax.swing.JSeparator(); - jPanel2 = new javax.swing.JPanel(); - vertexAttrsBox = new javax.swing.JCheckBox(); - geometryPanel = new javax.swing.JPanel(); - createButton = new javax.swing.JButton(); - destroyButton = new javax.swing.JButton(); - drawingPanel = new javax.swing.JPanel(); - jMenuBar1 = new javax.swing.JMenuBar(); - fileMenu = new javax.swing.JMenu(); - exitMenuItem = new javax.swing.JMenuItem(); - - setTitle("Vertex Attribute Test"); - addWindowListener(new java.awt.event.WindowAdapter() { - public void windowClosing(java.awt.event.WindowEvent evt) { - exitForm(evt); - } - }); - - mainPanel.setLayout(new java.awt.BorderLayout()); - - guiPanel.setLayout(new java.awt.GridBagLayout()); - - guiPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); - vertexCheckBoxPanel.setLayout(new java.awt.GridBagLayout()); - - vertexCheckBoxPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "vertexFormat", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Sans", 0, 10))); - jPanel1.setLayout(new java.awt.GridBagLayout()); - - jSeparator1.setPreferredSize(new java.awt.Dimension(0, 4)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 1; - jPanel1.add(jSeparator1, gridBagConstraints); - - jSeparator2.setPreferredSize(new java.awt.Dimension(0, 4)); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 3; - jPanel1.add(jSeparator2, gridBagConstraints); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; - vertexCheckBoxPanel.add(jPanel1, gridBagConstraints); - - jPanel2.setLayout(new java.awt.GridBagLayout()); - - vertexAttrsBox.setSelected(true); - vertexAttrsBox.setText("VertexAttrs"); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 4; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - jPanel2.add(vertexAttrsBox, gridBagConstraints); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; - vertexCheckBoxPanel.add(jPanel2, gridBagConstraints); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridy = 0; - gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); - guiPanel.add(vertexCheckBoxPanel, gridBagConstraints); - - geometryPanel.setLayout(new java.awt.GridBagLayout()); - - createButton.setText("Create Geometry"); - createButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - createButtonActionPerformed(evt); - } - }); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - geometryPanel.add(createButton, gridBagConstraints); - - destroyButton.setText("Destroy Geometry"); - destroyButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - destroyButtonActionPerformed(evt); - } - }); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0); - geometryPanel.add(destroyButton, gridBagConstraints); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridy = 0; - gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); - guiPanel.add(geometryPanel, gridBagConstraints); - - mainPanel.add(guiPanel, java.awt.BorderLayout.NORTH); - - drawingPanel.setLayout(new java.awt.BorderLayout()); - - drawingPanel.setPreferredSize(new java.awt.Dimension(500, 500)); - mainPanel.add(drawingPanel, java.awt.BorderLayout.CENTER); - - getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER); - - fileMenu.setText("File"); - exitMenuItem.setText("Exit"); - exitMenuItem.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - exitMenuItemActionPerformed(evt); - } - }); - - fileMenu.add(exitMenuItem); - - jMenuBar1.add(fileMenu); - - setJMenuBar(jMenuBar1); - - pack(); - }// //GEN-END:initComponents - - private void destroyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_destroyButtonActionPerformed - if (scene != null) { - universe.getLocale().removeBranchGraph(scene); - attached = false; - scene = null; - } - }//GEN-LAST:event_destroyButtonActionPerformed - - private void createButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createButtonActionPerformed - if (scene == null) { - boolean hasVertexAttrs = vertexAttrsBox.isSelected(); - scene = createSceneGraph(hasVertexAttrs); - universe.addBranchGraph(scene); - attached = true; - System.err.println("Scene created"); - } - }//GEN-LAST:event_createButtonActionPerformed - - private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed - System.exit(0); - }//GEN-LAST:event_exitMenuItemActionPerformed - - /** Exit the Application */ - private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm - System.exit(0); - }//GEN-LAST:event_exitForm - - /** - * @param args the command line arguments - */ - public static void main(String args[]) { - java.awt.EventQueue.invokeLater(new Runnable() { - public void run() { - new VertexAttrTest().setVisible(true); - } - }); - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton createButton; - private javax.swing.JButton destroyButton; - private javax.swing.JPanel drawingPanel; - private javax.swing.JMenuItem exitMenuItem; - private javax.swing.JMenu fileMenu; - private javax.swing.JPanel geometryPanel; - private javax.swing.JPanel guiPanel; - private javax.swing.JMenuBar jMenuBar1; - private javax.swing.JPanel jPanel1; - private javax.swing.JPanel jPanel2; - private javax.swing.JSeparator jSeparator1; - private javax.swing.JSeparator jSeparator2; - private javax.swing.JPanel mainPanel; - private javax.swing.JCheckBox vertexAttrsBox; - private javax.swing.JPanel vertexCheckBoxPanel; - // End of variables declaration//GEN-END:variables - -} diff --git a/src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTestGLSL.form b/src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTestGLSL.form new file mode 100644 index 0000000..6e31a8f --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTestGLSL.form @@ -0,0 +1,203 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTestGLSL.java b/src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTestGLSL.java new file mode 100644 index 0000000..7fb7484 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/VertexAttrTestGLSL.java @@ -0,0 +1,397 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ +package org.jdesktop.j3d.examples.glsl_shader; + +import com.sun.j3d.utils.universe.*; +import com.sun.j3d.utils.shader.StringIO; +import javax.media.j3d.*; +import java.awt.GraphicsConfiguration; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.vecmath.Color3f; +import javax.vecmath.Point3d; +import org.jdesktop.j3d.examples.Resources; + +public class VertexAttrTestGLSL extends javax.swing.JFrame { + + SimpleUniverse universe = null; + BranchGroup scene = null; + + public BranchGroup createSceneGraph( boolean hasVertexAttrs ) { + + // Bounds for BG and behavior + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + + // Create the root of the branch graph + BranchGroup objRoot = new BranchGroup(); + objRoot.setCapability(BranchGroup.ALLOW_DETACH); + + // Set up the background + Color3f bgColor = new Color3f(0.1f, 0.1f, 0.1f); + Background bg = new Background(bgColor); + bg.setApplicationBounds(bounds); + objRoot.addChild(bg); + + // Create the TransformGroup node and initialize it to the + // identity. Enable the TRANSFORM_WRITE capability so that + // our behavior code can modify it at run time. Add it to + // the root of the subgraph. + TransformGroup objTrans = new TransformGroup(); + objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + objRoot.addChild(objTrans); + + // Create a simple Shape3D node; add it to the scene graph. + objTrans.addChild(new MyShape(this, hasVertexAttrs)); + + return objRoot; + } + + private Canvas3D initScene() { + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + + Canvas3D c = new Canvas3D(config); + universe = new SimpleUniverse(c); + + ViewingPlatform viewingPlatform = universe.getViewingPlatform(); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + viewingPlatform.setNominalViewingTransform(); + + return c; + } + + /** + * Creates new form VertexAttrTestGLSL + */ + public VertexAttrTestGLSL() { + // Initialize the GUI components + initComponents(); + + // Create the scene and add the Canvas3D to the drawing panel + Canvas3D c = initScene(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + } + + static class MyShape extends Shape3D { + private static String vertexProgName = "glsl_shader/vertexshader.vert"; + + // Coordinate data + private static final float[] coords = { + 0.0f, 0.0f, 0.0f, + 0.5f, 0.0f, 0.0f, + 0.0f, 0.5f, 0.0f, + }; + + private static final int[] sizes = { 1, 3 }; + private static final float[] weights = { + 0.45f, + 0.15f, + 0.95f, + }; + private static final float[] temps = { + 1.0f, 0.5f, 0.5f, + 0.5f, 1.0f, 0.5f, + 0.5f, 0.5f, 1.0f, + }; + + private static final String[] vaNames = { "weight", "temperature" }; + + J3DBuffer createDirectFloatBuffer(float[] arr) { + ByteOrder order = ByteOrder.nativeOrder(); + + FloatBuffer nioBuf = ByteBuffer.allocateDirect(arr.length * 4).order(order).asFloatBuffer(); + nioBuf.put(arr); + return new J3DBuffer(nioBuf); + } + + + MyShape(JFrame frame, boolean hasVertexAttrs) { + + int vertexFormat = GeometryArray.COORDINATES; + int vertexAttrCount = 0; + int[] vertexAttrSizes = null; + String[] vertexAttrNames = null; + String[] shaderAttrNames = null; + + if (hasVertexAttrs) { + vertexFormat |= GeometryArray.VERTEX_ATTRIBUTES; + vertexAttrCount = vaNames.length; + vertexAttrSizes = sizes; + vertexAttrNames = vaNames; + } + + TriangleArray tri = new TriangleArray(6, vertexFormat, 0, null, vertexAttrCount, vertexAttrSizes); + tri.setValidVertexCount(3); + tri.setCoordinates(0, coords); + + if (hasVertexAttrs) { + tri.setVertexAttrs(0, 0, weights); + tri.setVertexAttrs(1, 0, temps); + + String vertexProgram = null; + try { + vertexProgram = StringIO.readFully(Resources.getResource(vertexProgName)); + } catch (IOException e) { + throw new RuntimeException(e); + } + + Shader[] shaders = new Shader[1]; + shaders[0] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, + Shader.SHADER_TYPE_VERTEX, + vertexProgram); + + ShaderProgram shaderProgram = new GLSLShaderProgram(); + shaderProgram.setShaders(shaders); + shaderProgram.setVertexAttrNames(vertexAttrNames); + shaderProgram.setShaderAttrNames(shaderAttrNames); + + ShaderAppearance app = new ShaderAppearance(); + app.setShaderProgram(shaderProgram); + + this.setGeometry(tri); + + this.setAppearance(app); + } else { + this.setGeometry(tri); + this.setAppearance(new Appearance()); + } + } + } + + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + mainPanel = new javax.swing.JPanel(); + guiPanel = new javax.swing.JPanel(); + vertexCheckBoxPanel = new javax.swing.JPanel(); + jPanel1 = new javax.swing.JPanel(); + jSeparator1 = new javax.swing.JSeparator(); + jSeparator2 = new javax.swing.JSeparator(); + jPanel2 = new javax.swing.JPanel(); + vertexAttrsBox = new javax.swing.JCheckBox(); + geometryPanel = new javax.swing.JPanel(); + createButton = new javax.swing.JButton(); + destroyButton = new javax.swing.JButton(); + drawingPanel = new javax.swing.JPanel(); + jMenuBar1 = new javax.swing.JMenuBar(); + fileMenu = new javax.swing.JMenu(); + exitMenuItem = new javax.swing.JMenuItem(); + + setTitle("VertexAttrTestGLSL"); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent evt) { + exitForm(evt); + } + }); + + mainPanel.setLayout(new java.awt.BorderLayout()); + + guiPanel.setLayout(new java.awt.GridBagLayout()); + + guiPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); + vertexCheckBoxPanel.setLayout(new java.awt.GridBagLayout()); + + vertexCheckBoxPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "vertexFormat", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Sans", 0, 10))); + jPanel1.setLayout(new java.awt.GridBagLayout()); + + jSeparator1.setPreferredSize(new java.awt.Dimension(0, 4)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + jPanel1.add(jSeparator1, gridBagConstraints); + + jSeparator2.setPreferredSize(new java.awt.Dimension(0, 4)); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 3; + jPanel1.add(jSeparator2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; + vertexCheckBoxPanel.add(jPanel1, gridBagConstraints); + + jPanel2.setLayout(new java.awt.GridBagLayout()); + + vertexAttrsBox.setSelected(true); + vertexAttrsBox.setText("VertexAttrs"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 4; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + jPanel2.add(vertexAttrsBox, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; + vertexCheckBoxPanel.add(jPanel2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); + guiPanel.add(vertexCheckBoxPanel, gridBagConstraints); + + geometryPanel.setLayout(new java.awt.GridBagLayout()); + + createButton.setText("Create Geometry"); + createButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + createButtonActionPerformed(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + geometryPanel.add(createButton, gridBagConstraints); + + destroyButton.setText("Destroy Geometry"); + destroyButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + destroyButtonActionPerformed(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0); + geometryPanel.add(destroyButton, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridy = 0; + gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); + guiPanel.add(geometryPanel, gridBagConstraints); + + mainPanel.add(guiPanel, java.awt.BorderLayout.NORTH); + + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(500, 500)); + mainPanel.add(drawingPanel, java.awt.BorderLayout.CENTER); + + getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER); + + fileMenu.setText("File"); + exitMenuItem.setText("Exit"); + exitMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + exitMenuItemActionPerformed(evt); + } + }); + + fileMenu.add(exitMenuItem); + + jMenuBar1.add(fileMenu); + + setJMenuBar(jMenuBar1); + + pack(); + }// //GEN-END:initComponents + + private void destroyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_destroyButtonActionPerformed + if (scene != null) { + universe.getLocale().removeBranchGraph(scene); + scene = null; + } + }//GEN-LAST:event_destroyButtonActionPerformed + + private void createButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createButtonActionPerformed + if (scene == null) { + boolean hasVertexAttrs = vertexAttrsBox.isSelected(); + scene = createSceneGraph(hasVertexAttrs); + universe.addBranchGraph(scene); + } + }//GEN-LAST:event_createButtonActionPerformed + + private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed + System.exit(0); + }//GEN-LAST:event_exitMenuItemActionPerformed + + /** Exit the Application */ + private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm + System.exit(0); + }//GEN-LAST:event_exitForm + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new VertexAttrTestGLSL().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton createButton; + private javax.swing.JButton destroyButton; + private javax.swing.JPanel drawingPanel; + private javax.swing.JMenuItem exitMenuItem; + private javax.swing.JMenu fileMenu; + private javax.swing.JPanel geometryPanel; + private javax.swing.JPanel guiPanel; + private javax.swing.JMenuBar jMenuBar1; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel2; + private javax.swing.JSeparator jSeparator1; + private javax.swing.JSeparator jSeparator2; + private javax.swing.JPanel mainPanel; + private javax.swing.JCheckBox vertexAttrsBox; + private javax.swing.JPanel vertexCheckBoxPanel; + // End of variables declaration//GEN-END:variables + +} diff --git a/src/classes/org/jdesktop/j3d/examples/lod/LOD.form b/src/classes/org/jdesktop/j3d/examples/lod/LOD.form new file mode 100644 index 0000000..7bba785 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/lod/LOD.form @@ -0,0 +1,36 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/classes/org/jdesktop/j3d/examples/lod/LOD.java b/src/classes/org/jdesktop/j3d/examples/lod/LOD.java index 45381f4..0d50284 100644 --- a/src/classes/org/jdesktop/j3d/examples/lod/LOD.java +++ b/src/classes/org/jdesktop/j3d/examples/lod/LOD.java @@ -44,20 +44,21 @@ package org.jdesktop.j3d.examples.lod; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.behaviors.vp.*; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; -public class LOD extends Applet { +/** + * Simple Java 3D example program to display a spinning cube. + */ +public class LOD extends javax.swing.JFrame { + + private SimpleUniverse univ = null; + private BranchGroup scene = null; - private SimpleUniverse u = null; - public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); @@ -129,24 +130,19 @@ public class LOD extends Applet { graphRoot.addChild(lgt1); } + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public LOD() { - } - - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - // only add zoom mouse behavior to viewingPlatform - ViewingPlatform viewingPlatform = u.getViewingPlatform(); + // only add zoom mouse behavior to viewingPlatform + ViewingPlatform viewingPlatform = univ.getViewingPlatform(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. @@ -161,21 +157,68 @@ public class LOD extends Applet { BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); orbit.setSchedulingBounds(bounds); - viewingPlatform.setViewPlatformBehavior(orbit); + viewingPlatform.setViewPlatformBehavior(orbit); + + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return c; } - public void destroy() { - u.cleanup(); + /** + * Creates new form LOD + */ + public LOD() { + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } - // - // The following allows LOD to be run as an application - // as well as an applet - // - public static void main(String[] args) { - new MainFrame(new LOD(), 512, 512); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("LOD"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new LOD().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.form b/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.form new file mode 100644 index 0000000..631f59a --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.form @@ -0,0 +1,36 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.java b/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.java index 5366738..612c5df 100644 --- a/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.java +++ b/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.java @@ -44,12 +44,10 @@ package org.jdesktop.j3d.examples.morphing; -import java.applet.Applet; -import java.awt.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; import java.io.*; import com.sun.j3d.loaders.objectfile.ObjectFile; import com.sun.j3d.loaders.Scene; @@ -57,12 +55,12 @@ import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.IncorrectFormatException; import org.jdesktop.j3d.examples.Resources; -public class Morphing extends Applet { +public class Morphing extends javax.swing.JFrame { + private SimpleUniverse univ = null; + private BranchGroup scene = null; private java.net.URL[] objFiles = null; - private SimpleUniverse u = null; - private BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); @@ -201,80 +199,89 @@ public class Morphing extends Applet { return objRoot; } - public Morphing() {} - public Morphing(java.net.URL[] urls) { - objFiles = urls; - } + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public void init() { - if (objFiles == null) { - objFiles = new java.net.URL[3]; - for(int i=0; i<3; i++) { - objFiles[i] = Resources.getResource("resources/geometry/hand" + (i+1) + ".obj"); - if (objFiles[i] == null) { - System.err.println("resources/geometry/hand" + (i+1) + ".obj not found"); - System.exit(1); - } - } - /* - // the path to the image for an applet - String path = getCodeBase().toString(); - try { - objFiles[0] = new java.net.URL(path + "hand1.obj"); - objFiles[1] = new java.net.URL(path + "hand2.obj"); - objFiles[2] = new java.net.URL(path + "hand3.obj"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - */ - } + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); - - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + univ.getViewingPlatform().setNominalViewingTransform(); + + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return c; } - public void destroy() { - u.cleanup(); + /** + * Creates new form LOD + */ + public Morphing(String args[]) { + + objFiles = new java.net.URL[3]; + for(int i=0; i<3; i++) { + objFiles[i] = Resources.getResource("resources/geometry/hand" + (i+1) + ".obj"); + if (objFiles[i] == null) { + System.err.println("resources/geometry/hand" + (i+1) + ".obj not found"); + System.exit(1); + } + } + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } - public static void main(String[] args) { - java.net.URL[] urls = new java.net.URL[3]; - // the path to the image file for an application - for(int i=0; i<3; i++) { - urls[i] = Resources.getResource("resources/geometry/hand" + (i+1) + ".obj"); - if (urls[i] == null) { - System.err.println("resources/geometry/hand" + (i+1) + ".obj not found"); - System.exit(1); - } + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("Morphing"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + Morphing morphing = new Morphing(args); + morphing.setVisible(true); } - /* - try { - urls[0] = new java.net.URL("file:./hand1.obj"); - urls[1] = new java.net.URL("file:./hand2.obj"); - urls[2] = new java.net.URL("file:./hand3.obj"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - **/ - new MainFrame(new Morphing(urls), 700, 700); + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/morphing/Pyramid2Cube.form b/src/classes/org/jdesktop/j3d/examples/morphing/Pyramid2Cube.form new file mode 100644 index 0000000..0c0b7e2 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/morphing/Pyramid2Cube.form @@ -0,0 +1,36 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/classes/org/jdesktop/j3d/examples/morphing/Pyramid2Cube.java b/src/classes/org/jdesktop/j3d/examples/morphing/Pyramid2Cube.java index e4d86ee..d8a6612 100644 --- a/src/classes/org/jdesktop/j3d/examples/morphing/Pyramid2Cube.java +++ b/src/classes/org/jdesktop/j3d/examples/morphing/Pyramid2Cube.java @@ -44,17 +44,15 @@ package org.jdesktop.j3d.examples.morphing; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; -public class Pyramid2Cube extends Applet { +public class Pyramid2Cube extends javax.swing.JFrame { - private SimpleUniverse u = null; + private SimpleUniverse univ = null; + private BranchGroup scene = null; private BranchGroup createSceneGraph() { // Create the root of the branch graph @@ -161,34 +159,78 @@ public class Pyramid2Cube extends Applet { return objRoot; } + + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public Pyramid2Cube() { - } - - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + univ.getViewingPlatform().setNominalViewingTransform(); - u.addBranchGraph(scene); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); + + return c; } - public void destroy() { - u.cleanup(); + /** + * Creates new form Pyramid2Cube + */ + public Pyramid2Cube() { + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } - public static void main(String[] args) { - new MainFrame(new Pyramid2Cube(), 700, 700); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("Pyramid2Cube"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new Pyramid2Cube().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } -- cgit v1.2.3