summaryrefslogtreecommitdiffstats
path: root/src/classes/org
diff options
context:
space:
mode:
authorphil <[email protected]>2016-11-04 23:04:11 +1300
committerphil <[email protected]>2016-11-04 23:04:11 +1300
commit7a8ff3f043c5140e0f40a4df72fc27085b8e8b71 (patch)
tree9f420f033a8160a82089ef4c60c6c953d2c133f6 /src/classes/org
parent3a573d43a87978741d03d7aecc2bf638a43d77c3 (diff)
Added a lot more GL2ES2 examples
And converted to struct based lights and material in shaders
Diffstat (limited to 'src/classes/org')
-rw-r--r--src/classes/org/jdesktop/j3d/examples/alternate_appearance/AlternateAppearanceBoundsTestGL2ES2.java314
-rw-r--r--src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixedGL2ES2.java530
-rw-r--r--src/classes/org/jdesktop/j3d/examples/background/BackgroundGeometryGL2ES2.java263
-rw-r--r--src/classes/org/jdesktop/j3d/examples/collision/TickTockCollisionGL2ES2.java254
-rw-r--r--src/classes/org/jdesktop/j3d/examples/depth_func/DepthFuncTestGL2ES2.java347
-rw-r--r--src/classes/org/jdesktop/j3d/examples/depth_func/RenderFrameGL2ES2.java294
-rw-r--r--src/classes/org/jdesktop/j3d/examples/distort_glyph/DistortGlyphTestGL2ES2.java324
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/Cube.java311
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/EnvironmentMappingGLSL.java60
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ObjLoadGLSL.java58
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/PhongShadingGLSL.java67
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SamplerTestGLSL.java54
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ShaderTestGLSL.java82
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java415
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SphereGLSL.java95
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/VertexAttrTestGLSL.java62
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/dimple.vert3
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag30
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert67
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert55
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag50
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.vert14
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert50
-rw-r--r--src/classes/org/jdesktop/j3d/examples/hello_universe/HelloUniverseGL2ES2.java161
-rw-r--r--src/classes/org/jdesktop/j3d/examples/jcanvas3d/JCanvas3DExampleGL2ES2.java175
-rw-r--r--src/classes/org/jdesktop/j3d/examples/jcanvas3d/JInternalWorldGL2ES2.java211
-rw-r--r--src/classes/org/jdesktop/j3d/examples/sphere_motion/SphereMotionGL2ES2.java363
-rw-r--r--src/classes/org/jdesktop/j3d/examples/sphere_motion/SphereMotionGL2ES3_Texture.java376
-rw-r--r--src/classes/org/jdesktop/j3d/examples/sphere_motion/SphereMotionGLSL_FFP.java361
-rw-r--r--src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_ffp.frag66
-rw-r--r--src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_ffp.vert19
-rw-r--r--src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.frag96
-rw-r--r--src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.vert31
-rw-r--r--src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.frag105
-rw-r--r--src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.vert35
35 files changed, 5285 insertions, 513 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/alternate_appearance/AlternateAppearanceBoundsTestGL2ES2.java b/src/classes/org/jdesktop/j3d/examples/alternate_appearance/AlternateAppearanceBoundsTestGL2ES2.java
new file mode 100644
index 0000000..c24b79a
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/alternate_appearance/AlternateAppearanceBoundsTestGL2ES2.java
@@ -0,0 +1,314 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+package org.jdesktop.j3d.examples.alternate_appearance;
+
+import java.awt.Container;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.BoxLayout;
+import javax.swing.JApplet;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.border.TitledBorder;
+
+import org.jdesktop.j3d.examples.gl2es2pipeline.SimpleShaderAppearance;
+import org.jogamp.java3d.AlternateAppearance;
+import org.jogamp.java3d.AmbientLight;
+import org.jogamp.java3d.Appearance;
+import org.jogamp.java3d.BoundingLeaf;
+import org.jogamp.java3d.BoundingSphere;
+import org.jogamp.java3d.Bounds;
+import org.jogamp.java3d.BranchGroup;
+import org.jogamp.java3d.Canvas3D;
+import org.jogamp.java3d.DirectionalLight;
+import org.jogamp.java3d.Group;
+import org.jogamp.java3d.Material;
+import org.jogamp.java3d.Shape3D;
+import org.jogamp.java3d.utils.applet.MainFrame;
+import org.jogamp.java3d.utils.universe.SimpleUniverse;
+import org.jogamp.vecmath.Color3f;
+import org.jogamp.vecmath.Point3d;
+import org.jogamp.vecmath.Vector3f;
+
+public class AlternateAppearanceBoundsTestGL2ES2 extends JApplet implements ActionListener
+{
+
+ Material mat1, altMat;
+ Appearance app, otherApp;
+ JComboBox<?> altAppMaterialColor;
+ JComboBox<?> appMaterialColor;
+ JCheckBox useBoundingLeaf;
+ JCheckBox override;
+ JComboBox<?> boundsType;
+ private Group content1 = null;
+ AlternateAppearance altApp;
+ Shape3D[] shapes1;
+ boolean boundingLeafOn = false;
+ // Globally used colors
+ Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
+ Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
+ Color3f green = new Color3f(0.0f, 1.0f, 0.0f);
+ Color3f blue = new Color3f(0.0f, 0.0f, 1.0f);
+ Color3f[] colors = { white, red, green, blue };
+
+ private Bounds worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
+ 1000.0); // Extent
+ private Bounds smallBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
+ 0.25); // Extent
+ private Bounds tinyBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
+ 0.05); // Extent
+ private BoundingLeaf leafBounds = null;
+ private int currentBounds = 2;
+
+ private Bounds[] allBounds = { tinyBounds, smallBounds, worldBounds };
+
+ DirectionalLight light1 = null;
+
+ // Get the current bounding leaf position
+ //private int currentPosition = 0;
+ // Point3f pos = (Point3f)positions[currentPosition].value;
+
+ private SimpleUniverse u = null;
+
+ public AlternateAppearanceBoundsTestGL2ES2()
+ {
+ }
+
+ @Override
+ public void init()
+ {
+ System.setProperty("sun.awt.noerasebackground", "true");
+ Container contentPane = getContentPane();
+
+ Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
+ contentPane.add("Center", c);
+
+ BranchGroup scene = createSceneGraph();
+ // SimpleUniverse is a Convenience Utility class
+ u = new SimpleUniverse(c);
+
+ // This will move the ViewPlatform back a bit so the
+ // objects in the scene can be viewed.
+ u.getViewingPlatform().setNominalViewingTransform();
+ u.addBranchGraph(scene);
+
+ // Create GUI
+ JPanel p = new JPanel();
+ BoxLayout boxlayout = new BoxLayout(p, BoxLayout.Y_AXIS);
+ p.add(createBoundsPanel());
+ p.add(createMaterialPanel());
+ p.setLayout(boxlayout);
+
+ contentPane.add("South", p);
+ }
+
+ @Override
+ public void destroy()
+ {
+ u.cleanup();
+ }
+
+ BranchGroup createSceneGraph()
+ {
+ BranchGroup objRoot = new BranchGroup();
+
+ // Create an alternate appearance
+ otherApp = new SimpleShaderAppearance(true, false);
+ //otherApp = new Appearance();
+ altMat = new Material();
+ altMat.setCapability(Material.ALLOW_COMPONENT_WRITE);
+ altMat.setDiffuseColor(new Color3f(0.0f, 1.0f, 0.0f));
+ otherApp.setMaterial(altMat);
+
+ altApp = new AlternateAppearance();
+ altApp.setAppearance(otherApp);
+ altApp.setCapability(AlternateAppearance.ALLOW_BOUNDS_WRITE);
+ altApp.setCapability(AlternateAppearance.ALLOW_INFLUENCING_BOUNDS_WRITE);
+ altApp.setInfluencingBounds(worldBounds);
+ objRoot.addChild(altApp);
+
+ // Build foreground geometry
+ Appearance app1 = new SimpleShaderAppearance(true, false);
+ //Appearance app1 = new Appearance();
+ mat1 = new Material();
+ mat1.setCapability(Material.ALLOW_COMPONENT_WRITE);
+ mat1.setDiffuseColor(new Color3f(1.0f, 0.0f, 0.0f));
+ app1.setMaterial(mat1);
+ content1 = new SphereGroup(0.05f, // radius of spheres
+ 0.15f, // x spacing
+ 0.15f, // y spacing
+ 5, // number of spheres in X
+ 5, // number of spheres in Y
+ app1, // appearance
+ true); // alt app override = true
+ objRoot.addChild(content1);
+ shapes1 = ((SphereGroup) content1).getShapes();
+
+ // Add lights
+ light1 = new DirectionalLight();
+ light1.setEnable(true);
+ light1.setColor(new Color3f(0.2f, 0.2f, 0.2f));
+ light1.setDirection(new Vector3f(1.0f, 0.0f, -1.0f));
+ light1.setInfluencingBounds(worldBounds);
+ light1.setCapability(DirectionalLight.ALLOW_INFLUENCING_BOUNDS_WRITE);
+ light1.setCapability(DirectionalLight.ALLOW_BOUNDS_WRITE);
+ objRoot.addChild(light1);
+
+ // Add an ambient light to dimly illuminate the rest of
+ // the shapes in the scene to help illustrate that the
+ // directional lights are being scoped... otherwise it looks
+ // like we're just removing shapes from the scene
+ AmbientLight ambient = new AmbientLight();
+ ambient.setEnable(true);
+ ambient.setColor(new Color3f(1.0f, 1.0f, 1.0f));
+ ambient.setInfluencingBounds(worldBounds);
+ objRoot.addChild(ambient);
+
+ // Define a bounding leaf
+ leafBounds = new BoundingLeaf(allBounds[currentBounds]);
+ leafBounds.setCapability(BoundingLeaf.ALLOW_REGION_WRITE);
+ objRoot.addChild(leafBounds);
+ if (boundingLeafOn)
+ {
+ altApp.setInfluencingBoundingLeaf(leafBounds);
+ }
+ else
+ {
+ altApp.setInfluencingBounds(allBounds[currentBounds]);
+ }
+
+ return objRoot;
+ }
+
+ JPanel createBoundsPanel()
+ {
+ JPanel panel = new JPanel();
+ panel.setBorder(new TitledBorder("Scopes"));
+
+ String boundsValues[] = { "Tiny Bounds", "Small Bounds", "Big Bounds" };
+
+ boundsType = new JComboBox<Object>(boundsValues);
+ boundsType.addActionListener(this);
+ boundsType.setSelectedIndex(2);
+ panel.add(new JLabel("Bounds"));
+ panel.add(boundsType);
+
+ useBoundingLeaf = new JCheckBox("Enable BoundingLeaf", boundingLeafOn);
+ useBoundingLeaf.addActionListener(this);
+ panel.add(useBoundingLeaf);
+
+ override = new JCheckBox("Enable App Override", false);
+ override.addActionListener(this);
+ panel.add(override);
+
+ return panel;
+
+ }
+
+ JPanel createMaterialPanel()
+ {
+ JPanel panel = new JPanel();
+ panel.setBorder(new TitledBorder("Appearance Attributes"));
+
+ String colorVals[] = { "WHITE", "RED", "GREEN", "BLUE" };
+
+ altAppMaterialColor = new JComboBox<Object>(colorVals);
+ altAppMaterialColor.addActionListener(this);
+ altAppMaterialColor.setSelectedIndex(2);
+ panel.add(new JLabel("Alternate Appearance MaterialColor"));
+ panel.add(altAppMaterialColor);
+
+ appMaterialColor = new JComboBox<Object>(colorVals);
+ appMaterialColor.addActionListener(this);
+ appMaterialColor.setSelectedIndex(1);
+ panel.add(new JLabel("Normal Appearance MaterialColor"));
+ panel.add(appMaterialColor);
+
+ return panel;
+
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ int i;
+
+ Object target = e.getSource();
+ if (target == altAppMaterialColor)
+ {
+ altMat.setDiffuseColor(colors[altAppMaterialColor.getSelectedIndex()]);
+ }
+ else if (target == useBoundingLeaf)
+ {
+ boundingLeafOn = useBoundingLeaf.isSelected();
+ if (boundingLeafOn)
+ {
+ leafBounds.setRegion(allBounds[currentBounds]);
+ altApp.setInfluencingBoundingLeaf(leafBounds);
+ }
+ else
+ {
+ altApp.setInfluencingBoundingLeaf(null);
+ altApp.setInfluencingBounds(allBounds[currentBounds]);
+ }
+
+ }
+ else if (target == boundsType)
+ {
+ currentBounds = boundsType.getSelectedIndex();
+ if (boundingLeafOn)
+ {
+ leafBounds.setRegion(allBounds[currentBounds]);
+ altApp.setInfluencingBoundingLeaf(leafBounds);
+ }
+ else
+ {
+ altApp.setInfluencingBoundingLeaf(null);
+ altApp.setInfluencingBounds(allBounds[currentBounds]);
+ }
+
+ }
+ else if (target == override)
+ {
+ for (i = 0; i < shapes1.length; i++)
+ shapes1[i].setAppearanceOverrideEnable(override.isSelected());
+ }
+ else if (target == appMaterialColor)
+ {
+ mat1.setDiffuseColor(colors[appMaterialColor.getSelectedIndex()]);
+ }
+
+ }
+
+ public static void main(String[] args)
+ {
+ System.setProperty("sun.awt.noerasebackground", "true");
+ System.setProperty("j3d.rend", "jogl2es2");
+ System.setProperty("j3d.displaylist", "false");
+ new MainFrame(new AlternateAppearanceBoundsTestGL2ES2(), 800, 800);
+ }
+
+}
diff --git a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixedGL2ES2.java b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixedGL2ES2.java
new file mode 100644
index 0000000..e3ec631
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixedGL2ES2.java
@@ -0,0 +1,530 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+package org.jdesktop.j3d.examples.appearance;
+
+import java.awt.GraphicsConfiguration;
+
+import org.jdesktop.j3d.examples.Resources;
+import org.jdesktop.j3d.examples.gl2es2pipeline.SimpleShaderAppearance;
+import org.jogamp.java3d.Alpha;
+import org.jogamp.java3d.AmbientLight;
+import org.jogamp.java3d.Appearance;
+import org.jogamp.java3d.Background;
+import org.jogamp.java3d.BoundingSphere;
+import org.jogamp.java3d.BranchGroup;
+import org.jogamp.java3d.Canvas3D;
+import org.jogamp.java3d.ColoringAttributes;
+import org.jogamp.java3d.DirectionalLight;
+import org.jogamp.java3d.GraphicsContext3D;
+import org.jogamp.java3d.Group;
+import org.jogamp.java3d.IndexedTriangleArray;
+import org.jogamp.java3d.Material;
+import org.jogamp.java3d.PointAttributes;
+import org.jogamp.java3d.PolygonAttributes;
+import org.jogamp.java3d.RotationInterpolator;
+import org.jogamp.java3d.Shape3D;
+import org.jogamp.java3d.TextureAttributes;
+import org.jogamp.java3d.Transform3D;
+import org.jogamp.java3d.TransformGroup;
+import org.jogamp.java3d.TransparencyAttributes;
+import org.jogamp.java3d.utils.image.TextureLoader;
+import org.jogamp.java3d.utils.universe.SimpleUniverse;
+import org.jogamp.vecmath.Color3f;
+import org.jogamp.vecmath.Point3d;
+import org.jogamp.vecmath.Point3f;
+import org.jogamp.vecmath.Vector3d;
+import org.jogamp.vecmath.Vector3f;
+
+public class AppearanceMixedGL2ES2 extends javax.swing.JFrame {
+
+ private java.net.URL texImage = null;
+ private java.net.URL bgImage = null;
+ private SimpleUniverse univ = null;
+ private BranchGroup scene = null;
+
+ static class MyCanvas3D extends Canvas3D {
+ private GraphicsContext3D gc;
+
+ private static final int vertIndices[] = { 0, 1, 2, 0, 2, 3 };
+ private static final int normalIndices[] = { 0, 0, 0, 1, 1, 1 };
+ private IndexedTriangleArray tri =
+ new IndexedTriangleArray(4, IndexedTriangleArray.COORDINATES |
+ IndexedTriangleArray.NORMALS, 6);
+
+ private Point3f vert[] = {
+ new Point3f(-0.12f, -0.12f, 0.0f),
+ new Point3f( 0.12f, -0.12f, 0.0f),
+ new Point3f( 0.12f, 0.12f, 0.0f),
+ new Point3f(-0.12f, 0.12f, 0.0f),
+ };
+
+ private Point3f min[] = {
+ new Point3f(-0.24f, -0.24f, -0.20f),
+ new Point3f( 0.04f, -0.28f, -0.24f),
+ new Point3f( 0.00f, 0.00f, -0.24f),
+ new Point3f(-0.32f, 0.08f, -0.20f),
+ };
+
+ private Point3f max[] = {
+ new Point3f(-0.04f, -0.04f, 0.12f),
+ new Point3f( 0.32f, -0.04f, 0.16f),
+ new Point3f( 0.36f, 0.28f, 0.20f),
+ new Point3f(-0.04f, 0.24f, 0.16f),
+ };
+
+ private Point3f delta[] = {
+ new Point3f(-0.0021f, -0.0017f, 0.0014f),
+ new Point3f( 0.0025f, -0.0013f, -0.0018f),
+ new Point3f( 0.0021f, 0.0017f, 0.0018f),
+ new Point3f(-0.0025f, 0.0013f, -0.0014f),
+ };
+
+ private Vector3f normals[];
+ private Vector3f v01 = new Vector3f();
+ private Vector3f v02 = new Vector3f();
+ private Vector3f v03 = new Vector3f();
+
+ public void renderField(int fieldDesc) {
+ computeVert();
+ computeNormals();
+ gc.draw(tri);
+ }
+
+ private void computeVert() {
+ for (int i = 0; i < 4; i++) {
+ vert[i].add(delta[i]);
+ if (vert[i].x > max[i].x) {
+ vert[i].x = max[i].x;
+ delta[i].x *= -1.0f;
+ }
+ if (vert[i].x < min[i].x) {
+ vert[i].x = min[i].x;
+ delta[i].x *= -1.0f;
+ }
+ if (vert[i].y > max[i].y) {
+ vert[i].y = max[i].y;
+ delta[i].y *= -1.0f;
+ }
+ if (vert[i].y < min[i].y) {
+ vert[i].y = min[i].y;
+ delta[i].y *= -1.0f;
+ }
+ if (vert[i].z > max[i].z) {
+ vert[i].z = max[i].z;
+ delta[i].z *= -1.0f;
+ }
+ if (vert[i].z < min[i].z) {
+ vert[i].z = min[i].z;
+ delta[i].z *= -1.0f;
+ }
+ }
+ tri.setCoordinates(0, vert);
+ }
+
+ private void computeNormals() {
+ v01.sub(vert[1], vert[0]);
+ v02.sub(vert[2], vert[0]);
+ v03.sub(vert[3], vert[0]);
+ normals[0].cross(v01, v02);
+ normals[0].normalize();
+ normals[1].cross(v02, v03);
+ normals[1].normalize();
+ tri.setNormals(0, normals);
+ }
+
+ public MyCanvas3D(GraphicsConfiguration gcfg) {
+ super(gcfg);
+
+ // Allocate memory for normals
+ normals = new Vector3f[2];
+ normals[0] = new Vector3f();
+ normals[1] = new Vector3f();
+
+ // Set up the indices
+ tri.setCoordinateIndices(0, vertIndices);
+ tri.setNormalIndices(0, normalIndices);
+
+ // Set up the graphics context
+ gc = getGraphicsContext3D();
+
+ // Create the appearance for the triangle fan
+ Appearance app = new SimpleShaderAppearance(true, false);
+ Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
+ Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
+ Color3f objColor = new Color3f(0.0f, 0.0f, 0.8f);
+ app.setMaterial(new Material(objColor, black, objColor,
+ white, 80.0f));
+ gc.setAppearance(app);
+
+ // Set up the global lights
+ Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
+ Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
+ Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
+ gc.addLight(new AmbientLight(alColor));
+ gc.addLight(new DirectionalLight(lColor1, lDir1));
+ }
+ }
+
+
+ private BranchGroup createSceneGraph() {
+ // Create the root of the branch graph
+ BranchGroup objRoot = new BranchGroup();
+
+ // Create a bounds for the background and lights
+ BoundingSphere bounds =
+ new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
+
+ // Set up the background
+ //TextureLoader bgTexture = new TextureLoader(bgImage, this);
+ //Background bg = new Background(bgTexture.getImage());
+ //bg.setApplicationBounds(bounds);
+ //objRoot.addChild(bg);
+
+ // Set up the global lights
+ Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
+ Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
+ Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
+
+ AmbientLight aLgt = new AmbientLight(alColor);
+ aLgt.setInfluencingBounds(bounds);
+ DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
+ lgt1.setInfluencingBounds(bounds);
+ objRoot.addChild(aLgt);
+ objRoot.addChild(lgt1);
+
+ // Create a bunch of objects with a behavior and add them
+ // into the scene graph.
+
+ int row, col;
+ Appearance[][] app = new SimpleShaderAppearance [3][3];
+
+ for (row = 0; row < 3; row++)
+ for (col = 0; col < 3; col++)
+ app[row][col] = createAppearance(row * 3 + col);
+
+ for (int i = 0; i < 3; i++) {
+ double ypos = (double)(i - 1) * 0.6;
+ for (int j = 0; j < 3; j++) {
+ double xpos = (double)(j - 1) * 0.6;
+ objRoot.addChild(createObject(app[i][j], 0.12, xpos, ypos));
+ }
+ }
+
+ // Let Java 3D perform optimizations on this scene graph.
+ objRoot.compile();
+
+ return objRoot;
+ }
+
+
+ private Appearance createAppearance(int idx) {
+ Appearance app = new SimpleShaderAppearance(true, false);;
+
+ // Globally used colors
+ Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
+ Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
+
+ switch (idx) {
+ // Unlit solid
+ case 0:
+ {
+ // Set up the coloring properties
+ Color3f objColor = new Color3f(1.0f, 0.2f, 0.4f);
+ ColoringAttributes ca = new ColoringAttributes();
+ ca.setColor(objColor);
+ app.setColoringAttributes(ca);
+ break;
+ }
+
+
+ // Unlit wire frame
+ case 1:
+ {
+ // Set up the coloring properties
+ Color3f objColor = new Color3f(0.5f, 0.0f, 0.2f);
+ ColoringAttributes ca = new ColoringAttributes();
+ ca.setColor(objColor);
+ app.setColoringAttributes(ca);
+
+ // Set up the polygon attributes
+ PolygonAttributes pa = new PolygonAttributes();
+ pa.setPolygonMode(pa.POLYGON_LINE);
+ pa.setCullFace(pa.CULL_NONE);
+ app.setPolygonAttributes(pa);
+ break;
+ }
+
+ // Unlit points
+ case 2:
+ {
+ // Set up the coloring properties
+ Color3f objColor = new Color3f(0.2f, 0.2f, 1.0f);
+ ColoringAttributes ca = new ColoringAttributes();
+ ca.setColor(objColor);
+ app.setColoringAttributes(ca);
+
+ // Set up the polygon attributes
+ PolygonAttributes pa = new PolygonAttributes();
+ pa.setPolygonMode(pa.POLYGON_POINT);
+ pa.setCullFace(pa.CULL_NONE);
+ app.setPolygonAttributes(pa);
+
+ // Set up point attributes
+ PointAttributes pta = new PointAttributes();
+ pta.setPointSize(5.0f);
+ app.setPointAttributes(pta);
+ break;
+ }
+
+ // Lit solid
+ case 3:
+ {
+ // Set up the material properties
+ Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f);
+ app.setMaterial(new Material(objColor, black, objColor,
+ white, 80.0f));
+ break;
+ }
+
+ // Texture mapped, lit solid
+ case 4:
+ {app = new SimpleShaderAppearance(true, true);;
+ // Set up the texture map
+ TextureLoader tex = new TextureLoader(texImage, this);
+ app.setTexture(tex.getTexture());
+
+ TextureAttributes texAttr = new TextureAttributes();
+ texAttr.setTextureMode(TextureAttributes.MODULATE);
+ app.setTextureAttributes(texAttr);
+
+
+ // Set up the material properties
+ app.setMaterial(new Material(white, black, white, black, 1.0f));
+ break;
+ }
+
+ // Transparent, lit solid
+ case 5:
+ {
+ // Set up the transparency properties
+ TransparencyAttributes ta = new TransparencyAttributes();
+ ta.setTransparencyMode(ta.BLENDED);
+ ta.setTransparency(0.6f);
+ app.setTransparencyAttributes(ta);
+
+ // Set up the polygon attributes
+ PolygonAttributes pa = new PolygonAttributes();
+ pa.setCullFace(pa.CULL_NONE);
+ app.setPolygonAttributes(pa);
+
+ // Set up the material properties
+ Color3f objColor = new Color3f(0.7f, 0.8f, 1.0f);
+ app.setMaterial(new Material(objColor, black, objColor,
+ black, 1.0f));
+ break;
+ }
+
+ // Lit solid, no specular
+ case 6:
+ {
+ // Set up the material properties
+ Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f);
+ app.setMaterial(new Material(objColor, black, objColor,
+ black, 80.0f));
+ break;
+ }
+
+ // Lit solid, specular only
+ case 7:
+ {
+
+ // Set up the material properties
+ Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f);
+ app.setMaterial(new Material(black, black, black,
+ white, 80.0f));
+ break;
+ }
+
+ // Another lit solid with a different color
+ case 8:
+ {
+ // Set up the material properties
+ Color3f objColor = new Color3f(0.8f, 0.8f, 0.0f);
+ app.setMaterial(new Material(objColor, black, objColor,
+ white, 80.0f));
+ break;
+ }
+
+ default:
+ {
+ ColoringAttributes ca = new ColoringAttributes();
+ ca.setColor(new Color3f(0.0f, 1.0f, 0.0f));
+ app.setColoringAttributes(ca);
+ }
+ }
+
+ return app;
+ }
+
+
+ private Group createObject(Appearance app, double scale,
+ double xpos, double ypos) {
+
+ // Create a transform group node to scale and position the object.
+ Transform3D t = new Transform3D();
+ t.set(scale, new Vector3d(xpos, ypos, 0.0));
+ TransformGroup objTrans = new TransformGroup(t);
+
+ // Create a second transform group node and initialize it to the
+ // identity. Enable the TRANSFORM_WRITE capability so that
+ // our behavior code can modify it at runtime.
+ TransformGroup spinTg = new TransformGroup();
+ spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+
+ // Create a simple shape leaf node and set the appearance
+ Shape3D shape = new Tetrahedron();
+ shape.setAppearance(app);
+
+ // add it to the scene graph.
+ spinTg.addChild(shape);
+
+ // Create a new Behavior object that will perform the desired
+ // operation on the specified transform object and add it into
+ // the scene graph.
+ Transform3D yAxis = new Transform3D();
+ Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE,
+ 0, 0,
+ 5000, 0, 0,
+ 0, 0, 0);
+
+ RotationInterpolator rotator =
+ new RotationInterpolator(rotationAlpha, spinTg, yAxis,
+ 0.0f, (float) Math.PI*2.0f);
+
+ BoundingSphere bounds =
+ new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
+
+ rotator.setSchedulingBounds(bounds);
+
+ // Add the behavior and the transform group to the object
+ objTrans.addChild(rotator);
+ objTrans.addChild(spinTg);
+
+ return objTrans;
+ }
+
+
+ private Canvas3D createUniverse() {
+ // Get the preferred graphics configuration for the default screen
+ GraphicsConfiguration config =
+ SimpleUniverse.getPreferredConfiguration();
+
+ // Create a MyCanvas3D using the preferred configuration
+ MyCanvas3D c = new MyCanvas3D(config);
+
+ // 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.
+ univ.getViewingPlatform().setNominalViewingTransform();
+
+ // Ensure at least 5 msec per frame (i.e., < 200Hz)
+ univ.getViewer().getView().setMinimumFrameCycleTime(5);
+
+ return c;
+ }
+
+ /**
+ * Creates new form AppearanceMixed
+ */
+ public AppearanceMixedGL2ES2() {
+
+ if (bgImage == null) {
+ // the path to the image for an applet
+ bgImage = Resources.getResource("resources/images/bg.jpg");
+ if (bgImage == null) {
+ System.err.println("resources/images/bg.jpg not found");
+ System.exit(1);
+ }
+ }
+
+ if (texImage == null) {
+ // the path to the image for an applet
+ texImage = Resources.getResource("resources/images/stone.jpg");
+ if (texImage == null) {
+ System.err.println("resources/images/stone.jpg 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);
+ }
+
+ // ----------------------------------------------------------------
+
+ /** 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.
+ */
+ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
+ private void initComponents() {
+ drawingPanel = new javax.swing.JPanel();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle("AppearanceMixed");
+ drawingPanel.setLayout(new java.awt.BorderLayout());
+
+ drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700));
+ getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER);
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[]) {System.setProperty("sun.awt.noerasebackground", "true");
+ System.setProperty("j3d.rend", "jogl2es2");System.setProperty("j3d.displaylist", "false");
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ new AppearanceMixedGL2ES2().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/background/BackgroundGeometryGL2ES2.java b/src/classes/org/jdesktop/j3d/examples/background/BackgroundGeometryGL2ES2.java
new file mode 100644
index 0000000..709dd78
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/background/BackgroundGeometryGL2ES2.java
@@ -0,0 +1,263 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+package org.jdesktop.j3d.examples.background;
+
+import java.awt.GraphicsConfiguration;
+
+import org.jdesktop.j3d.examples.Resources;
+import org.jdesktop.j3d.examples.gl2es2pipeline.SimpleShaderAppearance;
+import org.jogamp.java3d.Appearance;
+import org.jogamp.java3d.Background;
+import org.jogamp.java3d.BoundingSphere;
+import org.jogamp.java3d.BranchGroup;
+import org.jogamp.java3d.Canvas3D;
+import org.jogamp.java3d.DirectionalLight;
+import org.jogamp.java3d.Material;
+import org.jogamp.java3d.Transform3D;
+import org.jogamp.java3d.TransformGroup;
+import org.jogamp.java3d.utils.behaviors.mouse.MouseRotate;
+import org.jogamp.java3d.utils.behaviors.mouse.MouseTranslate;
+import org.jogamp.java3d.utils.behaviors.mouse.MouseZoom;
+import org.jogamp.java3d.utils.geometry.Box;
+import org.jogamp.java3d.utils.geometry.Sphere;
+import org.jogamp.java3d.utils.image.TextureLoader;
+import org.jogamp.java3d.utils.universe.SimpleUniverse;
+import org.jogamp.vecmath.Color3f;
+import org.jogamp.vecmath.Point3d;
+import org.jogamp.vecmath.Vector3f;
+
+public class BackgroundGeometryGL2ES2 extends javax.swing.JFrame {
+
+ private SimpleUniverse univ = null;
+ private BranchGroup scene = null;
+ private java.net.URL bgImage = null;
+ private BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
+
+ public BranchGroup createSceneGraph() {
+
+ // Create the root of the branch graph
+ BranchGroup objRoot = new BranchGroup();
+
+ // Create a Transformgroup to scale all objects so they
+ // appear in the scene.
+ TransformGroup objScale = new TransformGroup();
+ Transform3D t3d = new Transform3D();
+ t3d.setScale(0.4);
+ objScale.setTransform(t3d);
+ objRoot.addChild(objScale);
+
+ // Create the transform group node and initialize it to the
+ // identity. Enable the TRANSFORM_WRITE capability so that
+ // our behavior code can modify it at runtime.
+ TransformGroup objTrans = new TransformGroup();
+ objScale.addChild(objTrans);
+
+ Background bg = new Background();
+ bg.setApplicationBounds(bounds);
+ BranchGroup backGeoBranch = new BranchGroup();
+ Sphere sphereObj = new Sphere(1.0f, Sphere.GENERATE_NORMALS |
+ Sphere.GENERATE_NORMALS_INWARD |
+ Sphere.GENERATE_TEXTURE_COORDS |
+ Sphere.GENERATE_TEXTURE_COORDS_Y_UP, 45);
+ Appearance backgroundApp = new SimpleShaderAppearance(true, false);//sphereObj.getAppearance();
+ sphereObj.setAppearance(backgroundApp);
+ backGeoBranch.addChild(sphereObj);
+ bg.setGeometry(backGeoBranch);
+ objTrans.addChild(bg);
+
+ TextureLoader tex = new TextureLoader(bgImage,
+ new String("RGB"),
+ TextureLoader.BY_REFERENCE | TextureLoader.Y_UP,
+ this);
+ if (tex != null)
+ backgroundApp.setTexture(tex.getTexture());
+
+ Vector3f tranlation = new Vector3f(2.0f, 0.0f, 0.0f);
+ Transform3D modelTransform = new Transform3D();
+ Transform3D tmpTransform = new Transform3D();
+ double angleInc = Math.PI/8.0;
+ double angle = 0.0;
+ int numBoxes = 16;
+
+ float scaleX[] = {0.1f, 0.2f, 0.2f, 0.3f,
+ 0.2f, 0.1f, 0.2f, 0.3f,
+ 0.1f, 0.3f, 0.2f, 0.3f,
+ 0.1f, 0.3f, 0.2f, 0.3f};
+
+ float scaleY[] = {0.3f, 0.4f, 0.3f, 0.4f,
+ 0.3f, 0.4f, 0.3f, 0.4f,
+ 0.3f, 0.3f, 0.3f, 0.3f,
+ 0.3f, 0.3f, 0.3f, 0.4f};
+
+ float scaleZ[] = {0.3f, 0.2f, 0.1f, 0.1f,
+ 0.3f, 0.2f, 0.1f, 0.3f,
+ 0.3f, 0.2f, 0.1f, 0.3f,
+ 0.3f, 0.2f, 0.1f, 0.2f};
+
+ Appearance a1 = new SimpleShaderAppearance(true, false);
+
+ Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
+ Color3f sColor = new Color3f(0.5f, 0.5f, 1.0f);
+ Color3f oColor = new Color3f(0.5f, 0.5f, 0.3f);
+
+ Material m = new Material(oColor, eColor, oColor, sColor, 100.0f);
+ m.setLightingEnable(true);
+ a1.setMaterial(m);
+
+ for (int i=0; i<numBoxes; i++, angle += angleInc) {
+ modelTransform.rotY(angle);
+ tmpTransform.set(tranlation);
+ modelTransform.mul(tmpTransform);
+
+ TransformGroup tgroup = new TransformGroup(modelTransform);
+ objTrans.addChild(tgroup);
+
+ tgroup.addChild( new Box(scaleX[i],scaleY[i],scaleZ[i],
+ Box.GENERATE_NORMALS,a1));
+ }
+
+
+ // Shine it with two lights.
+ Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
+ Color3f lColor2 = new Color3f(0.2f, 0.2f, 0.1f);
+ Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
+ Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f);
+ DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
+ DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
+ lgt1.setInfluencingBounds(bounds);
+ lgt2.setInfluencingBounds(bounds);
+ objScale.addChild(lgt1);
+ objScale.addChild(lgt2);
+
+ return objRoot;
+ }
+
+ private Canvas3D createUniverse() {
+ // Get the preferred graphics configuration for the default screen
+ GraphicsConfiguration config =
+ SimpleUniverse.getPreferredConfiguration();
+
+ // Create a Canvas3D using the preferred configuration
+ Canvas3D c = new Canvas3D(config);
+
+ // 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.
+ univ.getViewingPlatform().setNominalViewingTransform();
+
+ // Ensure at least 5 msec per frame (i.e., < 200Hz)
+ univ.getViewer().getView().setMinimumFrameCycleTime(5);
+
+ TransformGroup viewTrans =
+ univ.getViewingPlatform().getViewPlatformTransform();
+
+ // Create the rotate behavior node
+ MouseRotate behavior1 = new MouseRotate(viewTrans);
+ scene.addChild(behavior1);
+ behavior1.setSchedulingBounds(bounds);
+
+ // Create the zoom behavior node
+ MouseZoom behavior2 = new MouseZoom(viewTrans);
+ scene.addChild(behavior2);
+ behavior2.setSchedulingBounds(bounds);
+
+ // Create the translate behavior node
+ MouseTranslate behavior3 = new MouseTranslate(viewTrans);
+ scene.addChild(behavior3);
+ behavior3.setSchedulingBounds(bounds);
+
+ return c;
+ }
+
+ /**
+ * Creates new form BackgroundGeometry
+ */
+ public BackgroundGeometryGL2ES2() {
+
+ if (bgImage == null) {
+ // the path to the image for an applet
+ bgImage = Resources.getResource("resources/images/bg.jpg");
+ if (bgImage == null) {
+ System.err.println("resources/images/bg.jpg not found");
+ System.exit(1);
+ }
+ }
+
+ // Initialize the GUI components
+ initComponents();
+
+ // Create the content branch and add it to the universe
+ scene = createSceneGraph();
+
+ // Create Canvas3D and SimpleUniverse; add canvas to drawing panel
+ Canvas3D c = createUniverse();
+ drawingPanel.add(c, java.awt.BorderLayout.CENTER);
+
+ // Let Java 3D perform optimizations on this scene graph.
+ scene.compile();
+
+ 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.
+ */
+ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
+ private void initComponents() {
+ drawingPanel = new javax.swing.JPanel();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle("BackgroundGeometry");
+ drawingPanel.setLayout(new java.awt.BorderLayout());
+
+ drawingPanel.setOpaque(false);
+ drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700));
+ getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER);
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[]) {System.setProperty("sun.awt.noerasebackground", "true");
+ System.setProperty("j3d.rend", "jogl2es2");System.setProperty("j3d.displaylist", "false");
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ new BackgroundGeometryGL2ES2().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/collision/TickTockCollisionGL2ES2.java b/src/classes/org/jdesktop/j3d/examples/collision/TickTockCollisionGL2ES2.java
new file mode 100644
index 0000000..44db453
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/collision/TickTockCollisionGL2ES2.java
@@ -0,0 +1,254 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+package org.jdesktop.j3d.examples.collision;
+
+import java.awt.GraphicsConfiguration;
+
+import org.jdesktop.j3d.examples.gl2es2pipeline.Cube;
+import org.jdesktop.j3d.examples.gl2es2pipeline.SimpleShaderAppearance;
+import org.jogamp.java3d.Alpha;
+import org.jogamp.java3d.Appearance;
+import org.jogamp.java3d.Background;
+import org.jogamp.java3d.BoundingSphere;
+import org.jogamp.java3d.BranchGroup;
+import org.jogamp.java3d.Canvas3D;
+import org.jogamp.java3d.ColoringAttributes;
+import org.jogamp.java3d.Group;
+import org.jogamp.java3d.RenderingAttributes;
+import org.jogamp.java3d.RotationInterpolator;
+import org.jogamp.java3d.Shape3D;
+import org.jogamp.java3d.Transform3D;
+import org.jogamp.java3d.TransformGroup;
+
+import org.jogamp.java3d.utils.universe.SimpleUniverse;
+import org.jogamp.vecmath.Color3f;
+import org.jogamp.vecmath.Point3d;
+import org.jogamp.vecmath.Vector3d;
+
+/**
+ * Simple Java 3D example program to display how collision work.
+ */
+public class TickTockCollisionGL2ES2 extends javax.swing.JFrame
+{
+
+ private SimpleUniverse univ = null;
+ private BranchGroup scene = null;
+
+ public BranchGroup createSceneGraph()
+ {
+ // Create the root of the branch graph
+ BranchGroup objRoot = new BranchGroup();
+
+ // Create a Transformgroup to scale all objects so they
+ // appear in the scene.
+ TransformGroup objScale = new TransformGroup();
+ Transform3D t3d = new Transform3D();
+ t3d.setScale(0.4);
+ objScale.setTransform(t3d);
+ objRoot.addChild(objScale);
+
+ // Create a bounds for the background and behaviors
+ BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
+
+ // Set up the background
+ Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
+ Background bg = new Background(bgColor);
+ bg.setApplicationBounds(bounds);
+ objScale.addChild(bg);
+
+ // Create a pair of transform group nodes and initialize them to
+ // identity. Enable the TRANSFORM_WRITE capability so that
+ // our behaviors can modify them at runtime. Add them to the
+ // root of the subgraph.
+ TransformGroup objTrans1 = new TransformGroup();
+ objTrans1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ objScale.addChild(objTrans1);
+
+ TransformGroup objTrans2 = new TransformGroup();
+ objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ objTrans1.addChild(objTrans2);
+
+ // Create the positioning and scaling transform group node.
+ Transform3D t = new Transform3D();
+ t.set(0.3, new Vector3d(0.0, -1.5, 0.0));
+ TransformGroup objTrans3 = new TransformGroup(t);
+ objTrans2.addChild(objTrans3);
+
+ // Create a simple shape leaf node, add it to the scene graph.
+ objTrans3.addChild(new Cube());
+
+ // Create a new Behavior object that will perform the desired
+ // rotation on the specified transform object and add it into
+ // the scene graph.
+ Transform3D yAxis1 = new Transform3D();
+ yAxis1.rotX(Math.PI / 2.0);
+ Alpha tickTockAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 5000, 2500, 200, 5000, 2500, 200);
+
+ RotationInterpolator tickTock = new RotationInterpolator(tickTockAlpha, objTrans1, yAxis1, -(float) Math.PI / 2.0f,
+ (float) Math.PI / 2.0f);
+ tickTock.setSchedulingBounds(bounds);
+ objTrans2.addChild(tickTock);
+
+ // Create a new Behavior object that will perform the desired
+ // rotation on the specified transform object and add it into
+ // the scene graph.
+ Transform3D yAxis2 = new Transform3D();
+ Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);
+
+ RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans2, yAxis2, 0.0f, (float) Math.PI * 2.0f);
+ rotator.setSchedulingBounds(bounds);
+ objTrans2.addChild(rotator);
+
+ // Now create a pair of rectangular boxes, each with a collision
+ // detection behavior attached. The behavior will highlight the
+ // object when it is in a state of collision.
+
+ Group box1 = createBox(0.3, new Vector3d(-1.3, 0.0, 0.0));
+ Group box2 = createBox(0.3, new Vector3d(1.3, 0.0, 0.0));
+
+ objScale.addChild(box1);
+ objScale.addChild(box2);
+
+ // Have Java 3D perform optimizations on this scene graph.
+ objRoot.compile();
+
+ return objRoot;
+ }
+
+ private static Group createBox(double scale, Vector3d pos)
+ {
+ // Create a transform group node to scale and position the object.
+ Transform3D t = new Transform3D();
+ t.set(scale, pos);
+ TransformGroup objTrans = new TransformGroup(t);
+
+ // Create a simple shape leaf node and add it to the scene graph
+ Shape3D shape = new Cube(0.5 / 2, 5.0 / 2, 1.0 / 2);
+ objTrans.addChild(shape);
+
+ // Create a new ColoringAttributes object for the shape's
+ // appearance and make it writable at runtime.
+ Appearance app = new SimpleShaderAppearance();
+ shape.setAppearance(app);
+ RenderingAttributes ra = new RenderingAttributes();
+ ra.setIgnoreVertexColors(true);
+ app.setRenderingAttributes(ra);
+ ColoringAttributes ca = new ColoringAttributes();
+ ca.setColor(0.6f, 0.3f, 0.0f);
+ app.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
+ app.setColoringAttributes(ca);
+
+ // Create a new Behavior object that will perform the collision
+ // detection on the specified object, and add it into
+ // the scene graph.
+ CollisionDetector cd = new CollisionDetector(shape);
+ BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
+ cd.setSchedulingBounds(bounds);
+
+ // Add the behavior to the scene graph
+ objTrans.addChild(cd);
+
+ return objTrans;
+ }
+
+ private Canvas3D createUniverse()
+ {
+ // Get the preferred graphics configuration for the default screen
+ GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
+
+ // Create a Canvas3D using the preferred configuration
+ Canvas3D c = new Canvas3D(config);
+
+ // 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.
+ univ.getViewingPlatform().setNominalViewingTransform();
+
+ // Ensure at least 5 msec per frame (i.e., < 200Hz)
+ univ.getViewer().getView().setMinimumFrameCycleTime(5);
+
+ return c;
+ }
+
+ /**
+ * Creates new form TickTockCollision
+ */
+ public TickTockCollisionGL2ES2()
+ {
+ // 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.
+ */
+ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
+ private void initComponents()
+ {
+ drawingPanel = new javax.swing.JPanel();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle("TickTockCollision");
+ drawingPanel.setLayout(new java.awt.BorderLayout());
+
+ drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700));
+ getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER);
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[])
+ {
+ System.setProperty("sun.awt.noerasebackground", "true");
+ System.setProperty("j3d.rend", "jogl2es2");
+ System.setProperty("j3d.displaylist", "false");
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
+ public void run()
+ {
+ new TickTockCollisionGL2ES2().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/depth_func/DepthFuncTestGL2ES2.java b/src/classes/org/jdesktop/j3d/examples/depth_func/DepthFuncTestGL2ES2.java
new file mode 100644
index 0000000..ed34922
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/depth_func/DepthFuncTestGL2ES2.java
@@ -0,0 +1,347 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+package org.jdesktop.j3d.examples.depth_func;
+
+import org.jogamp.java3d.RenderingAttributes;
+
+
+/**
+ *The goal of that example is to show the use of different ZBuffer comparison modes.
+ */
+public class DepthFuncTestGL2ES2 extends javax.swing.JFrame
+{
+
+ RenderFrameGL2ES2 rf;
+
+ /**
+ * Creates new form DepthFuncTest
+ */
+ public DepthFuncTestGL2ES2(){
+ initComponents();
+ }
+
+ /** 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.
+ */
+ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
+ private void initComponents()
+ {
+ java.awt.GridBagConstraints gridBagConstraints;
+
+ jPanel1 = new javax.swing.JPanel();
+ jLabel1 = new javax.swing.JLabel();
+ normalComboBox = new javax.swing.JComboBox();
+ wfCheckBox = new javax.swing.JCheckBox();
+ jPanel2 = new javax.swing.JPanel();
+ jLabel3 = new javax.swing.JLabel();
+ shadedComboBox = new javax.swing.JComboBox();
+ shadedCheckBox = new javax.swing.JCheckBox();
+ jPanel3 = new javax.swing.JPanel();
+ jLabel4 = new javax.swing.JLabel();
+ rotatingComboBox = new javax.swing.JComboBox();
+
+ getContentPane().setLayout(new java.awt.GridBagLayout());
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ jPanel1.setBorder(new javax.swing.border.TitledBorder("WireFrame Object"));
+ jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
+ jLabel1.setText("Depth function");
+ jLabel1.setToolTipText("Mode for normal object");
+ jPanel1.add(jLabel1);
+ jLabel1.getAccessibleContext().setAccessibleParent(shadedComboBox);
+
+ normalComboBox.setFont(new java.awt.Font("Dialog", 0, 12));
+ normalComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ALWAYS", "NEVER", "EQUAL", "NOT_EQUAL", "LESS", "LESS_OR_EQUAL", "GREATER", "GREATER_OR_EQUAL" }));
+ normalComboBox.setSelectedIndex(6);
+ normalComboBox.setPreferredSize(new java.awt.Dimension(150, 22));
+ normalComboBox.addActionListener(new java.awt.event.ActionListener()
+ {
+ @Override
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ normalComboBoxActionPerformed(evt);
+ }
+ });
+
+ jPanel1.add(normalComboBox);
+
+ wfCheckBox.setFont(new java.awt.Font("Dialog", 0, 12));
+ wfCheckBox.setText("Write Depth Buffer");
+ wfCheckBox.setToolTipText("Depth will be written for the object, if selected");
+ wfCheckBox.addActionListener(new java.awt.event.ActionListener()
+ {
+ @Override
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ wfCheckBoxActionPerformed(evt);
+ }
+ });
+
+ jPanel1.add(wfCheckBox);
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 0;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+ getContentPane().add(jPanel1, gridBagConstraints);
+
+ jPanel2.setBorder(new javax.swing.border.TitledBorder("Shaded Object"));
+ jLabel3.setFont(new java.awt.Font("Dialog", 0, 12));
+ jLabel3.setText("Depth Function");
+ jLabel3.setToolTipText("Mode of shaded object");
+ jPanel2.add(jLabel3);
+
+ shadedComboBox.setFont(new java.awt.Font("Dialog", 0, 12));
+ shadedComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ALWAYS", "NEVER", "EQUAL", "NOT_EQUAL", "LESS", "LESS_OR_EQUAL", "GREATER", "GREATER_OR_EQUAL" }));
+ shadedComboBox.setSelectedIndex(4);
+ shadedComboBox.addActionListener(new java.awt.event.ActionListener()
+ {
+ @Override
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ shadedComboBoxActionPerformed(evt);
+ }
+ });
+
+ jPanel2.add(shadedComboBox);
+
+ shadedCheckBox.setFont(new java.awt.Font("Dialog", 0, 12));
+ shadedCheckBox.setSelected(true);
+ shadedCheckBox.setText("Write Depth Buffer");
+ shadedCheckBox.setToolTipText("Depth will be written for the object, if selected");
+ shadedCheckBox.addActionListener(new java.awt.event.ActionListener()
+ {
+ @Override
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ shadedCheckBoxActionPerformed(evt);
+ }
+ });
+
+ jPanel2.add(shadedCheckBox);
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 1;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+ getContentPane().add(jPanel2, gridBagConstraints);
+
+ jPanel3.setBorder(new javax.swing.border.TitledBorder("Rotating Cube"));
+ jLabel4.setFont(new java.awt.Font("Dialog", 0, 12));
+ jLabel4.setText("Raster Operator - Raster Ops are not availible in GL2ES2");
+ jLabel4.setToolTipText("Raster mode of rotating object (try NOOP)");
+ jPanel3.add(jLabel4);
+
+ rotatingComboBox.setFont(new java.awt.Font("Dialog", 0, 12));
+ rotatingComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "CLEAR", "AND", "AND_REVERSE", "COPY", "AND_INVERTED", "NOOP", "XOR", "OR", "NOR", "EQUIV", "INVERT", "OR_REVERSE", "COPY_INVERTED", "OR_INVERTED", "NAND", "SET" }));
+ rotatingComboBox.setSelectedIndex(3);
+ rotatingComboBox.addActionListener(new java.awt.event.ActionListener()
+ {
+ @Override
+ public void actionPerformed(java.awt.event.ActionEvent evt)
+ {
+ rotatingComboBoxActionPerformed(evt);
+ }
+ });
+
+ //Raster Ops are not availible in GL2ES2
+ //jPanel3.add(rotatingComboBox);
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 2;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+ getContentPane().add(jPanel3, gridBagConstraints);
+
+ setBounds(0, 0, 403, 240);
+ }
+ // </editor-fold>//GEN-END:initComponents
+
+ private void rotatingComboBoxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_rotatingComboBoxActionPerformed
+ {//GEN-HEADEREND:event_rotatingComboBoxActionPerformed
+ String selectedItem = rotatingComboBox.getSelectedItem().toString(); // how to avoid a cast and all that goes with it. (lazyness)
+ int mode = RenderingAttributes.ROP_COPY;
+ if ( "CLEAR".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_CLEAR;
+ }
+ else if ( "AND".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_AND;
+ }
+ else if ( "AND_REVERSE".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_AND_REVERSE;
+ }
+ else if ( "COPY".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_COPY;
+ }
+ else if ( "AND_INVERTED".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_AND_INVERTED;
+ }
+ else if ( "NOOP".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_NOOP;
+ }
+ else if ( "XOR".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_XOR;
+ }
+ else if ( "OR".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_OR;
+ }
+ else if ( "NOR".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_NOR;
+ }
+ else if ( "EQUIV".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_EQUIV;
+ }
+ else if ( "INVERT".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_INVERT;
+ }
+ else if ( "OR_REVERSE".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_OR_REVERSE;
+ }
+ else if ( "COPY_INVERTED".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_COPY_INVERTED;
+ }
+ else if ( "OR_INVERTED".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_OR_INVERTED;
+ }
+ else if ( "NAND".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_NAND;
+ }
+ else if ( "SET".equals(selectedItem) )
+ {
+ mode = RenderingAttributes.ROP_SET;
+ }
+ else
+ {
+ System.out.println("oops. wrong mode in ROP combo: "+selectedItem);
+ }
+
+ rf.setRotatingObjectROPMode( mode );
+ }//GEN-LAST:event_rotatingComboBoxActionPerformed
+
+ private void shadedCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shadedCheckBoxActionPerformed
+ rf.setStaticObjectDBWriteStatus( shadedCheckBox.isSelected() );
+ }//GEN-LAST:event_shadedCheckBoxActionPerformed
+
+ private void wfCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wfCheckBoxActionPerformed
+ rf.setStaticWFObjectDBWriteStatus( wfCheckBox.isSelected() );
+ }//GEN-LAST:event_wfCheckBoxActionPerformed
+
+ private void shadedComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shadedComboBoxActionPerformed
+ //int func = RenderingAttributes.LESS_OR_EQUAL;
+ String selectedItem = shadedComboBox.getSelectedItem().toString(); // how to avoid a cast and all that goes with it. (lazyness)
+ rf.setStaticObjectTestFunc( getID( selectedItem ) );
+ }//GEN-LAST:event_shadedComboBoxActionPerformed
+
+ private void normalComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_normalComboBoxActionPerformed
+ //int func = RenderingAttributes.LESS_OR_EQUAL;
+ String selectedItem = normalComboBox.getSelectedItem().toString(); // how to avoid a cast and all that goes with it. (lazyness)
+ rf.setStaticWFObjectTestFunc( getID( selectedItem ) );
+ }//GEN-LAST:event_normalComboBoxActionPerformed
+
+ int getID( String selectedItem )
+ {
+ int func = RenderingAttributes.LESS_OR_EQUAL;
+ if ( "LESS_OR_EQUAL".equals(selectedItem) )
+ {
+ func = RenderingAttributes.LESS_OR_EQUAL;
+ }
+ else if ( "NEVER".equals(selectedItem) )
+ {
+ func = RenderingAttributes.NEVER;
+ }
+ else if ( "ALWAYS".equals(selectedItem) )
+ {
+ func = RenderingAttributes.ALWAYS;
+ }
+ else if ( "GREATER".equals(selectedItem) )
+ {
+ func = RenderingAttributes.GREATER;
+ }
+ else if ( "GREATER_OR_EQUAL".equals(selectedItem) )
+ {
+ func = RenderingAttributes.GREATER_OR_EQUAL;
+ }
+ else if ( "LESS".equals(selectedItem) )
+ {
+ func = RenderingAttributes.LESS;
+ }
+ else if ( "EQUAL".equals(selectedItem) )
+ {
+ func = RenderingAttributes.EQUAL;
+ }
+ else if ( "NOT_EQUAL".equals(selectedItem) )
+ {
+ func = RenderingAttributes.NOT_EQUAL;
+ }
+ return func;
+ }
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[]) {System.setProperty("sun.awt.noerasebackground", "true");
+ System.setProperty("j3d.rend", "jogl2es2");
+ System.setProperty("j3d.displaylist", "false");
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ DepthFuncTestGL2ES2 dpt = new DepthFuncTestGL2ES2();
+ dpt.rf = new RenderFrameGL2ES2( dpt );
+ dpt.setVisible(true);
+ dpt.rf.setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JLabel jLabel3;
+ private javax.swing.JLabel jLabel4;
+ private javax.swing.JPanel jPanel1;
+ private javax.swing.JPanel jPanel2;
+ private javax.swing.JPanel jPanel3;
+ private javax.swing.JComboBox<?> normalComboBox;
+ private javax.swing.JComboBox<?> rotatingComboBox;
+ private javax.swing.JCheckBox shadedCheckBox;
+ private javax.swing.JComboBox<?> shadedComboBox;
+ private javax.swing.JCheckBox wfCheckBox;
+ // End of variables declaration//GEN-END:variables
+
+}
diff --git a/src/classes/org/jdesktop/j3d/examples/depth_func/RenderFrameGL2ES2.java b/src/classes/org/jdesktop/j3d/examples/depth_func/RenderFrameGL2ES2.java
new file mode 100644
index 0000000..7eaed6e
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/depth_func/RenderFrameGL2ES2.java
@@ -0,0 +1,294 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+package org.jdesktop.j3d.examples.depth_func;
+
+import java.awt.GraphicsConfiguration;
+
+import org.jdesktop.j3d.examples.gl2es2pipeline.Cube;
+import org.jdesktop.j3d.examples.gl2es2pipeline.SimpleShaderAppearance;
+import org.jogamp.java3d.Alpha;
+import org.jogamp.java3d.Appearance;
+import org.jogamp.java3d.BoundingSphere;
+import org.jogamp.java3d.BranchGroup;
+import org.jogamp.java3d.Canvas3D;
+import org.jogamp.java3d.Material;
+import org.jogamp.java3d.OrderedGroup;
+import org.jogamp.java3d.PointLight;
+import org.jogamp.java3d.PolygonAttributes;
+import org.jogamp.java3d.RenderingAttributes;
+import org.jogamp.java3d.RotationInterpolator;
+import org.jogamp.java3d.ScaleInterpolator;
+import org.jogamp.java3d.Transform3D;
+import org.jogamp.java3d.TransformGroup;
+import org.jogamp.java3d.utils.behaviors.mouse.MouseRotate;
+import org.jogamp.java3d.utils.geometry.Sphere;
+import org.jogamp.java3d.utils.universe.SimpleUniverse;
+import org.jogamp.vecmath.Color3f;
+import org.jogamp.vecmath.Point3d;
+import org.jogamp.vecmath.Point3f;
+import org.jogamp.vecmath.Vector3f;
+
+public class RenderFrameGL2ES2 extends javax.swing.JFrame
+{
+
+ DepthFuncTestGL2ES2 dpt;
+
+ SimpleUniverse su;
+
+ RenderingAttributes staticWFBoxRA;
+ RenderingAttributes staticBoxRA;
+
+ RenderingAttributes rotatingBoxRA;
+
+ /** Creates new form RenderFrame */
+ public RenderFrameGL2ES2(DepthFuncTestGL2ES2 _dpt)
+ {
+ dpt = _dpt;
+ initComponents();
+ initUniverse();
+ }
+
+ /** 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.
+ */
+ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
+ private void initComponents()
+ {
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle("J3D frame");
+ setBounds(400, 0, 640, 480);
+ }
+ // </editor-fold>//GEN-END:initComponents
+
+ void initUniverse()
+ {
+ GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
+
+ Canvas3D c = new Canvas3D(config);
+ add("Center", c);
+ su = new SimpleUniverse(c);
+ su.addBranchGraph(createScene());
+ c.getView().setMinimumFrameCycleTime(10);
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ // End of variables declaration//GEN-END:variables
+
+ BranchGroup createScene()
+ {
+ BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
+
+ BranchGroup globalBG = new BranchGroup();
+ BranchGroup rotObjectBG = new BranchGroup();
+ OrderedGroup staticObjectOG = new OrderedGroup();
+ BranchGroup lampsBG = new BranchGroup();
+ OrderedGroup oGroup = new OrderedGroup();
+ TransformGroup staticBoxRotTG = new TransformGroup();
+ staticBoxRotTG.addChild(staticObjectOG);
+ TransformGroup objectsTGRot = new TransformGroup();
+ TransformGroup objectsTGTrans = new TransformGroup();
+ Transform3D objectsTGTransT3d = new Transform3D();
+ objectsTGTransT3d.setTranslation(new Vector3f(0.0f, 0.0f, -10.0f));
+ objectsTGTrans.setTransform(objectsTGTransT3d);
+ objectsTGRot.addChild(oGroup);
+ objectsTGTrans.addChild(objectsTGRot);
+ lampsBG.addChild(objectsTGTrans);
+
+ //adding a sphere as backgroung so there is something else than flat black, and cut cube removal as an other implication. (seeing through)
+ Appearance globalSphereAppearance = new SimpleShaderAppearance(true, false);
+ PolygonAttributes globalSpherePA = new PolygonAttributes();
+ globalSpherePA.setCullFace(PolygonAttributes.CULL_FRONT);// so that interior of the sphere is visible.
+ Material globalSphereMaterial = new Material();
+ globalSphereMaterial.setEmissiveColor(.25f, .3f, .35f);
+ globalSphereAppearance.setMaterial(globalSphereMaterial);
+ globalSphereAppearance.setPolygonAttributes(globalSpherePA);
+ Sphere globalSphere = new Sphere(6.0f);
+ globalSphere.setAppearance(globalSphereAppearance);
+ globalSphere.setBounds(bounds);
+ oGroup.addChild(globalSphere);
+
+ globalBG.addChild(lampsBG);
+
+ // adding lamps.
+ PointLight frontLamp = new PointLight(new Color3f(1.0f, 1.0f, 1.0f), new Point3f(20, 20, 20), new Point3f(0.0f, .0f, 0.f));
+ lampsBG.addChild(frontLamp);
+ frontLamp.setBounds(bounds);
+ frontLamp.setInfluencingBounds(bounds);
+ PointLight backLamp = new PointLight(new Color3f(1.0f, .0f, .0f), new Point3f(-20, -20, -20), new Point3f(0.0f, .0f, 0.f));
+ lampsBG.addChild(backLamp);
+ backLamp.setBounds(bounds);
+ backLamp.setInfluencingBounds(bounds);
+
+ //adding shapes.
+ {
+ //adding rotating and scaling cube
+ //doing the rotation
+ TransformGroup rotBoxTGRot = new TransformGroup();
+ rotBoxTGRot.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ RotationInterpolator rotBoxRotInt = new RotationInterpolator(new Alpha(-1, 20000), rotBoxTGRot);
+ rotBoxRotInt.setSchedulingBounds(bounds);
+ rotBoxRotInt.setBounds(bounds);
+
+ //doing the scaling
+ //Transform3D scaleBoxt3d = new Transform3D();
+ TransformGroup rotBoxTGScale = new TransformGroup();
+ rotBoxTGScale.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ ScaleInterpolator rotBoxScaleInt = new ScaleInterpolator(
+ new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 3000, 1500, 0, 3000, 1500, 0), rotBoxTGScale,
+ new Transform3D(), 0.7f, 1.6f);
+ rotBoxScaleInt.setSchedulingBounds(bounds);
+ rotBoxScaleInt.setBounds(bounds);
+
+ Appearance rotBoxApp = new SimpleShaderAppearance(false, false);
+ Material rotBoxMat = new Material();
+ rotBoxMat.setDiffuseColor(.4f, .4f, .4f);
+ rotBoxApp.setMaterial(rotBoxMat);
+ Cube rotBox = new Cube(1.1f / 2, 1.1f / 2, 1.1f / 2);
+ rotBox.setAppearance(rotBoxApp);
+ rotBoxTGScale.addChild(rotBox);
+ rotBoxTGRot.addChild(rotBoxTGScale);
+ TransformGroup rotBoxTG = new TransformGroup();
+ rotBoxTG.addChild(rotBoxTGRot);
+ rotObjectBG.addChild(rotBoxTG);
+ rotObjectBG.addChild(rotBoxScaleInt);
+ rotObjectBG.addChild(rotBoxRotInt);
+ rotBox.setBounds(bounds);
+
+ rotatingBoxRA = new RenderingAttributes();
+ //Raster Ops are not availible in GL2ES2
+ // rotatingBoxRA.setRasterOpEnable( true );
+ rotatingBoxRA.setCapability(RenderingAttributes.ALLOW_RASTER_OP_WRITE);
+ // rotatingBoxRA.setRasterOp( rotatingBoxRA.ROP_XOR );
+ rotBoxApp.setRenderingAttributes(rotatingBoxRA);
+
+ rotBox.setAppearance(rotBoxApp);
+ }
+
+ //adding static back face wireframe cube
+ {
+ Cube staticWFBoxBack = new Cube();
+ Appearance staticWFBoxApp = new SimpleShaderAppearance(false, false);
+ Material staticWFBoxMat = new Material();
+ staticWFBoxMat.setDiffuseColor(0.f, 0.f, 0.f);
+ staticWFBoxMat.setEmissiveColor(0.f, .4f, 0.f);
+ staticWFBoxApp.setMaterial(staticWFBoxMat);
+ PolygonAttributes staticWFBoxPABack = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_FRONT, 0.0f);
+ staticWFBoxApp.setPolygonAttributes(staticWFBoxPABack);
+ staticWFBoxRA = new RenderingAttributes();
+ staticWFBoxRA.setCapability(RenderingAttributes.ALLOW_DEPTH_TEST_FUNCTION_WRITE);
+ staticWFBoxRA.setCapability(RenderingAttributes.ALLOW_DEPTH_ENABLE_WRITE);
+ staticWFBoxRA.setDepthTestFunction(RenderingAttributes.GREATER);
+ staticWFBoxRA.setDepthBufferWriteEnable(false);
+ staticWFBoxApp.setRenderingAttributes(staticWFBoxRA);
+ staticWFBoxBack.setAppearance(staticWFBoxApp);
+ staticWFBoxBack.setBounds(bounds);
+ staticObjectOG.addChild(staticWFBoxBack);
+ }
+
+ //adding static front face wireframe cube
+ {
+ Cube staticWFBox = new Cube();
+ Appearance staticWFBoxApp = new SimpleShaderAppearance(false, false);
+ Material staticWFBoxMat = new Material();
+ staticWFBoxMat.setDiffuseColor(0.f, 0.f, 0.f);
+ staticWFBoxMat.setEmissiveColor(0.f, 1.f, 0.f);
+ staticWFBoxApp.setMaterial(staticWFBoxMat);
+ PolygonAttributes staticWFBoxPA = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_BACK, 0.0f);
+ staticWFBoxApp.setPolygonAttributes(staticWFBoxPA);
+ staticWFBoxApp.setRenderingAttributes(staticWFBoxRA);
+ staticWFBox.setAppearance(staticWFBoxApp);
+ staticWFBox.setBounds(bounds);
+ staticObjectOG.addChild(staticWFBox);
+ }
+
+ {// rotating the static cubes
+ Transform3D boxt3d = new Transform3D();
+ Transform3D tempt3d = new Transform3D();
+ boxt3d.rotZ(Math.PI / 4.0f);
+ tempt3d.rotX(Math.PI / 4.0f);
+ boxt3d.mul(tempt3d);
+ tempt3d.rotY(Math.PI / 4.0f);
+ boxt3d.mul(tempt3d);
+ staticBoxRotTG.setTransform(boxt3d);
+ }
+
+ // adding static flat cube
+ {
+ Cube staticBox = new Cube();
+ staticBox.setBounds(bounds);
+ Appearance boxApp = new SimpleShaderAppearance(false, false);
+ Material boxMat = new Material();
+ boxMat.setDiffuseColor(.7f, .7f, .7f);
+ boxApp.setMaterial(boxMat);
+ staticBoxRA = new RenderingAttributes();
+ staticBoxRA.setCapability(RenderingAttributes.ALLOW_DEPTH_TEST_FUNCTION_WRITE);
+ staticBoxRA.setCapability(RenderingAttributes.ALLOW_DEPTH_ENABLE_WRITE);
+ staticBoxRA.setDepthTestFunction(RenderingAttributes.LESS);
+ staticBoxRA.setDepthBufferWriteEnable(false);
+ boxApp.setRenderingAttributes(staticBoxRA);
+ staticBox.setAppearance(boxApp);
+ staticObjectOG.addChild(staticBox);
+ }
+ oGroup.addChild(rotObjectBG);
+ oGroup.addChild(staticBoxRotTG);
+
+ //adding the mouse rotate behavior to the group of cubes.
+ MouseRotate behavior = new MouseRotate();
+ behavior.setTransformGroup(objectsTGRot);
+ objectsTGRot.addChild(behavior);
+ objectsTGRot.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
+ objectsTGRot.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ behavior.setSchedulingBounds(bounds);
+ return globalBG;
+ }
+
+ public void setStaticWFObjectTestFunc(int func)
+ {
+ staticWFBoxRA.setDepthTestFunction(func);
+ }
+
+ public void setStaticObjectTestFunc(int func)
+ {
+ staticBoxRA.setDepthTestFunction(func);
+ }
+
+ public void setStaticWFObjectDBWriteStatus(boolean status)
+ {
+ staticWFBoxRA.setDepthBufferWriteEnable(status);
+ }
+
+ public void setStaticObjectDBWriteStatus(boolean status)
+ {
+ staticBoxRA.setDepthBufferWriteEnable(status);
+ }
+
+ public void setRotatingObjectROPMode(int mode)
+ {
+ //Raster Ops are not availible in GL2ES2
+ //rotatingBoxRA.setRasterOp( mode );
+ }
+
+}
diff --git a/src/classes/org/jdesktop/j3d/examples/distort_glyph/DistortGlyphTestGL2ES2.java b/src/classes/org/jdesktop/j3d/examples/distort_glyph/DistortGlyphTestGL2ES2.java
new file mode 100644
index 0000000..c92725a
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/distort_glyph/DistortGlyphTestGL2ES2.java
@@ -0,0 +1,324 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+package org.jdesktop.j3d.examples.distort_glyph;
+
+import java.awt.Font;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsEnvironment;
+
+import org.jdesktop.j3d.examples.Resources;
+
+import org.jogamp.java3d.AmbientLight;
+import org.jogamp.java3d.Appearance;
+import org.jogamp.java3d.BoundingSphere;
+import org.jogamp.java3d.BranchGroup;
+import org.jogamp.java3d.Canvas3D;
+import org.jogamp.java3d.DirectionalLight;
+import org.jogamp.java3d.Font3D;
+import org.jogamp.java3d.FontExtrusion;
+import org.jogamp.java3d.GLSLShaderProgram;
+import org.jogamp.java3d.GeometryArray;
+import org.jogamp.java3d.GraphicsConfigTemplate3D;
+import org.jogamp.java3d.Light;
+import org.jogamp.java3d.Material;
+import org.jogamp.java3d.PointLight;
+import org.jogamp.java3d.Shader;
+import org.jogamp.java3d.ShaderAppearance;
+import org.jogamp.java3d.ShaderAttributeSet;
+import org.jogamp.java3d.ShaderAttributeValue;
+import org.jogamp.java3d.Shape3D;
+import org.jogamp.java3d.SourceCodeShader;
+import org.jogamp.java3d.TexCoordGeneration;
+import org.jogamp.java3d.Texture;
+import org.jogamp.java3d.TransformGroup;
+import org.jogamp.java3d.utils.behaviors.mouse.MouseRotate;
+import org.jogamp.java3d.utils.behaviors.mouse.MouseTranslate;
+import org.jogamp.java3d.utils.behaviors.mouse.MouseZoom;
+import org.jogamp.java3d.utils.image.TextureLoader;
+import org.jogamp.java3d.utils.universe.SimpleUniverse;
+import org.jogamp.vecmath.Color3f;
+import org.jogamp.vecmath.Point3d;
+import org.jogamp.vecmath.Point3f;
+import org.jogamp.vecmath.Vector3f;
+
+public class DistortGlyphTestGL2ES2 extends javax.swing.JFrame
+{
+
+ private SimpleUniverse univ = null;
+ private BranchGroup scene = null;
+
+ // get a nice graphics config
+ private static GraphicsConfiguration getGraphicsConfig()
+ {
+ GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
+ template.setSceneAntialiasing(GraphicsConfigTemplate3D.PREFERRED);
+ GraphicsConfiguration gcfg = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
+ .getBestConfiguration(template);
+ return gcfg;
+ }
+
+ private void setupLights(BranchGroup root)
+ {
+ // set up the BoundingSphere for all the lights
+ BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0);
+
+ // Set up the ambient light
+ AmbientLight lightAmbient = new AmbientLight(new Color3f(0.37f, 0.37f, 0.37f));
+ lightAmbient.setInfluencingBounds(bounds);
+ root.addChild(lightAmbient);
+
+ // Set up the directional light
+ Vector3f lightDirection1 = new Vector3f(0.0f, 0.0f, -1.0f);
+ DirectionalLight lightDirectional1 = new DirectionalLight(new Color3f(1.00f, 0.10f, 0.00f), lightDirection1);
+ lightDirectional1.setInfluencingBounds(bounds);
+ lightDirectional1.setCapability(Light.ALLOW_STATE_WRITE);
+ root.addChild(lightDirectional1);
+
+ Point3f lightPos1 = new Point3f(-4.0f, 8.0f, 16.0f);
+ Point3f lightAttenuation1 = new Point3f(1.0f, 0.0f, 0.0f);
+ PointLight pointLight1 = new PointLight(new Color3f(0.37f, 1.00f, 0.37f), lightPos1, lightAttenuation1);
+ pointLight1.setInfluencingBounds(bounds);
+ root.addChild(pointLight1);
+
+ Point3f lightPos2 = new Point3f(-16.0f, 8.0f, 4.0f);
+ Point3f lightAttenuation2 = new Point3f(1.0f, 0.0f, 0.0f);
+ PointLight pointLight2 = new PointLight(new Color3f(0.37f, 0.37f, 1.00f), lightPos2, lightAttenuation2);
+ pointLight2.setInfluencingBounds(bounds);
+ root.addChild(pointLight2);
+ }
+
+ public BranchGroup createSceneGraph()
+ {
+ // Create the root of the branch graph
+ BranchGroup objRoot = new BranchGroup();
+
+ setupLights(objRoot);
+
+ TransformGroup objTransform = new TransformGroup();
+ objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
+
+ objRoot.addChild(objTransform);
+
+ // setup a nice textured appearance
+ Appearance app = makeShaderAppearance();
+ Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f);
+ Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
+ app.setMaterial(new Material(objColor, black, objColor, black, 80.0f));
+ Texture txtr = new TextureLoader(Resources.getResource("resources/images/gold.jpg"), this).getTexture();
+ app.setTexture(txtr);
+ // done in shader see makeShaderAppearance() below
+ //TexCoordGeneration tcg = new TexCoordGeneration(TexCoordGeneration.SPHERE_MAP, TexCoordGeneration.TEXTURE_COORDINATE_2);
+ //app.setTexCoordGeneration(tcg);
+
+ // use a customized FontExtrusion object to control the depth of the text
+ java.awt.geom.GeneralPath gp = new java.awt.geom.GeneralPath();
+ gp.moveTo(0, 0);
+ gp.lineTo(.01f, .01f);
+ gp.lineTo(.2f, .01f);
+ gp.lineTo(.21f, 0f);
+ FontExtrusion fontEx = new FontExtrusion(gp);
+
+ // our glyph
+ Font fnt = new Font("dialog", Font.BOLD, 1);
+ Font3D f3d = new Font3D(fnt, .001, fontEx);
+ GeometryArray geom = f3d.getGlyphGeometry('A');
+ Shape3D shape = new Shape3D(geom, app);
+ objTransform.addChild(shape);
+
+ // the DistortBehavior
+ DistortBehavior eb = new DistortBehavior(shape, 1000, 1000);
+ eb.setSchedulingBounds(new BoundingSphere());
+ objTransform.addChild(eb);
+
+ MouseRotate myMouseRotate = new MouseRotate();
+ myMouseRotate.setTransformGroup(objTransform);
+ myMouseRotate.setSchedulingBounds(new BoundingSphere());
+ objRoot.addChild(myMouseRotate);
+
+ MouseTranslate myMouseTranslate = new MouseTranslate();
+ myMouseTranslate.setTransformGroup(objTransform);
+ myMouseTranslate.setSchedulingBounds(new BoundingSphere());
+ objRoot.addChild(myMouseTranslate);
+
+ MouseZoom myMouseZoom = new MouseZoom();
+ myMouseZoom.setTransformGroup(objTransform);
+ myMouseZoom.setSchedulingBounds(new BoundingSphere());
+ objRoot.addChild(myMouseZoom);
+
+ // Let Java 3D perform optimizations on this scene graph.
+ objRoot.compile();
+
+ return objRoot;
+ }
+
+ private Canvas3D createUniverse()
+ {
+
+ // Create a Canvas3D using a nice configuration
+ Canvas3D c = new Canvas3D(getGraphicsConfig());
+
+ // 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.
+ univ.getViewingPlatform().setNominalViewingTransform();
+
+ // Ensure at least 5 msec per frame (i.e., < 200Hz)
+ univ.getViewer().getView().setMinimumFrameCycleTime(5);
+
+ return c;
+ }
+
+ /**
+ * Creates new form DistortGlyphTest2
+ */
+ public DistortGlyphTestGL2ES2()
+ {
+ // 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.
+ */
+ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
+ private void initComponents()
+ {
+ drawingPanel = new javax.swing.JPanel();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle("DistortGlyphTest");
+ drawingPanel.setLayout(new java.awt.BorderLayout());
+
+ drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700));
+ getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER);
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[])
+ {
+ System.setProperty("sun.awt.noerasebackground", "true");
+ System.setProperty("j3d.rend", "jogl2es2");
+ System.setProperty("j3d.displaylist", "false");
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ public void run()
+ {
+ new DistortGlyphTestGL2ES2().setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JPanel drawingPanel;
+ // End of variables declaration//GEN-END:variables
+
+ public static ShaderAppearance makeShaderAppearance()
+ {
+ ShaderAppearance app = new ShaderAppearance();
+ GLSLShaderProgram litTextureShaderProgram = new GLSLShaderProgram() {
+ @Override
+ public String toString()
+ {
+ return "SimpleShaderAppearance litTextureShaderProgram";
+ }
+ };
+ litTextureShaderProgram.setShaders(makeShaders(vertShader, fragShader));
+ litTextureShaderProgram.setShaderAttrNames(new String[] { "EnvMap" });
+
+ app.setShaderProgram(litTextureShaderProgram);
+
+ ShaderAttributeSet shaderAttributeSet = new ShaderAttributeSet();
+ shaderAttributeSet.put(new ShaderAttributeValue("EnvMap", new Integer(0)));
+ app.setShaderAttributeSet(shaderAttributeSet);
+ return app;
+ }
+
+ private static Shader[] makeShaders(String vertexProgram, String fragmentProgram)
+ {
+ Shader[] shaders = new Shader[2];
+ shaders[0] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_VERTEX, vertexProgram) {
+ @Override
+ public String toString()
+ {
+ return "vertexProgram";
+ }
+ };
+ shaders[1] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_FRAGMENT, fragmentProgram) {
+ @Override
+ public String toString()
+ {
+ return "fragmentProgram";
+ }
+ };
+ return shaders;
+ }
+
+ public static String fragShader = "uniform sampler2D EnvMap;\n" + //
+ "varying vec2 texCoord0;\n" + //
+ "void main (void)\n" + //
+ "{\n" + //
+ " vec2 tc0 = texCoord0.xy;\n" + //
+ " vec3 color = vec3(texture2D(EnvMap, tc0));\n" + //
+ " gl_FragColor = vec4(color, 1.0);\n" + //
+ "}\n";
+
+ public static String vertShader = "attribute vec4 glVertex;\n" + //
+ "attribute vec3 glNormal; \n" + //
+ "uniform mat4 glModelViewProjectionMatrix;\n" + //
+ "uniform mat4 glModelViewMatrix;\n" + //
+ "uniform mat3 glNormalMatrix;\n" + //
+ "varying vec3 Normal;\n" + //
+ "varying vec2 texCoord0;\n" + //
+ "vec2 sphere_map(vec3 position, vec3 normal)\n" + //
+ "{\n" + //
+ " vec3 reflection = reflect(position, normal);\n" + //
+ " float m = 2.0 * sqrt(reflection.x * reflection.x + reflection.y * reflection.y + (reflection.z + 1.0) * (reflection.z + 1.0)); \n"
+ + //
+ " return vec2((reflection.x / m + 0.5), (reflection.y / m + 0.5));\n" + //
+ "}\n" + //
+ "void main()\n" + //
+ "{\n" + //
+ " Normal = normalize(vec3(glNormalMatrix * glNormal));\n" + //
+ " gl_Position = glModelViewProjectionMatrix * glVertex; \n" + //
+ " texCoord0 = sphere_map(normalize(vec3(glModelViewMatrix*glVertex)), Normal);\n" + //
+ "}\n"; //
+
+}
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/Cube.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/Cube.java
new file mode 100644
index 0000000..86f02ea
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/Cube.java
@@ -0,0 +1,311 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+package org.jdesktop.j3d.examples.gl2es2pipeline;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+
+import org.jogamp.java3d.GeometryArray;
+import org.jogamp.java3d.J3DBuffer;
+import org.jogamp.java3d.Shape3D;
+import org.jogamp.java3d.TriangleArray;
+
+/**
+ * @author Administrator
+ *
+ */
+public class Cube extends Shape3D
+{
+
+ private static final float[] verts = {
+ // front face
+ 1.0f, -1.0f, 1.0f, //1
+ 1.0f, 1.0f, 1.0f, //2
+ -1.0f, 1.0f, 1.0f, //3
+ 1.0f, -1.0f, 1.0f, //1
+ -1.0f, 1.0f, 1.0f, //3
+ -1.0f, -1.0f, 1.0f, //4
+ // back face
+ -1.0f, -1.0f, -1.0f, //1
+ -1.0f, 1.0f, -1.0f, //2
+ 1.0f, 1.0f, -1.0f, //3
+ -1.0f, -1.0f, -1.0f, //1
+ 1.0f, 1.0f, -1.0f, //3
+ 1.0f, -1.0f, -1.0f, //4
+ // right face
+ 1.0f, -1.0f, -1.0f, //1
+ 1.0f, 1.0f, -1.0f, //2
+ 1.0f, 1.0f, 1.0f, //3
+ 1.0f, -1.0f, -1.0f, //1
+ 1.0f, 1.0f, 1.0f, //3
+ 1.0f, -1.0f, 1.0f, //4
+ // left face
+ -1.0f, -1.0f, 1.0f, //1
+ -1.0f, 1.0f, 1.0f, //2
+ -1.0f, 1.0f, -1.0f, //3
+ -1.0f, -1.0f, 1.0f, //1
+ -1.0f, 1.0f, -1.0f, //3
+ -1.0f, -1.0f, -1.0f, //4
+ // top face
+ 1.0f, 1.0f, 1.0f, //1
+ 1.0f, 1.0f, -1.0f, //2
+ -1.0f, 1.0f, -1.0f, //3
+ 1.0f, 1.0f, 1.0f, //1
+ -1.0f, 1.0f, -1.0f, //3
+ -1.0f, 1.0f, 1.0f, //4
+ // bottom face
+ -1.0f, -1.0f, 1.0f, //1
+ -1.0f, -1.0f, -1.0f, //2
+ 1.0f, -1.0f, -1.0f, //3
+ -1.0f, -1.0f, 1.0f, //1
+ 1.0f, -1.0f, -1.0f, //3
+ 1.0f, -1.0f, 1.0f, };//4
+
+ private static final float[] colors = {
+ // front face (red)
+ 1.0f, 0.0f, 0.0f, //1
+ 1.0f, 0.0f, 0.0f, //2
+ 1.0f, 0.0f, 0.0f, //3
+ 1.0f, 0.0f, 0.0f, //1
+ 1.0f, 0.0f, 0.0f, //3
+ 1.0f, 0.0f, 0.0f, //4
+ // back face (green)
+ 0.0f, 1.0f, 0.0f, //1
+ 0.0f, 1.0f, 0.0f, //2
+ 0.0f, 1.0f, 0.0f, //3
+ 0.0f, 1.0f, 0.0f, //1
+ 0.0f, 1.0f, 0.0f, //3
+ 0.0f, 1.0f, 0.0f, //4
+ // right face (blue)
+ 0.0f, 0.0f, 1.0f, //1
+ 0.0f, 0.0f, 1.0f, //2
+ 0.0f, 0.0f, 1.0f, //3
+ 0.0f, 0.0f, 1.0f, //1
+ 0.0f, 0.0f, 1.0f, //3
+ 0.0f, 0.0f, 1.0f, //4
+ // left face (yellow)
+ 1.0f, 1.0f, 0.0f, //1
+ 1.0f, 1.0f, 0.0f, //2
+ 1.0f, 1.0f, 0.0f, //3
+ 1.0f, 1.0f, 0.0f, //1
+ 1.0f, 1.0f, 0.0f, //3
+ 1.0f, 1.0f, 0.0f, //4
+ // top face (magenta)
+ 1.0f, 0.0f, 1.0f, //1
+ 1.0f, 0.0f, 1.0f, //2
+ 1.0f, 0.0f, 1.0f, //3
+ 1.0f, 0.0f, 1.0f, //1
+ 1.0f, 0.0f, 1.0f, //3
+ 1.0f, 0.0f, 1.0f, //4
+ // bottom face (cyan)
+ 0.0f, 1.0f, 1.0f, //1
+ 0.0f, 1.0f, 1.0f, //2
+ 0.0f, 1.0f, 1.0f, //3
+ 0.0f, 1.0f, 1.0f, //1
+ 0.0f, 1.0f, 1.0f, //3
+ 0.0f, 1.0f, 1.0f, };//4
+
+ /**
+ * Constructs a color cube with unit scale. The corners of the
+ * color cube are [-1,-1,-1] and [1,1,1].
+ */
+ public Cube()
+ {
+ TriangleArray cube = new TriangleArray(36,
+ GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.USE_NIO_BUFFER | GeometryArray.BY_REFERENCE);
+
+ cube.setCoordRefBuffer(new J3DBuffer(makeFloatBuffer(verts)));
+ cube.setColorRefBuffer(new J3DBuffer(makeFloatBuffer(colors)));
+
+ this.setGeometry(cube);
+ this.setAppearance(new SimpleShaderAppearance());
+ }
+
+ /**
+ * Constructs a color cube with the specified scale. The corners of the
+ * color cube are [-scale,-scale,-scale] and [scale,scale,scale].
+ * @param scale the scale of the cube
+ */
+ public Cube(double scale)
+ {
+ TriangleArray cube = new TriangleArray(36,
+ GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.USE_NIO_BUFFER | GeometryArray.BY_REFERENCE);
+
+ float scaledVerts[] = new float[verts.length];
+ for (int i = 0; i < verts.length; i++)
+ scaledVerts[i] = verts[i] * (float) scale;
+
+ cube.setCoordRefBuffer(new J3DBuffer(makeFloatBuffer(scaledVerts)));
+ cube.setColorRefBuffer(new J3DBuffer(makeFloatBuffer(colors)));
+
+ this.setGeometry(cube);
+
+ this.setAppearance(new SimpleShaderAppearance());
+ }
+
+ public Cube(double scale, float r, float g, float b)
+ {
+ TriangleArray cube = new TriangleArray(36,
+ GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.USE_NIO_BUFFER | GeometryArray.BY_REFERENCE);
+
+ float scaledVerts[] = new float[verts.length];
+ for (int i = 0; i < verts.length; i++)
+ scaledVerts[i] = verts[i] * (float) scale;
+
+ cube.setCoordRefBuffer(new J3DBuffer(makeFloatBuffer(scaledVerts)));
+
+ float colorsSet[] = new float[36 * 3];
+ for (int i = 0; i < 36; i++)
+ {
+ colorsSet[i * 3 + 0] = r;
+ colorsSet[i * 3 + 1] = g;
+ colorsSet[i * 3 + 2] = b;
+ }
+
+ cube.setColorRefBuffer(new J3DBuffer(makeFloatBuffer(colorsSet)));
+
+ this.setGeometry(cube);
+ this.setAppearance(new SimpleShaderAppearance());
+ }
+
+ /**
+ * Constructs a color cube with the specified scale. The corners of the
+ * color cube are [-scale,-scale,-scale] and [scale,scale,scale].
+ * @param scale the scale of the cube
+ */
+ public Cube(double xScale, double yScale, double zScale)
+ {
+ TriangleArray cube = new TriangleArray(36,
+ GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.USE_NIO_BUFFER | GeometryArray.BY_REFERENCE);
+
+ float scaledVerts[] = new float[verts.length];
+ for (int i = 0; i < verts.length; i += 3)
+ {
+ scaledVerts[i + 0] = verts[i + 0] * (float) xScale;
+ scaledVerts[i + 1] = verts[i + 1] * (float) yScale;
+ scaledVerts[i + 2] = verts[i + 2] * (float) zScale;
+ }
+
+ cube.setCoordRefBuffer(new J3DBuffer(makeFloatBuffer(scaledVerts)));
+ cube.setColorRefBuffer(new J3DBuffer(makeFloatBuffer(colors)));
+
+ this.setGeometry(cube);
+ this.setAppearance(new SimpleShaderAppearance());
+ }
+
+ public Cube(double xScale, double yScale, double zScale, float r, float g, float b)
+ {
+ TriangleArray cube = new TriangleArray(36,
+ GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.USE_NIO_BUFFER | GeometryArray.BY_REFERENCE);
+
+ float scaledVerts[] = new float[verts.length];
+ for (int i = 0; i < verts.length; i += 3)
+ {
+ scaledVerts[i + 0] = verts[i + 0] * (float) xScale;
+ scaledVerts[i + 1] = verts[i + 1] * (float) yScale;
+ scaledVerts[i + 2] = verts[i + 2] * (float) zScale;
+ }
+
+ cube.setCoordRefBuffer(new J3DBuffer(makeFloatBuffer(scaledVerts)));
+
+ float colorsSet[] = new float[36 * 3];
+ for (int i = 0; i < 36; i++)
+ {
+ colorsSet[i * 3 + 0] = r;
+ colorsSet[i * 3 + 1] = g;
+ colorsSet[i * 3 + 2] = b;
+ }
+
+ cube.setColorRefBuffer(new J3DBuffer(makeFloatBuffer(colorsSet)));
+
+ this.setGeometry(cube);
+ this.setAppearance(new SimpleShaderAppearance());
+ }
+
+ public Cube(float xMin, float yMin, float zMin, float xMax, float yMax, float zMax)
+ {
+ TriangleArray cube = new TriangleArray(36,
+ GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.USE_NIO_BUFFER | GeometryArray.BY_REFERENCE);
+
+ float scaledVerts[] = new float[] {
+ // front face
+ xMax, yMin, zMax, //1
+ xMax, yMax, zMax, //2
+ xMin, yMax, zMax, //3
+ xMax, yMin, zMax, //1
+ xMin, yMax, zMax, //3
+ xMin, yMin, zMax, //4
+ // back face
+ xMin, yMin, zMin, //1
+ xMin, yMax, zMin, //2
+ xMax, yMax, zMin, //3
+ xMin, yMin, zMin, //1
+ xMax, yMax, zMin, //3
+ xMax, yMin, zMin, //4
+ // right face
+ xMax, yMin, zMin, //1
+ xMax, yMax, zMin, //2
+ xMax, yMax, zMax, //3
+ xMax, yMin, zMin, //1
+ xMax, yMax, zMax, //3
+ xMax, yMin, zMax, //4
+ // left face
+ xMin, yMin, zMax, //1
+ xMin, yMax, zMax, //2
+ xMin, yMax, zMin, //3
+ xMin, yMin, zMax, //1
+ xMin, yMax, zMin, //3
+ xMin, yMin, zMin, //4
+ // top face
+ xMax, yMax, zMax, //1
+ xMax, yMax, zMin, //2
+ xMin, yMax, zMin, //3
+ xMax, yMax, zMax, //1
+ xMin, yMax, zMin, //3
+ xMin, yMax, zMax, //4
+ // bottom face
+ xMin, yMin, zMax, //1
+ xMin, yMin, zMin, //2
+ xMax, yMin, zMin, //3
+ xMin, yMin, zMax, //1
+ xMax, yMin, zMin, //3
+ xMax, yMin, zMax, };//4
+
+ cube.setCoordRefBuffer(new J3DBuffer(makeFloatBuffer(scaledVerts)));
+ cube.setColorRefBuffer(new J3DBuffer(makeFloatBuffer(colors)));
+
+ this.setGeometry(cube);
+ this.setAppearance(new SimpleShaderAppearance());
+ }
+
+ public static FloatBuffer makeFloatBuffer(float[] arr)
+ {
+ ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4);
+ bb.order(ByteOrder.nativeOrder());
+ FloatBuffer fb = bb.asFloatBuffer();
+ fb.put(arr);
+ fb.position(0);
+ return fb;
+ }
+
+}
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/EnvironmentMappingGLSL.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/EnvironmentMappingGLSL.java
index 5eba8df..700df00 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/EnvironmentMappingGLSL.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/EnvironmentMappingGLSL.java
@@ -1,45 +1,23 @@
/*
- * $RCSfile$
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
*
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * - 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.gl2es2pipeline;
@@ -48,9 +26,6 @@ import java.awt.GraphicsConfiguration;
import java.io.File;
import java.io.IOException;
import java.net.URL;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.FloatBuffer;
import javax.swing.JOptionPane;
@@ -60,8 +35,6 @@ import org.jogamp.java3d.BoundingSphere;
import org.jogamp.java3d.BranchGroup;
import org.jogamp.java3d.Canvas3D;
import org.jogamp.java3d.GLSLShaderProgram;
-import org.jogamp.java3d.GeometryArray;
-import org.jogamp.java3d.J3DBuffer;
import org.jogamp.java3d.RotationInterpolator;
import org.jogamp.java3d.Shader;
import org.jogamp.java3d.ShaderAppearance;
@@ -76,7 +49,6 @@ import org.jogamp.java3d.Texture;
import org.jogamp.java3d.TextureUnitState;
import org.jogamp.java3d.Transform3D;
import org.jogamp.java3d.TransformGroup;
-import org.jogamp.java3d.TriangleStripArray;
import org.jogamp.java3d.utils.geometry.Sphere;
import org.jogamp.java3d.utils.image.TextureLoader;
import org.jogamp.java3d.utils.shader.StringIO;
@@ -191,6 +163,7 @@ public class EnvironmentMappingGLSL extends javax.swing.JFrame
// Add a ShaderErrorListener
univ.addShaderErrorListener(new ShaderErrorListener() {
+ @Override
public void errorOccurred(ShaderError error)
{
error.printVerbose();
@@ -251,6 +224,7 @@ public class EnvironmentMappingGLSL extends javax.swing.JFrame
System.setProperty("sun.awt.noerasebackground", "true");
System.setProperty("j3d.rend", "jogl2es2");
java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
public void run()
{
new EnvironmentMappingGLSL().setVisible(true);
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ObjLoadGLSL.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ObjLoadGLSL.java
index 709ff47..2708e58 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ObjLoadGLSL.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ObjLoadGLSL.java
@@ -1,45 +1,23 @@
/*
- * $RCSfile$
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
*
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * - 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.gl2es2pipeline;
@@ -212,6 +190,7 @@ public class ObjLoadGLSL extends javax.swing.JFrame
// Add a ShaderErrorListener
univ.addShaderErrorListener(new ShaderErrorListener() {
+ @Override
public void errorOccurred(ShaderError error)
{
error.printVerbose();
@@ -263,7 +242,7 @@ public class ObjLoadGLSL extends javax.swing.JFrame
return canvas3d;
}
- private void usage()
+ private static void usage()
{
System.out.println("Usage: java ObjLoadGLSL [-s] [-S shaderName] [-n] [-t] [-c degrees] <.obj file>");
System.out.println(" -s Spin (no user interaction)");
@@ -289,7 +268,7 @@ public class ObjLoadGLSL extends javax.swing.JFrame
private void setShaderProgram(Group g, ShaderAppearance myApp)
{
- Enumeration e = g.getAllChildren();
+ Enumeration<?> e = g.getAllChildren();
while (e.hasMoreElements())
{
Node n = (Node) (e.nextElement());
@@ -429,6 +408,7 @@ public class ObjLoadGLSL extends javax.swing.JFrame
System.setProperty("sun.awt.noerasebackground", "true");
System.setProperty("j3d.rend","jogl2es2");
java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
public void run()
{
ObjLoadGLSL objLoadGLSL = new ObjLoadGLSL(args);
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/PhongShadingGLSL.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/PhongShadingGLSL.java
index 03fbd3d..fa5ba7a 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/PhongShadingGLSL.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/PhongShadingGLSL.java
@@ -1,45 +1,23 @@
/*
- * $RCSfile$
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
*
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * - 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.gl2es2pipeline;
@@ -47,9 +25,6 @@ package org.jdesktop.j3d.examples.gl2es2pipeline;
import java.awt.GraphicsConfiguration;
import java.io.File;
import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.FloatBuffer;
import javax.swing.JOptionPane;
@@ -63,8 +38,6 @@ import org.jogamp.java3d.Canvas3D;
import org.jogamp.java3d.ColoringAttributes;
import org.jogamp.java3d.DirectionalLight;
import org.jogamp.java3d.GLSLShaderProgram;
-import org.jogamp.java3d.GeometryArray;
-import org.jogamp.java3d.J3DBuffer;
import org.jogamp.java3d.Light;
import org.jogamp.java3d.Material;
import org.jogamp.java3d.PointLight;
@@ -78,7 +51,6 @@ import org.jogamp.java3d.SourceCodeShader;
import org.jogamp.java3d.SpotLight;
import org.jogamp.java3d.Transform3D;
import org.jogamp.java3d.TransformGroup;
-import org.jogamp.java3d.TriangleStripArray;
import org.jogamp.java3d.utils.geometry.Sphere;
import org.jogamp.java3d.utils.shader.StringIO;
import org.jogamp.java3d.utils.universe.SimpleUniverse;
@@ -160,7 +132,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame
String vertexProgram = null;
String fragmentProgram = null;
Shader[] shaders = new Shader[2];
- String[] attrNames = { "numLights" };
+ //String[] attrNames = { "numLights" };
try
{
@@ -332,6 +304,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame
// Add a ShaderErrorListener
univ.addShaderErrorListener(new ShaderErrorListener() {
+ @Override
public void errorOccurred(ShaderError error)
{
error.printVerbose();
@@ -397,6 +370,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame
gouraudButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
gouraudButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
gouraudButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
gouraudButtonActionPerformed(evt);
@@ -413,6 +387,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame
phongButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
phongButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
phongButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
phongButtonActionPerformed(evt);
@@ -441,6 +416,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame
fileMenu.setText("File");
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
exitMenuItemActionPerformed(evt);
@@ -466,7 +442,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame
sApp.setShaderProgram(gouraudSP);
}//GEN-LAST:event_gouraudButtonActionPerformed
- private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt)
+ private static void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_exitMenuItemActionPerformed
System.exit(0);
}//GEN-LAST:event_exitMenuItemActionPerformed
@@ -479,6 +455,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame
System.setProperty("sun.awt.noerasebackground", "true");
System.setProperty("j3d.rend", "jogl2es2");
java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
public void run()
{
new PhongShadingGLSL().setVisible(true);
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SamplerTestGLSL.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SamplerTestGLSL.java
index 11bfeeb..1cb2904 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SamplerTestGLSL.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SamplerTestGLSL.java
@@ -1,45 +1,23 @@
/*
- * $RCSfile$
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
*
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * - 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.gl2es2pipeline;
@@ -207,6 +185,7 @@ public class SamplerTestGLSL extends javax.swing.JFrame
// Add a ShaderErrorListener
univ.addShaderErrorListener(new ShaderErrorListener() {
+ @Override
public void errorOccurred(ShaderError error)
{
error.printVerbose();
@@ -267,6 +246,7 @@ public class SamplerTestGLSL extends javax.swing.JFrame
System.setProperty("sun.awt.noerasebackground", "true");
System.setProperty("j3d.rend","jogl2es2");
java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
public void run()
{
new SamplerTestGLSL().setVisible(true);
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ShaderTestGLSL.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ShaderTestGLSL.java
index 65f40bb..ac0282e 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ShaderTestGLSL.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ShaderTestGLSL.java
@@ -1,45 +1,23 @@
/*
- * $RCSfile$
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
*
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * - 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.gl2es2pipeline;
@@ -47,9 +25,6 @@ package org.jdesktop.j3d.examples.gl2es2pipeline;
import java.awt.GraphicsConfiguration;
import java.io.File;
import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.FloatBuffer;
import javax.swing.JOptionPane;
@@ -59,8 +34,6 @@ import org.jogamp.java3d.BoundingSphere;
import org.jogamp.java3d.BranchGroup;
import org.jogamp.java3d.Canvas3D;
import org.jogamp.java3d.GLSLShaderProgram;
-import org.jogamp.java3d.GeometryArray;
-import org.jogamp.java3d.J3DBuffer;
import org.jogamp.java3d.Material;
import org.jogamp.java3d.PositionInterpolator;
import org.jogamp.java3d.Shader;
@@ -75,8 +48,6 @@ import org.jogamp.java3d.Shape3D;
import org.jogamp.java3d.SourceCodeShader;
import org.jogamp.java3d.Transform3D;
import org.jogamp.java3d.TransformGroup;
-import org.jogamp.java3d.TriangleStripArray;
-import org.jogamp.java3d.View;
import org.jogamp.java3d.utils.geometry.Sphere;
import org.jogamp.java3d.utils.shader.StringIO;
import org.jogamp.java3d.utils.universe.SimpleUniverse;
@@ -102,8 +73,8 @@ public class ShaderTestGLSL extends javax.swing.JFrame
static final String[] shaderAttrNames2 = { "BrickColor", "LightPosition" };
private SimpleUniverse univ = null;
- private View view;
- private BranchGroup transpObj;
+ //private View view;
+ //private BranchGroup transpObj;
private BranchGroup scene = null;
private int shaderSelected = DIMPLE_SHADER;
private float density = 16.0f;
@@ -140,7 +111,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
return m;
}
- private ShaderProgram createGLSLShaderProgram(int index)
+ private static ShaderProgram createGLSLShaderProgram(int index)
{
String vertexProgram = null;
String fragmentProgram = null;
@@ -348,6 +319,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
// Add a ShaderErrorListener
univ.addShaderErrorListener(new ShaderErrorListener() {
+ @Override
public void errorOccurred(ShaderError error)
{
error.printVerbose();
@@ -360,7 +332,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
// objects in the scene can be viewed.
viewingPlatform.setNominalViewingTransform();
- view = univ.getViewer().getView();
+ //view = univ.getViewer().getView();
return c;
}
@@ -413,6 +385,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
setTitle("Window Title");
addWindowListener(new java.awt.event.WindowAdapter() {
+ @Override
public void windowClosing(java.awt.event.WindowEvent evt)
{
exitForm(evt);
@@ -430,6 +403,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
densityButtonGroup.add(zeroButton);
zeroButton.setText("Zero");
zeroButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
zeroButtonActionPerformed(evt);
@@ -443,6 +417,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
densityButtonGroup.add(halfButton);
halfButton.setText("Half");
halfButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
halfButtonActionPerformed(evt);
@@ -459,6 +434,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
fullButton.setSelected(true);
fullButton.setText("Full");
fullButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
fullButtonActionPerformed(evt);
@@ -481,6 +457,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
goldButton.setSelected(true);
goldButton.setText("Gold");
goldButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
goldButtonActionPerformed(evt);
@@ -494,6 +471,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
colorButtonGroup.add(silverButton);
silverButton.setText("Silver");
silverButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
silverButtonActionPerformed(evt);
@@ -515,6 +493,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
DetachButton.setSelected(true);
DetachButton.setText("Detach");
DetachButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
DetachButtonActionPerformed(evt);
@@ -528,6 +507,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
sceneGraphButtonGroup.add(AttachButton);
AttachButton.setText("Create");
AttachButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
AttachButtonActionPerformed(evt);
@@ -543,6 +523,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
replaceSPButton.setText("Replace Shader");
replaceSPButton.setEnabled(false);
replaceSPButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
replaceSPButtonActionPerformed(evt);
@@ -569,6 +550,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
fileMenu.setText("File");
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
exitMenuItemActionPerformed(evt);
@@ -698,13 +680,13 @@ public class ShaderTestGLSL extends javax.swing.JFrame
}//GEN-LAST:event_zeroButtonActionPerformed
- private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt)
+ private static 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)
+ private static void exitForm(java.awt.event.WindowEvent evt)
{//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java
index f06f9e9..5b7be75 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
package org.jdesktop.j3d.examples.gl2es2pipeline;
import org.jogamp.java3d.ColoringAttributes;
@@ -14,7 +35,6 @@ import org.jogamp.java3d.SourceCodeShader;
import org.jogamp.vecmath.Color3f;
/**
- * Note all of these are no lighting shaders, so materials are always ignored
* @author phil
*
*/
@@ -23,6 +43,8 @@ public class SimpleShaderAppearance extends ShaderAppearance
private static GLSLShaderProgram flatShaderProgram;
private static GLSLShaderProgram textureShaderProgram;
private static GLSLShaderProgram colorLineShaderProgram;
+ private static GLSLShaderProgram litFlatShaderProgram;
+ private static GLSLShaderProgram litTextureShaderProgram;
public static String alphaTestUniforms = "uniform int alphaTestEnabled;\n" + //
"uniform int alphaTestFunction;\n" + //
@@ -51,7 +73,7 @@ public class SimpleShaderAppearance extends ShaderAppearance
*/
public SimpleShaderAppearance()
{
- this(null, false);
+ this(null, false, false);
}
/**
@@ -60,7 +82,7 @@ public class SimpleShaderAppearance extends ShaderAppearance
*/
public SimpleShaderAppearance(Color3f color)
{
- this(color, false);
+ this(color, false, false);
}
/**
@@ -68,161 +90,364 @@ public class SimpleShaderAppearance extends ShaderAppearance
*/
public SimpleShaderAppearance(boolean hasTexture)
{
- this(null, hasTexture);
+ this(null, false, hasTexture);
+ }
+
+ public SimpleShaderAppearance(boolean lit, boolean hasTexture)
+ {
+ this(null, lit, hasTexture);
}
/** if color is not null then a line appearance
* otherwise simple poly appearance
* @param color
*/
- private SimpleShaderAppearance(Color3f color, boolean hasTexture)
+ private SimpleShaderAppearance(Color3f color, boolean lit, boolean hasTexture)
{
- if (hasTexture)
+ if (lit)
{
- RenderingAttributes ra = new RenderingAttributes();
- setRenderingAttributes(ra);
-
- if (textureShaderProgram == null)
+ String vertexProgram = "#version 120\n";
+ vertexProgram += "attribute vec4 glVertex;\n";
+ vertexProgram += "attribute vec4 glColor;\n";
+ vertexProgram += "attribute vec3 glNormal; \n";
+ if (hasTexture)
{
- textureShaderProgram = new GLSLShaderProgram() {
- @Override
- public String toString()
- {
- return "SimpleShaderAppearance textureShaderProgram";
- }
- };
- String vertexProgram = "#version 120\n";
- vertexProgram += "attribute vec4 glVertex;\n";
vertexProgram += "attribute vec2 glMultiTexCoord0;\n";
- vertexProgram += "uniform mat4 glModelViewProjectionMatrix;\n";
+ }
+ vertexProgram += "uniform mat4 glModelViewProjectionMatrix;\n";
+ vertexProgram += "uniform mat4 glModelViewMatrix;\n";
+ vertexProgram += "uniform mat3 glNormalMatrix;\n";
+ vertexProgram += "uniform int ignoreVertexColors;\n";
+ vertexProgram += "uniform vec4 glLightModelambient;\n";
+ vertexProgram += "struct material\n";
+ vertexProgram += "{\n";
+ vertexProgram += " int lightEnabled;\n";
+ vertexProgram += " vec4 ambient;\n";
+ vertexProgram += " vec4 diffuse;\n";
+ vertexProgram += " vec4 emission; \n";
+ vertexProgram += " vec3 specular;\n";
+ vertexProgram += " float shininess;\n";
+ vertexProgram += "};\n";
+ vertexProgram += "uniform material glFrontMaterial;\n";
+ vertexProgram += "struct lightSource\n";
+ vertexProgram += " {\n";
+ vertexProgram += " int enabled;\n";
+ vertexProgram += " vec4 position;\n";
+ vertexProgram += " vec4 diffuse;\n";
+ vertexProgram += " vec4 specular;\n";
+ vertexProgram += " float constantAttenuation, linearAttenuation, quadraticAttenuation;\n";
+ vertexProgram += " float spotCutoff, spotExponent;\n";
+ vertexProgram += " vec3 spotDirection;\n";
+ vertexProgram += " };\n";
+ vertexProgram += "\n";
+ vertexProgram += " uniform int numberOfLights;\n";
+ vertexProgram += " const int maxLights = 1;\n";
+ vertexProgram += " uniform lightSource glLightSource[maxLights];\n";
+ if (hasTexture)
+ {
vertexProgram += "varying vec2 glTexCoord0;\n";
- vertexProgram += "void main( void ){\n";
- vertexProgram += "gl_Position = glModelViewProjectionMatrix * glVertex;\n";
+ }
+ vertexProgram += "varying vec3 LightDir;\n";
+ vertexProgram += "varying vec3 ViewDir;\n";
+ vertexProgram += "varying vec3 N;\n";
+ vertexProgram += "varying vec4 A;\n";
+ vertexProgram += "varying vec4 C;\n";
+ vertexProgram += "varying vec4 D;\n";
+ vertexProgram += "varying vec3 emissive;\n";
+ vertexProgram += "varying vec3 specular;\n";
+ vertexProgram += "varying float shininess;\n";
+ vertexProgram += "void main( void ){\n";
+ vertexProgram += "gl_Position = glModelViewProjectionMatrix * glVertex;\n";
+ if (hasTexture)
+ {
vertexProgram += "glTexCoord0 = glMultiTexCoord0.st;\n";
- vertexProgram += "}";
+ }
+
+ vertexProgram += "N = normalize(glNormalMatrix * glNormal);\n";
+
+ vertexProgram += "vec3 v = vec3(glModelViewMatrix * glVertex);\n";
+
+ vertexProgram += "ViewDir = -v.xyz;\n";
+ vertexProgram += "LightDir = glLightSource[0].position.xyz;\n";
- String fragmentProgram = "#version 120\n";
- fragmentProgram += "precision mediump float;\n";
+ vertexProgram += "A = glLightModelambient * glFrontMaterial.ambient;\n";
+ vertexProgram += "if( ignoreVertexColors != 0) \n";
+ // objectColor should be used if it is no lighting, and reusing material diffuse appears wrong
+ vertexProgram += " C = vec4(1,1,1,1);//glFrontMaterial.diffuse; \n";
+ vertexProgram += "else \n";
+ vertexProgram += " C = glColor; \n";
+
+ vertexProgram += "D = glLightSource[0].diffuse * glFrontMaterial.diffuse;\n";
+
+ vertexProgram += "emissive = glFrontMaterial.emission.rgb;\n";
+ vertexProgram += "specular = glFrontMaterial.specular;\n";
+ vertexProgram += "shininess = glFrontMaterial.shininess;\n";
+ vertexProgram += "}";
+
+ String fragmentProgram = "#version 120\n";
+ fragmentProgram += "precision mediump float;\n";
+ if (hasTexture)
+ {
fragmentProgram += alphaTestUniforms;
+
fragmentProgram += "varying vec2 glTexCoord0;\n";
fragmentProgram += "uniform sampler2D BaseMap;\n";
- fragmentProgram += "void main( void ){\n ";
+ }
+
+ fragmentProgram += "in vec3 LightDir;\n";
+ fragmentProgram += "in vec3 ViewDir;\n";
+
+ fragmentProgram += "in vec3 N;\n";
+
+ fragmentProgram += "in vec4 A;\n";
+ fragmentProgram += "in vec4 C;\n";
+ fragmentProgram += "in vec4 D;\n";
+
+ fragmentProgram += "in vec3 emissive;\n";
+ fragmentProgram += "in vec3 specular;\n";
+ fragmentProgram += "in float shininess;\n";
+ fragmentProgram += "void main( void ){\n ";
+ if (hasTexture)
+ {
fragmentProgram += "vec4 baseMap = texture2D( BaseMap, glTexCoord0.st );\n";
+ }
+ if (hasTexture)
+ {
fragmentProgram += alphaTestMethod;
- fragmentProgram += "gl_FragColor = baseMap;\n";
- fragmentProgram += "}";
-
- textureShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
- textureShaderProgram.setShaderAttrNames(new String[] { "BaseMap" });
}
+ fragmentProgram += "vec3 normal = N;\n";
- setShaderProgram(textureShaderProgram);
+ fragmentProgram += "vec3 L = normalize(LightDir);\n";
+ fragmentProgram += "vec3 E = normalize(ViewDir);\n";
+ fragmentProgram += "vec3 R = reflect(-L, normal);\n";
+ fragmentProgram += "vec3 H = normalize( L + E );\n";
- ShaderAttributeSet shaderAttributeSet = new ShaderAttributeSet();
- shaderAttributeSet.put(new ShaderAttributeValue("BaseMap", new Integer(0)));
- setShaderAttributeSet(shaderAttributeSet);
+ fragmentProgram += "float NdotL = max( dot(normal, L), 0.0 );\n";
+ fragmentProgram += "float NdotH = max( dot(normal, H), 0.0 );\n";
+ fragmentProgram += "float EdotN = max( dot(normal, E), 0.0 );\n";
+ fragmentProgram += "float NdotNegL = max( dot(normal, -L), 0.0 );\n";
- }
- else
- {
- if (color != null)
+ fragmentProgram += "vec4 color;\n";
+ if (hasTexture)
+ {
+ fragmentProgram += "vec3 albedo = baseMap.rgb * C.rgb;\n";
+ }
+ else
{
- PolygonAttributes polyAtt = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0.0f);
- polyAtt.setPolygonOffset(0.1f);
- setPolygonAttributes(polyAtt);
- LineAttributes lineAtt = new LineAttributes(1, LineAttributes.PATTERN_SOLID, false);
- setLineAttributes(lineAtt);
+ fragmentProgram += "vec3 albedo = C.rgb;\n";
+ }
+ fragmentProgram += "vec3 diffuse = A.rgb + (D.rgb * NdotL);\n";
- ColoringAttributes colorAtt = new ColoringAttributes(color, ColoringAttributes.FASTEST);
- setColoringAttributes(colorAtt);
+ // 0.3 is just what the calc is
+ fragmentProgram += "vec3 spec = specular * pow(NdotH, 0.3*shininess);\n";
+ // D is not right it should be the light source spec color, probably just 1,1,1 but java3d has no spec on lights
+ //fragmentProgram += "spec *= D.rgb;\n";
- RenderingAttributes ra = new RenderingAttributes();
- ra.setIgnoreVertexColors(true);
- setRenderingAttributes(ra);
+ fragmentProgram += "color.rgb = albedo * (diffuse + emissive) + spec;\n";
+ if (hasTexture)
+ {
+ fragmentProgram += "color.a = C.a * baseMap.a;\n";
+ }
+ else
+ {
+ fragmentProgram += "color.a = C.a;\n";
+ }
- Material mat = new Material();
- setMaterial(mat);
+ fragmentProgram += "gl_FragColor = color;\n";
- if (colorLineShaderProgram == null)
+ fragmentProgram += "}";
+ if (hasTexture)
+ {
+ if (litTextureShaderProgram == null)
{
- colorLineShaderProgram = new GLSLShaderProgram() {
+ litTextureShaderProgram = new GLSLShaderProgram() {
@Override
public String toString()
{
- return "SimpleShaderAppearance colorLineShaderProgram";
+ return "SimpleShaderAppearance litTextureShaderProgram";
}
};
- String vertexProgram = "#version 120\n";
- vertexProgram += "attribute vec4 glVertex;\n";
- vertexProgram += "attribute vec4 glColor;\n";
- vertexProgram += "uniform int ignoreVertexColors;\n";
- vertexProgram += "uniform vec4 objectColor;\n";
- vertexProgram += "uniform mat4 glModelViewProjectionMatrix;\n";
- vertexProgram += "varying vec4 glFrontColor;\n";
- vertexProgram += "void main( void ){\n";
- vertexProgram += "gl_Position = glModelViewProjectionMatrix * glVertex;\n";
- vertexProgram += "if( ignoreVertexColors != 0 )\n";
- vertexProgram += " glFrontColor = objectColor;\n";
- vertexProgram += "else\n";
- vertexProgram += " glFrontColor = glColor;\n";
- vertexProgram += "}";
-
- String fragmentProgram = "#version 120\n";
- fragmentProgram += "precision mediump float;\n";
- fragmentProgram += "varying vec4 glFrontColor;\n";
- fragmentProgram += "void main( void ){\n";
- fragmentProgram += "gl_FragColor = glFrontColor;\n";
- fragmentProgram += "}";
+ litTextureShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
+ litTextureShaderProgram.setShaderAttrNames(new String[] { "BaseMap" });
- colorLineShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
}
- setShaderProgram(colorLineShaderProgram);
+ setShaderProgram(litTextureShaderProgram);
+ ShaderAttributeSet shaderAttributeSet = new ShaderAttributeSet();
+ shaderAttributeSet.put(new ShaderAttributeValue("BaseMap", new Integer(0)));
+ setShaderAttributeSet(shaderAttributeSet);
}
else
{
- RenderingAttributes ra = new RenderingAttributes();
- setRenderingAttributes(ra);
+ if (litFlatShaderProgram == null)
+ {
+ litFlatShaderProgram = new GLSLShaderProgram() {
+ @Override
+ public String toString()
+ {
+ return "SimpleShaderAppearance litFlatShaderProgram";
+ }
+ };
+ litFlatShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
- if (flatShaderProgram == null)
+ //System.out.println("vertexProgram " + vertexProgram);
+ //System.out.println("fragmentProgram " + fragmentProgram);
+
+ }
+
+ setShaderProgram(litFlatShaderProgram);
+
+ }
+ }
+ else
+ {
+ if (hasTexture)
+ {
+ if (textureShaderProgram == null)
{
- flatShaderProgram = new GLSLShaderProgram() {
+ textureShaderProgram = new GLSLShaderProgram() {
@Override
public String toString()
{
- return "SimpleShaderAppearance flatShaderProgram";
+ return "SimpleShaderAppearance textureShaderProgram";
}
};
String vertexProgram = "#version 120\n";
vertexProgram += "attribute vec4 glVertex;\n";
- vertexProgram += "attribute vec4 glColor;\n";
- vertexProgram += "uniform int ignoreVertexColors;\n";
- vertexProgram += "uniform vec4 objectColor;\n";
+ vertexProgram += "attribute vec2 glMultiTexCoord0;\n";
vertexProgram += "uniform mat4 glModelViewProjectionMatrix;\n";
- vertexProgram += "varying vec4 glFrontColor;\n";
+ vertexProgram += "varying vec2 glTexCoord0;\n";
vertexProgram += "void main( void ){\n";
vertexProgram += "gl_Position = glModelViewProjectionMatrix * glVertex;\n";
- vertexProgram += "if( ignoreVertexColors != 0 )\n";
- vertexProgram += " glFrontColor = objectColor;\n";
- vertexProgram += "else\n";
- vertexProgram += " glFrontColor = glColor;\n";
+ vertexProgram += "glTexCoord0 = glMultiTexCoord0.st;\n";
vertexProgram += "}";
String fragmentProgram = "#version 120\n";
fragmentProgram += "precision mediump float;\n";
- fragmentProgram += "varying vec4 glFrontColor;\n";
- fragmentProgram += "void main( void ){\n";
- fragmentProgram += "gl_FragColor = glFrontColor;\n";
+ fragmentProgram += alphaTestUniforms;
+ fragmentProgram += "varying vec2 glTexCoord0;\n";
+ fragmentProgram += "uniform sampler2D BaseMap;\n";
+ fragmentProgram += "void main( void ){\n ";
+ fragmentProgram += "vec4 baseMap = texture2D( BaseMap, glTexCoord0.st );\n";
+ fragmentProgram += alphaTestMethod;
+ fragmentProgram += "gl_FragColor = baseMap;\n";
fragmentProgram += "}";
- flatShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
+ textureShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
+ textureShaderProgram.setShaderAttrNames(new String[] { "BaseMap" });
+ }
+
+ setShaderProgram(textureShaderProgram);
+
+ ShaderAttributeSet shaderAttributeSet = new ShaderAttributeSet();
+ shaderAttributeSet.put(new ShaderAttributeValue("BaseMap", new Integer(0)));
+ setShaderAttributeSet(shaderAttributeSet);
+
+ }
+ else
+
+ {
+ if (color != null)
+ {
+ PolygonAttributes polyAtt = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0.0f);
+ polyAtt.setPolygonOffset(0.1f);
+ setPolygonAttributes(polyAtt);
+ LineAttributes lineAtt = new LineAttributes(1, LineAttributes.PATTERN_SOLID, false);
+ setLineAttributes(lineAtt);
+
+ ColoringAttributes colorAtt = new ColoringAttributes(color, ColoringAttributes.FASTEST);
+ setColoringAttributes(colorAtt);
+
+ RenderingAttributes ra = new RenderingAttributes();
+ ra.setIgnoreVertexColors(true);
+ setRenderingAttributes(ra);
+
+ Material mat = new Material();
+ setMaterial(mat);
+
+ if (colorLineShaderProgram == null)
+ {
+ colorLineShaderProgram = new GLSLShaderProgram() {
+ @Override
+ public String toString()
+ {
+ return "SimpleShaderAppearance colorLineShaderProgram";
+ }
+ };
+ String vertexProgram = "#version 120\n";
+ vertexProgram += "attribute vec4 glVertex;\n";
+ vertexProgram += "attribute vec4 glColor;\n";
+ vertexProgram += "uniform int ignoreVertexColors;\n";
+ vertexProgram += "uniform vec4 objectColor;\n";
+ vertexProgram += "uniform mat4 glModelViewProjectionMatrix;\n";
+ vertexProgram += "varying vec4 glFrontColor;\n";
+ vertexProgram += "void main( void ){\n";
+ vertexProgram += "gl_Position = glModelViewProjectionMatrix * glVertex;\n";
+ vertexProgram += "if( ignoreVertexColors != 0 )\n";
+ vertexProgram += " glFrontColor = objectColor;\n";
+ vertexProgram += "else\n";
+ vertexProgram += " glFrontColor = glColor;\n";
+ vertexProgram += "}";
+
+ String fragmentProgram = "#version 120\n";
+ fragmentProgram += "precision mediump float;\n";
+ fragmentProgram += "varying vec4 glFrontColor;\n";
+ fragmentProgram += "void main( void ){\n";
+ fragmentProgram += "gl_FragColor = glFrontColor;\n";
+ fragmentProgram += "}";
+
+ colorLineShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
+ }
+
+ setShaderProgram(colorLineShaderProgram);
}
+ else
+ {
+ RenderingAttributes ra = new RenderingAttributes();
+ setRenderingAttributes(ra);
+
+ if (flatShaderProgram == null)
+ {
+ flatShaderProgram = new GLSLShaderProgram() {
+ @Override
+ public String toString()
+ {
+ return "SimpleShaderAppearance flatShaderProgram";
+ }
+ };
+ String vertexProgram = "#version 120\n";
+ vertexProgram += "attribute vec4 glVertex;\n";
+ vertexProgram += "attribute vec4 glColor;\n";
+ vertexProgram += "uniform int ignoreVertexColors;\n";
+ vertexProgram += "uniform vec4 objectColor;\n";
+ vertexProgram += "uniform mat4 glModelViewProjectionMatrix;\n";
+ vertexProgram += "varying vec4 glFrontColor;\n";
+ vertexProgram += "void main( void ){\n";
+ vertexProgram += "gl_Position = glModelViewProjectionMatrix * glVertex;\n";
+ vertexProgram += "if( ignoreVertexColors != 0 )\n";
+ vertexProgram += " glFrontColor = objectColor;\n";
+ vertexProgram += "else\n";
+ vertexProgram += " glFrontColor = glColor;\n";
+ vertexProgram += "}";
- setShaderProgram(flatShaderProgram);
+ String fragmentProgram = "#version 120\n";
+ fragmentProgram += "precision mediump float;\n";
+ fragmentProgram += "varying vec4 glFrontColor;\n";
+ fragmentProgram += "void main( void ){\n";
+ fragmentProgram += "gl_FragColor = glFrontColor;\n";
+ fragmentProgram += "}";
+ flatShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
+
+ }
+
+ setShaderProgram(flatShaderProgram);
+
+ }
}
+
}
}
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SphereGLSL.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SphereGLSL.java
index 61069f7..8a59c5f 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SphereGLSL.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SphereGLSL.java
@@ -1,45 +1,23 @@
/*
- * $RCSfile$
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
*
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * - 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.gl2es2pipeline;
@@ -198,8 +176,8 @@ public class SphereGLSL extends javax.swing.JFrame
caL1.setColor(lColor1);
caL2.setColor(lColor2);
- Appearance appL1 = makeGouraudShaderAppearance();
- Appearance appL2 = makeGouraudShaderAppearance();
+ Appearance appL1 = new SimpleShaderAppearance(false, false);
+ Appearance appL2 = new SimpleShaderAppearance(false, false);
appL1.setColoringAttributes(caL1);
appL2.setColoringAttributes(caL2);
@@ -285,41 +263,6 @@ public class SphereGLSL extends javax.swing.JFrame
return objRoot;
}
- /**
- * GL2ES2: this should be a trivial emissive color shader, but gouraud will do for now
- * @return
- */
- private Appearance makeGouraudShaderAppearance()
- {
- // Create a Sphere object, generate one copy of the sphere,
- // and add it into the scene graph.
- ShaderAppearance a = new ShaderAppearance();
- Material m = new Material();
- m.setLightingEnable(true);
- String vertexProgram = null;
- String fragmentProgram = null;
- try
- {
- vertexProgram = StringIO.readFully(
- new File(System.getProperty("user.dir") + "/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert"));
- fragmentProgram = StringIO.readFully(
- new File(System.getProperty("user.dir") + "/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.frag"));
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- Shader[] shaders = new Shader[2];
- shaders[0] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_VERTEX, vertexProgram);
- shaders[1] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_FRAGMENT, fragmentProgram);
- ShaderProgram shaderProgram = new GLSLShaderProgram();
- shaderProgram.setShaders(shaders);
-
- a.setShaderProgram(shaderProgram);
- a.setMaterial(m);
- return a;
- }
-
private Canvas3D createUniverse()
{
// Get the preferred graphics configuration for the default screen
@@ -330,10 +273,11 @@ public class SphereGLSL extends javax.swing.JFrame
// Create simple universe with view branch
univ = new SimpleUniverse(canvas3d);
- BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
+ //BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
// Add a ShaderErrorListener
univ.addShaderErrorListener(new ShaderErrorListener() {
+ @Override
public void errorOccurred(ShaderError error)
{
error.printVerbose();
@@ -399,6 +343,7 @@ public class SphereGLSL extends javax.swing.JFrame
System.setProperty("sun.awt.noerasebackground", "true");
System.setProperty("j3d.rend", "jogl2es2");
java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
public void run()
{
SphereGLSL sphereGLSL = new SphereGLSL();
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/VertexAttrTestGLSL.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/VertexAttrTestGLSL.java
index 96bc0c9..f80ac11 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/VertexAttrTestGLSL.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/VertexAttrTestGLSL.java
@@ -1,45 +1,23 @@
/*
- * $RCSfile$
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
*
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * - 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.gl2es2pipeline;
@@ -122,6 +100,7 @@ public class VertexAttrTestGLSL extends javax.swing.JFrame
// Add a ShaderErrorListener
univ.addShaderErrorListener(new ShaderErrorListener() {
+ @Override
public void errorOccurred(ShaderError error)
{
error.printVerbose();
@@ -272,6 +251,7 @@ public class VertexAttrTestGLSL extends javax.swing.JFrame
setTitle("VertexAttrTestGLSL");
addWindowListener(new java.awt.event.WindowAdapter() {
+ @Override
public void windowClosing(java.awt.event.WindowEvent evt)
{
exitForm(evt);
@@ -329,6 +309,7 @@ public class VertexAttrTestGLSL extends javax.swing.JFrame
createButton.setText("Create Geometry");
createButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
createButtonActionPerformed(evt);
@@ -341,6 +322,7 @@ public class VertexAttrTestGLSL extends javax.swing.JFrame
destroyButton.setText("Destroy Geometry");
destroyButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
destroyButtonActionPerformed(evt);
@@ -370,6 +352,7 @@ public class VertexAttrTestGLSL extends javax.swing.JFrame
fileMenu.setText("File");
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
exitMenuItemActionPerformed(evt);
@@ -404,13 +387,13 @@ public class VertexAttrTestGLSL extends javax.swing.JFrame
}
}//GEN-LAST:event_createButtonActionPerformed
- private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt)
+ private static 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)
+ private static void exitForm(java.awt.event.WindowEvent evt)
{//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm
@@ -423,6 +406,7 @@ public class VertexAttrTestGLSL extends javax.swing.JFrame
System.setProperty("sun.awt.noerasebackground", "true");
System.setProperty("j3d.rend","jogl2es2");
java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
public void run()
{
new VertexAttrTestGLSL().setVisible(true);
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/dimple.vert b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/dimple.vert
index 9b06148..ebbfdc9 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/dimple.vert
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/dimple.vert
@@ -18,7 +18,6 @@ uniform mat4 glModelViewMatrix;
uniform mat4 glModelViewProjectionMatrix;
uniform mat3 glNormalMatrix;
-uniform vec4 glFrontMaterialdiffuse;
uniform int ignoreVertexColors;
// GL2ES2: new output varyings, these replace gl_TexCoord[] and gl_FrontColor (along with A and D)
@@ -52,7 +51,7 @@ void main(void)
//gl_FrontColor = gl_Color;
if( ignoreVertexColors != 0)
- C = glFrontMaterialdiffuse;
+ C = vec4(1,1,1,1);
else
C = glColor;
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag
index bdc0fe0..d6f5e96 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag
@@ -7,12 +7,16 @@ uniform int alphaTestEnabled;
uniform int alphaTestFunction;
uniform float alphaTestValue;
-uniform int fogEnabled;
-uniform vec4 expColor;
-uniform float expDensity;
-uniform vec4 linearColor;
-uniform float linearStart;
-uniform float linearEnd;
+struct fogData
+{
+ int fogEnabled = -1;
+ vec3 expColor = new Vector3f();
+ float expDensity;
+ vec3 linearColor = new Vector3f();
+ float linearStart;
+ float linearEnd;
+};
+uniform fogData fogData;
//End of FFP inputs
in vec2 glTexCoord0;
@@ -85,7 +89,7 @@ void main( void )
color.rgb = albedo * (diffuse + emissive) + spec;
color.a = C.a * baseMap.a;
- if(fogEnabled == 1)
+ if(fogData.fogEnabled == 1)
{
//distance
float dist = 0.0;
@@ -94,21 +98,21 @@ void main( void )
//compute distance used in fog equations
dist = length(ViewDir);
- if(linearEnd > 0.0)//linear fog
+ if(fogData.linearEnd > 0.0)//linear fog
{
- fogFactor = (linearEnd - dist)/(linearEnd - linearStart);
+ fogFactor = (fogData.linearEnd - dist)/(fogData.linearEnd - fogData.linearStart);
fogFactor = clamp( fogFactor, 0.0, 1.0 );
//if you inverse color in glsl mix function you have to put 1.0 - fogFactor
- color = mix(linearColor, color, fogFactor);
+ color = mix(fogData.linearColor, color, fogFactor);
}
- else if( expDensity > 0.0)// exponential fog
+ else if( fogData.expDensity > 0.0)// exponential fog
{
- fogFactor = 1.0 /exp(dist * expDensity);
+ fogFactor = 1.0 /exp(dist * fogData.expDensity);
fogFactor = clamp( fogFactor, 0.0, 1.0 );
// mix function fogColor-(1-fogFactor) + lightColor-fogFactor
- color = mix(expColor, color, fogFactor);
+ color = mix(fogData.expColor, color, fogFactor);
}
}
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert
index 184620e..091e33b 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert
@@ -18,17 +18,36 @@ uniform mat4 glModelMatrix;
//uniform mat3 glNormalMatrix;
-//uniform vec4 glFrontMaterialambient;
-uniform vec4 glFrontMaterialdiffuse;
-uniform vec4 glFrontMaterialemission;
-uniform vec3 glFrontMaterialspecular;
-uniform float glFrontMaterialshininess;
+
uniform int ignoreVertexColors;
uniform vec4 glLightModelambient;
-uniform vec4 glLightSource0position;
-uniform vec4 glLightSource0diffuse;
+struct material
+{
+ int lightEnabled;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 emission;// note vec4 extra 1.0 sent through for ease
+ vec3 specular;
+ float shininess;
+};
+uniform material glFrontMaterial;
+
+struct lightSource
+{
+ int enabled;
+ vec4 position;
+ vec4 diffuse;
+ vec4 specular;
+ float constantAttenuation, linearAttenuation, quadraticAttenuation;
+ float spotCutoff, spotExponent;
+ vec3 spotDirection;
+};
+
+uniform int numberOfLights;
+const int maxLights = 1;
+uniform lightSource glLightSource[maxLights];
uniform mat4 textureTransform;
@@ -37,15 +56,17 @@ uniform mat4 textureTransform;
//uniform float alphaTestValue;
-//uniform int fogEnabled;
-//uniform vec4 expColor;
-//uniform float expDensity;
-//uniform vec4 linearColor;
-//uniform float linearStart;
-//uniform float linearEnd;
+ // struct fogData
+ // {
+ // int fogEnabled = -1;
+ // vec3 expColor = new Vector3f();
+ // float expDensity;
+ // vec3 linearColor = new Vector3f();
+ // float linearStart;
+ // float linearEnd;
+ // };
+ // uniform fogData fogData;
-//End of FFP inputs
-//The line above in not optional for parsing reasons
//Fixed function pipeline pre-calculated values not available
//vec3 halfVector = normalize(vec3(gl_LightSource[0].halfVector));
@@ -96,8 +117,8 @@ out float shininess;
void main( void )
{
- mat4 glModelViewMatrix = glViewMatrix*glModelMatrix;
- gl_Position = glProjectionMatrix*glModelViewMatrix * glVertex;//glModelViewProjectionMatrix * glVertex;
+ mat4 glModelViewMatrix = glViewMatrix * glModelMatrix;
+ gl_Position = glProjectionMatrix * glModelViewMatrix * glVertex;//glModelViewProjectionMatrix * glVertex;
glTexCoord0 = (textureTransform * vec4(glMultiTexCoord0,0,1)).st;
@@ -107,17 +128,17 @@ void main( void )
vec3 v = vec3(glModelViewMatrix * glVertex);
ViewDir = -v.xyz;
- LightDir = glLightSource0position.xyz;
+ LightDir = glLightSource[0].position.xyz;
A = glLightModelambient;
if( ignoreVertexColors != 0)
- C = glFrontMaterialdiffuse; // objectColor should be used if it is no lighting
+ C = vec4(1,1,1,1);//glFrontMaterialdiffuse; // objectColor should be used if it is no lighting
else
C = glColor;
- D = glLightSource0diffuse * glFrontMaterialdiffuse;
+ D = glLightSource[0].diffuse * glFrontMaterial.diffuse;
- emissive = glFrontMaterialemission.rgb;
- specular = glFrontMaterialspecular;
- shininess = glFrontMaterialshininess;
+ emissive = glFrontMaterial.emission.rgb;
+ specular = glFrontMaterial.specular;
+ shininess = glFrontMaterial.shininess;
}
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert
index 81d9c95..771afce 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert
@@ -54,16 +54,35 @@ uniform mat4 glModelViewMatrix;
uniform mat4 glModelViewProjectionMatrix;
uniform mat3 glNormalMatrix;
-uniform vec4 glFrontMaterialambient;
-uniform vec4 glFrontMaterialdiffuse;
-uniform vec4 glFrontMaterialemission;
-uniform vec3 glFrontMaterialspecular;
-uniform float glFrontMaterialshininess;
+
uniform vec4 glLightModelambient;
-uniform vec4 glLightSource0position;
-uniform vec4 glLightSource0diffuse;
+struct material
+{
+ int lightEnabled;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 emission;// note vec4 extra 1.0 sent through for ease
+ vec3 specular;
+ float shininess;
+};
+uniform material glFrontMaterial;
+
+struct lightSource
+{
+ int enabled;
+ vec4 position;
+ vec4 diffuse;
+ vec4 specular;
+ float constantAttenuation, linearAttenuation, quadraticAttenuation;
+ float spotCutoff, spotExponent;
+ vec3 spotDirection;
+};
+
+uniform int numberOfLights;
+const int maxLights = 1;
+uniform lightSource glLightSource[maxLights];
//GL2ES2: varying color data needs to be defined
varying vec4 glFrontColor;
@@ -76,17 +95,17 @@ void directionalLight0(
inout vec3 specular)
{
// Normalized light direction and half vector
- vec3 lightDirection = normalize(vec3(glLightSource0position));
+ vec3 lightDirection = normalize(vec3(glLightSource[0].position));
//GL2ES2: half vector must be calculated
//vec3 halfVector = normalize(vec3(gl_LightSource[0].halfVector));
//http://stackoverflow.com/questions/3744038/what-is-half-vector-in-modern-glsl
vec3 ecPos = vec3(glModelViewMatrix * glVertex);
vec3 ecL;
- if( glLightSource0position.w == 0.0)
- ecL = vec3(glLightSource0position.xyz);// no -ecPos in case of dir lights?
+ if( glLightSource[0].position.w == 0.0)
+ ecL = vec3(glLightSource[0].position.xyz);// no -ecPos in case of dir lights?
else
- ecL = vec3(glLightSource0position.xyz - ecPos);
+ ecL = vec3(glLightSource[0].position.xyz - ecPos);
vec3 L = normalize(ecL.xyz);
vec3 V = -ecPos.xyz;
vec3 halfVector = normalize(L + V);
@@ -102,12 +121,12 @@ void directionalLight0(
pf = 0.0;
}
else {
- pf = pow(nDotHV, glFrontMaterialshininess);
+ pf = pow(nDotHV, glFrontMaterial.shininess);
}
ambient += glLightModelambient;
- diffuse += glLightSource0diffuse * nDotVP;
- specular += glFrontMaterialspecular * pf;
+ diffuse += glLightSource[0].diffuse * nDotVP;
+ specular += glFrontMaterial.specular * pf;
}
@@ -125,13 +144,13 @@ void main()
directionalLight0(tnorm, amb, diff, spec);
//GL2ES2: sceneColor Derived. Ecm + Acm * Acs (Acs is normal glLightModelambient)
- vec4 sceneColor = glFrontMaterialemission + glFrontMaterialambient * glLightModelambient;
+ vec4 sceneColor = glFrontMaterial.emission + glFrontMaterial.ambient * glLightModelambient;
// Apply the result of the lighting equation
- vec4 outSecondaryColor = vec4(vec3(spec * glFrontMaterialspecular), 1.0);
+ vec4 outSecondaryColor = vec4(vec3(spec * glFrontMaterial.specular), 1.0);
vec4 outColor = vec4(vec3( sceneColor +
- amb * glFrontMaterialambient +
- diff * glFrontMaterialdiffuse), 1.0);
+ amb * glFrontMaterial.ambient +
+ diff * glFrontMaterial.diffuse), 1.0);
glFrontColor = outColor;
glFrontSecondaryColor = outSecondaryColor;
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag
index 230288a..7cb6388 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag
@@ -48,15 +48,35 @@
// GL2ES2: Java3D built-in uniforms, these are calculated and passsed in if declared here
uniform mat4 glModelViewMatrix;
-
-uniform vec4 glLightSource0position;
-uniform vec4 glLightSource0diffuse;
+
uniform vec4 glLightModelambient;
-uniform vec4 glFrontMaterialdiffuse;
-uniform float glFrontMaterialshininess;
-uniform vec3 glFrontMaterialspecular;
+struct material
+{
+ int lightEnabled;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 emission;
+ vec3 specular;
+ float shininess;
+};
+uniform material glFrontMaterial;
+
+struct lightSource
+{
+ int enabled;
+ vec4 position;
+ vec4 diffuse;
+ vec4 specular;
+ float constantAttenuation, linearAttenuation, quadraticAttenuation;
+ float spotCutoff, spotExponent;
+ vec3 spotDirection;
+};
+
+uniform int numberOfLights;
+const int maxLights = 1;
+uniform lightSource glLightSource[maxLights];
varying vec3 worldPos;
@@ -65,7 +85,7 @@ varying vec4 sceneColor;
void directionalLight0(in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec3 specular)
{
// Normalized light direction and half vector
- vec3 lightDirection = normalize(vec3(glLightSource0position));
+ vec3 lightDirection = normalize(vec3(glLightSource[0].position));
//GL2ES2: half vector must be calculated
@@ -73,10 +93,10 @@ void directionalLight0(in vec3 normal, inout vec4 ambient, inout vec4 diffuse,
//http://stackoverflow.com/questions/3744038/what-is-half-vector-in-modern-glsl
vec3 ecPos = vec3(glModelViewMatrix * vec4(worldPos,1.0));
vec3 ecL;
- if( glLightSource0position.w == 0.0)
- ecL = vec3(glLightSource0position.xyz);// no -ecPos in case of dir lights?
+ if( glLightSource[0].position.w == 0.0)
+ ecL = vec3(glLightSource[0].position.xyz);// no -ecPos in case of dir lights?
else
- ecL = vec3(glLightSource0position.xyz - ecPos);
+ ecL = vec3(glLightSource[0].position.xyz - ecPos);
vec3 L = normalize(ecL.xyz);
vec3 V = -ecPos.xyz;
vec3 halfVector = normalize(L + V);
@@ -93,17 +113,17 @@ void directionalLight0(in vec3 normal, inout vec4 ambient, inout vec4 diffuse,
pf = 0.0;
}
else {
- pf = pow(nDotHV, glFrontMaterialshininess);
+ pf = pow(nDotHV, glFrontMaterial.shininess);
}
// GL2ES2: ambient is part of light model
//ambient += gl_LightSource[0].ambient;
ambient += glLightModelambient;
- diffuse += glLightSource0diffuse * nDotVP;
+ diffuse += glLightSource[0].diffuse * nDotVP;
// GL2ES2: specular is part of material
//specular += gl_LightSource[0].specular * pf;
- specular += glFrontMaterialspecular * pf;
+ specular += glFrontMaterial.specular * pf;
}
@@ -123,12 +143,12 @@ void main()
// Apply the result of the lighting equation
- vec4 secondaryColor = vec4(spec * glFrontMaterialspecular, 1.0);
+ vec4 secondaryColor = vec4(spec * glFrontMaterial.specular, 1.0);
// GL2ES2: change to calc'ed sceneColor
//vec4 color = vec4(vec3(gl_FrontLightModelProduct.sceneColor +
vec4 color = vec4(vec3(sceneColor +
amb * glLightModelambient +
- diff * glFrontMaterialdiffuse), 1.0);
+ diff * glFrontMaterial.diffuse), 1.0);
gl_FragColor = color + secondaryColor;
}
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.vert b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.vert
index 6d3aeb2..780c2bd 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.vert
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.vert
@@ -56,8 +56,16 @@ uniform mat3 glNormalMatrix;
uniform vec4 glLightModelambient;
-uniform vec4 glFrontMaterialambient;
-uniform vec4 glFrontMaterialemission;
+struct material
+{
+ int lightEnabled;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 emission;
+ vec3 specular;
+ float shininess;
+};
+uniform material glFrontMaterial;
// Per-pixel normal (output to fragment shader)
varying vec3 Normal;
@@ -70,7 +78,7 @@ void main()
{
//GL2ES2: sceneColor Derived. Ecm + Acm * Acs (Acs is normal glLightModelambient)
- sceneColor = glFrontMaterialemission + glFrontMaterialambient * glLightModelambient;
+ sceneColor = glFrontMaterial.emission + glFrontMaterial.ambient * glLightModelambient;
Normal = normalize(vec3(glNormalMatrix * glNormal));
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert
index 93a61bf..4c5f3c9 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert
@@ -55,16 +55,34 @@ uniform mat4 glModelViewMatrix;
uniform mat4 glModelViewProjectionMatrix;
uniform mat3 glNormalMatrix;
-uniform vec4 glFrontMaterialambient;
-uniform vec4 glFrontMaterialdiffuse;
-uniform vec4 glFrontMaterialemission;
-uniform vec3 glFrontMaterialspecular;
-uniform float glFrontMaterialshininess;
-
uniform vec4 glLightModelambient;
-uniform vec4 glLightSource0position;
-uniform vec4 glLightSource0diffuse;
+
+struct material
+{
+ int lightEnabled;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 emission;
+ vec3 specular;
+ float shininess;
+};
+uniform material glFrontMaterial;
+
+struct lightSource
+{
+ int enabled;
+ vec4 position;
+ vec4 diffuse;
+ vec4 specular;
+ float constantAttenuation, linearAttenuation, quadraticAttenuation;
+ float spotCutoff, spotExponent;
+ vec3 spotDirection;
+};
+
+uniform int numberOfLights;
+const int maxLights = 1;
+uniform lightSource glLightSource[maxLights];
//GL2ES2: varying color data needs to be defined
varying vec4 glFrontColor;
@@ -81,12 +99,12 @@ void directionalLight(
// (shouldn't they be pre-normalized?!)
//GL2ES2 notice not using the i parameter but hard coded to 0
- vec3 lightDirection = normalize(vec3(glLightSource0position));
+ vec3 lightDirection = normalize(vec3(glLightSource[0].position));
//GL2ES2: half vector must be calculated
//vec3 halfVector = normalize(vec3(gl_LightSource[0].halfVector));
vec3 worldPos = vec3(glModelViewMatrix * glVertex);
- vec3 L = normalize(glLightSource0position.xyz - worldPos);
+ vec3 L = normalize(glLightSource[0].position.xyz - worldPos);
vec3 V = vec3(0,0,1);//eye position
vec3 halfVector = (L + V);
@@ -103,12 +121,12 @@ void directionalLight(
pf = 0.0;
}
else {
- pf = pow(nDotHV, glFrontMaterialshininess);
+ pf = pow(nDotHV, glFrontMaterial.shininess);
}
ambient += glLightModelambient;
- diffuse += glLightSource0diffuse * nDotVP;
- specular += glFrontMaterialspecular * pf;
+ diffuse += glLightSource[0].diffuse * nDotVP;
+ specular += glFrontMaterial.specular * pf;
}
//GL2ES2: only a single light for now
@@ -136,13 +154,13 @@ void main()
}
//GL2ES2: sceneColor Derived. Ecm + Acm * Acs (Acs is normal glLightModelambient)
- vec4 sceneColor = glFrontMaterialemission + glFrontMaterialambient * glLightModelambient;
+ vec4 sceneColor = glFrontMaterial.emission + glFrontMaterial.ambient * glLightModelambient;
// Apply the result of the lighting equation
- vec4 outSecondaryColor = vec4(vec3(spec * glFrontMaterialspecular), 1.0);
+ vec4 outSecondaryColor = vec4(vec3(spec * glFrontMaterial.specular), 1.0);
vec3 color0 = vec3(sceneColor +
amb * glLightModelambient +
- diff * glFrontMaterialdiffuse);
+ diff * glFrontMaterial.diffuse);
// Generate a pseudo-random noise pattern
vec3 xyz = clamp((outPosition.xyz + 1.0) * 0.5, 0.0, 1.0);
diff --git a/src/classes/org/jdesktop/j3d/examples/hello_universe/HelloUniverseGL2ES2.java b/src/classes/org/jdesktop/j3d/examples/hello_universe/HelloUniverseGL2ES2.java
new file mode 100644
index 0000000..b62906b
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/hello_universe/HelloUniverseGL2ES2.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+package org.jdesktop.j3d.examples.hello_universe;
+
+import java.awt.GraphicsConfiguration;
+
+import org.jdesktop.j3d.examples.gl2es2pipeline.Cube;
+import org.jogamp.java3d.Alpha;
+import org.jogamp.java3d.BoundingSphere;
+import org.jogamp.java3d.BranchGroup;
+import org.jogamp.java3d.Canvas3D;
+import org.jogamp.java3d.RotationInterpolator;
+import org.jogamp.java3d.Transform3D;
+import org.jogamp.java3d.TransformGroup;
+import org.jogamp.java3d.utils.universe.SimpleUniverse;
+import org.jogamp.vecmath.Point3d;
+
+/**
+ * Simple Java 3D example program to display a spinning cube.
+ */
+public class HelloUniverseGL2ES2 extends javax.swing.JFrame
+{
+
+ private SimpleUniverse univ = null;
+ private BranchGroup scene = null;
+
+ public BranchGroup createSceneGraph()
+ {
+ // Create the root of the branch graph
+ BranchGroup objRoot = new BranchGroup();
+
+ // 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 Cube(0.4));
+
+ // Create a new Behavior object that will perform the
+ // desired operation on the specified transform and add
+ // it into the scene graph.
+ Transform3D yAxis = new Transform3D();
+ Alpha rotationAlpha = new Alpha(-1, 4000);
+
+ RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f);
+ BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
+ rotator.setSchedulingBounds(bounds);
+ objRoot.addChild(rotator);
+
+ // Have Java 3D perform optimizations on this scene graph.
+ objRoot.compile();
+
+ return objRoot;
+ }
+
+ private Canvas3D createUniverse()
+ {
+ // Get the preferred graphics configuration for the default screen
+ GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
+
+ // Create a Canvas3D using the preferred configuration
+ Canvas3D c = new Canvas3D(config);
+
+ // 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.
+ univ.getViewingPlatform().setNominalViewingTransform();
+
+ // Ensure at least 5 msec per frame (i.e., < 200Hz)
+ univ.getViewer().getView().setMinimumFrameCycleTime(5);
+
+ return c;
+ }
+
+ /**
+ * Creates new form HelloUniverse
+ */
+ public HelloUniverseGL2ES2()
+ {
+ // 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.
+ */
+ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
+ private void initComponents()
+ {
+ drawingPanel = new javax.swing.JPanel();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle("HelloUniverse GL2ES2");
+ drawingPanel.setLayout(new java.awt.BorderLayout());
+
+ drawingPanel.setPreferredSize(new java.awt.Dimension(250, 250));
+ getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER);
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[])
+ {
+ System.setProperty("sun.awt.noerasebackground", "true");
+ System.setProperty("j3d.rend", "jogl2es2");
+ System.setProperty("j3d.displaylist", "false");
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
+ public void run()
+ {
+ new HelloUniverseGL2ES2().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/jcanvas3d/JCanvas3DExampleGL2ES2.java b/src/classes/org/jdesktop/j3d/examples/jcanvas3d/JCanvas3DExampleGL2ES2.java
new file mode 100644
index 0000000..45dccc0
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/jcanvas3d/JCanvas3DExampleGL2ES2.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+package org.jdesktop.j3d.examples.jcanvas3d;
+
+
+/**
+ * Simple Java 3D example program that displays universes within lightweight swing components, layed in JInternalFrame objects.
+ */
+import java.awt.Toolkit;
+
+public class JCanvas3DExampleGL2ES2 extends javax.swing.JFrame implements java.awt.event.ActionListener
+{
+
+ /**
+ * Creates new form JCanvas3DExample
+ */
+ public JCanvas3DExampleGL2ES2()
+ {
+ initComponents();
+ Toolkit.getDefaultToolkit().setDynamicLayout( true );
+ setDefaultCloseOperation( EXIT_ON_CLOSE );
+ }
+
+ /** 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.
+ */
+ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
+ private void initComponents() {
+ java.awt.GridBagConstraints gridBagConstraints;
+
+ splitPane = new javax.swing.JSplitPane();
+ scrollPane = new javax.swing.JScrollPane();
+ panel = new javax.swing.JPanel();
+ addButton = new javax.swing.JButton();
+ delayCheckBox = new javax.swing.JCheckBox();
+ interactiveCheckBox = new javax.swing.JCheckBox();
+ randomCheckBox = new javax.swing.JCheckBox();
+ desktopPane = new javax.swing.JDesktopPane();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ splitPane.setDividerLocation(300);
+ splitPane.setDividerSize(8);
+ splitPane.setContinuousLayout(true);
+ splitPane.setOneTouchExpandable(true);
+ panel.setLayout(new java.awt.GridBagLayout());
+
+ addButton.setText("Create New Frame");
+ addButton.setToolTipText("Adds a new frame containing an universe into the desktop pane");
+ addButton.addActionListener(this);
+
+ panel.add(addButton, new java.awt.GridBagConstraints());
+
+ delayCheckBox.setText("Resize Delayed");
+ delayCheckBox.setToolTipText("Shows the effect of using a delayed resizing to the internal frames.");
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 1;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ panel.add(delayCheckBox, gridBagConstraints);
+
+ interactiveCheckBox.setSelected(true);
+ interactiveCheckBox.setText("Interactive Cube");
+ interactiveCheckBox.setToolTipText("Tests the use of AWT behaviors on the displayed component.");
+ interactiveCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
+ interactiveCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
+ interactiveCheckBox.addActionListener(this);
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 2;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ panel.add(interactiveCheckBox, gridBagConstraints);
+
+ randomCheckBox.setText("Random start angle");
+ randomCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
+ randomCheckBox.setEnabled(false);
+ randomCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 3;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ panel.add(randomCheckBox, gridBagConstraints);
+
+ scrollPane.setViewportView(panel);
+
+ splitPane.setLeftComponent(scrollPane);
+
+ desktopPane.setBackground(new java.awt.Color(153, 153, 201));
+ desktopPane.setPreferredSize(new java.awt.Dimension(300, 300));
+ splitPane.setRightComponent(desktopPane);
+
+ getContentPane().add(splitPane, java.awt.BorderLayout.CENTER);
+
+ java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
+ setBounds((screenSize.width-1011)/2, (screenSize.height-733)/2, 1011, 733);
+ }
+
+ // Code for dispatching events from components to event handlers.
+
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ if (evt.getSource() == addButton) {
+ JCanvas3DExampleGL2ES2.this.addButtonActionPerformed(evt);
+ }
+ else if (evt.getSource() == interactiveCheckBox) {
+ JCanvas3DExampleGL2ES2.this.interactiveCheckBoxActionPerformed(evt);
+ }
+ }// </editor-fold>//GEN-END:initComponents
+
+ private void interactiveCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_interactiveCheckBoxActionPerformed
+ randomCheckBox.setEnabled( interactiveCheckBox.isSelected() ? false:true );
+ }//GEN-LAST:event_interactiveCheckBoxActionPerformed
+
+ private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
+ JInternalWorldGL2ES2 iWorld;
+ // we create an internal world to be added within the JDesktop.
+ iWorld = new JInternalWorldGL2ES2( interactiveCheckBox.isSelected(),
+ delayCheckBox.isSelected(),
+ randomCheckBox.isSelected() );
+ iWorld.setSize( 256, 256 );
+ iWorld.setLocation( 50, 50 );
+ iWorld.setResizable( true );
+ desktopPane.add( iWorld );
+ iWorld.setVisible(true);
+ }//GEN-LAST:event_addButtonActionPerformed
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[])
+ {System.setProperty("sun.awt.noerasebackground", "true");
+ System.setProperty("j3d.rend", "jogl2es2");
+ System.setProperty("j3d.displaylist", "false");
+ java.awt.EventQueue.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ new JCanvas3DExampleGL2ES2().setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton addButton;
+ private javax.swing.JCheckBox delayCheckBox;
+ private javax.swing.JDesktopPane desktopPane;
+ private javax.swing.JCheckBox interactiveCheckBox;
+ private javax.swing.JPanel panel;
+ private javax.swing.JCheckBox randomCheckBox;
+ private javax.swing.JScrollPane scrollPane;
+ private javax.swing.JSplitPane splitPane;
+ // End of variables declaration//GEN-END:variables
+
+}
diff --git a/src/classes/org/jdesktop/j3d/examples/jcanvas3d/JInternalWorldGL2ES2.java b/src/classes/org/jdesktop/j3d/examples/jcanvas3d/JInternalWorldGL2ES2.java
new file mode 100644
index 0000000..d38dc6e
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/jcanvas3d/JInternalWorldGL2ES2.java
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+package org.jdesktop.j3d.examples.jcanvas3d;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+
+import javax.swing.JInternalFrame;
+
+import org.jdesktop.j3d.examples.gl2es2pipeline.SimpleShaderAppearance;
+import org.jogamp.java3d.Alpha;
+import org.jogamp.java3d.AmbientLight;
+import org.jogamp.java3d.Appearance;
+import org.jogamp.java3d.BoundingSphere;
+import org.jogamp.java3d.BranchGroup;
+import org.jogamp.java3d.DirectionalLight;
+import org.jogamp.java3d.Font3D;
+import org.jogamp.java3d.FontExtrusion;
+import org.jogamp.java3d.GraphicsConfigTemplate3D;
+import org.jogamp.java3d.Material;
+import org.jogamp.java3d.RotationInterpolator;
+import org.jogamp.java3d.Shape3D;
+import org.jogamp.java3d.Text3D;
+import org.jogamp.java3d.Transform3D;
+import org.jogamp.java3d.TransformGroup;
+import org.jogamp.java3d.exp.swing.JCanvas3D;
+import org.jogamp.java3d.utils.behaviors.mouse.MouseRotate;
+import org.jogamp.java3d.utils.universe.SimpleUniverse;
+import org.jogamp.vecmath.Color3f;
+import org.jogamp.vecmath.Point3d;
+import org.jogamp.vecmath.Point3f;
+import org.jogamp.vecmath.Vector3d;
+import org.jogamp.vecmath.Vector3f;
+
+
+/**
+ * This is a JInternalFrame holding an universe, which can be configured to
+ * be interactive -that is, where user can interact with object- or automatic
+ * -where the object spins only-. When in automatic mode, spinning speed is
+ * changed so that they look less the same. Changing the spinning start angle
+ * helps unsynchronizing the rotations too.
+ *
+ * @author pepe
+ */
+public class JInternalWorldGL2ES2 extends JInternalFrame {
+ /** DOCUMENT ME! */
+ private Component comp;
+
+ /**
+ * Creates a new JInternalWorld object.
+ *
+ * @param isInteractive tells the world to be constructed as interactive
+ * @param isDelayed tells the rotator to start at a random alpha.
+ */
+ public JInternalWorldGL2ES2(boolean isInteractive, boolean isDelayed, boolean isRandom) {
+ super();
+ setSize(256, 256);
+ setClosable(true);
+
+ JCanvas3D canvas = new JCanvas3D(new GraphicsConfigTemplate3D());
+
+ if (true == isDelayed) {
+ canvas.setResizeMode(canvas.RESIZE_DELAYED);
+ }
+
+ comp = canvas;
+
+ Dimension dim = new Dimension(256, 256);
+ comp.setPreferredSize(dim);
+ comp.setSize(dim);
+ getContentPane().setLayout(new BorderLayout());
+ getContentPane().add(comp, BorderLayout.CENTER);
+ pack();
+
+ // Create a simple scene and attach it to the virtual universe
+ BranchGroup scene = createSceneGraph(isInteractive, isRandom);
+ SimpleUniverse universe = new SimpleUniverse(canvas.getOffscreenCanvas3D()); //TODO: this is awful and must not be done like that in final version
+
+ // This will move the ViewPlatform back a bit so the
+ // objects in the scene can be viewed.
+ universe.getViewingPlatform().setNominalViewingTransform();
+ universe.getViewer().getView().setMinimumFrameCycleTime(30);
+ universe.addBranchGraph(scene);
+ }
+
+ /**
+ * Creates the world. Only exists to cleanup the source a bit
+ *
+ * @param isInteractive tells the world to be constructed as interactive
+ * @param isDelayed tells the rotator to start at a random alpha.
+ *
+ * @return a global branchgroup containing the world, as desired.
+ */
+ private BranchGroup createSceneGraph(boolean isInteractive, boolean isRandom) {
+ // Create the root of the branch graph
+ BranchGroup objRoot = new BranchGroup();
+
+ // 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();
+ Transform3D t3dTrans = new Transform3D();
+ t3dTrans.setTranslation(new Vector3d(0, 0, -1));
+ objTrans.setTransform(t3dTrans);
+
+ TransformGroup objRot = new TransformGroup();
+ objRot.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ objRoot.addChild(objTrans);
+ objTrans.addChild(objRot);
+
+ // Create a simple Shape3D node; add it to the scene graph.
+ // issue 383: changed the cube to a text, so that any graphical problem related to Yup can be seen.
+ Font3D f3d = new Font3D(new Font("dialog", Font.PLAIN, 1),
+ new FontExtrusion());
+ Text3D text = new Text3D(f3d, "JCanvas3D",
+ new Point3f( -2.3f, -0.5f, 0.f));
+
+ Shape3D sh = new Shape3D();
+ Appearance app = new SimpleShaderAppearance(false,false);
+ Material mm = new Material();
+ mm.setLightingEnable(true);
+ app.setMaterial(mm);
+ sh.setGeometry(text);
+ sh.setAppearance(app);
+
+ objRot.addChild( sh );
+
+ BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
+ 100.0);
+
+ // Set up the ambient light
+ Color3f ambientColor = new Color3f(0.3f, 0.3f, 0.3f);
+ AmbientLight ambientLightNode = new AmbientLight(ambientColor);
+ ambientLightNode.setInfluencingBounds(bounds);
+ objRoot.addChild(ambientLightNode);
+
+ // Set up the directional lights
+ Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
+ Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
+ Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f);
+ Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);
+
+ DirectionalLight light1
+ = new DirectionalLight(light1Color, light1Direction);
+ light1.setInfluencingBounds(bounds);
+ objRoot.addChild(light1);
+
+ DirectionalLight light2
+ = new DirectionalLight(light2Color, light2Direction);
+ light2.setInfluencingBounds(bounds);
+ objRoot.addChild(light2);
+
+
+ if (true == isInteractive) {
+ MouseRotate mr = new MouseRotate(comp, objRot);
+ mr.setSchedulingBounds(bounds);
+ mr.setSchedulingInterval(1);
+ objRoot.addChild(mr);
+ } else {
+ // Create a new Behavior object that will perform the
+ // desired operation on the specified transform and add
+ // it into the scene graph.
+ Transform3D yAxis = new Transform3D();
+
+ // rotation speed is randomized a bit so that it does not go at the same speed on every canvases,
+ // which will make it more natural and express the differences between every present universes
+ Alpha rotationAlpha = null;
+
+ if (true == isRandom) {
+ int duration = Math.max(2000, (int) (Math.random() * 8000.));
+ rotationAlpha = new Alpha(-1,
+ (int) ((double) duration * Math.random()), 0, duration,
+ 0, 0);
+ } else {
+ rotationAlpha = new Alpha(-1, 4000);
+ }
+
+ RotationInterpolator rotator = new RotationInterpolator(rotationAlpha,
+ objRot, yAxis, 0.0f, (float) Math.PI * 2.0f);
+
+ rotator.setSchedulingBounds(bounds);
+ objRoot.addChild(rotator);
+ }
+
+ return objRoot;
+ }
+
+}
diff --git a/src/classes/org/jdesktop/j3d/examples/sphere_motion/SphereMotionGL2ES2.java b/src/classes/org/jdesktop/j3d/examples/sphere_motion/SphereMotionGL2ES2.java
new file mode 100644
index 0000000..547c998
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/sphere_motion/SphereMotionGL2ES2.java
@@ -0,0 +1,363 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+package org.jdesktop.j3d.examples.sphere_motion;
+
+import java.awt.GraphicsConfiguration;
+import java.io.File;
+import java.io.IOException;
+
+import org.jdesktop.j3d.examples.gl2es2pipeline.SimpleShaderAppearance;
+import org.jogamp.java3d.Alpha;
+import org.jogamp.java3d.AmbientLight;
+import org.jogamp.java3d.Appearance;
+import org.jogamp.java3d.Background;
+import org.jogamp.java3d.BoundingSphere;
+import org.jogamp.java3d.BranchGroup;
+import org.jogamp.java3d.Canvas3D;
+import org.jogamp.java3d.ColoringAttributes;
+import org.jogamp.java3d.DirectionalLight;
+import org.jogamp.java3d.GLSLShaderProgram;
+import org.jogamp.java3d.Light;
+import org.jogamp.java3d.Material;
+import org.jogamp.java3d.PointLight;
+import org.jogamp.java3d.PositionInterpolator;
+import org.jogamp.java3d.RotationInterpolator;
+import org.jogamp.java3d.Shader;
+import org.jogamp.java3d.ShaderAppearance;
+import org.jogamp.java3d.ShaderProgram;
+import org.jogamp.java3d.SourceCodeShader;
+import org.jogamp.java3d.SpotLight;
+import org.jogamp.java3d.Transform3D;
+import org.jogamp.java3d.TransformGroup;
+import org.jogamp.java3d.utils.geometry.Sphere;
+import org.jogamp.java3d.utils.shader.StringIO;
+import org.jogamp.java3d.utils.universe.SimpleUniverse;
+import org.jogamp.vecmath.Color3f;
+import org.jogamp.vecmath.Point3d;
+import org.jogamp.vecmath.Point3f;
+import org.jogamp.vecmath.Vector3d;
+import org.jogamp.vecmath.Vector3f;
+
+public class SphereMotionGL2ES2 extends javax.swing.JFrame
+{
+
+ private SimpleUniverse univ = null;
+ private BranchGroup scene = null;
+
+ // Constants for type of light to use
+ private static final int DIRECTIONAL_LIGHT = 0;
+ private static final int POINT_LIGHT = 1;
+ private static final int SPOT_LIGHT = 2;
+
+ // Flag indicates type of lights: directional, point, or spot
+ // lights. This flag is set based on command line argument
+ private static int lightType = POINT_LIGHT;
+
+ public BranchGroup createSceneGraph()
+ {
+ Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
+ Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
+ Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f);
+ Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f);
+ Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f);
+ Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
+ Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
+
+ Transform3D t;
+
+ // Create the root of the branch graph
+ BranchGroup objRoot = new BranchGroup();
+
+ // Create a Transformgroup to scale all objects so they
+ // appear in the scene.
+ TransformGroup objScale = new TransformGroup();
+ Transform3D t3d = new Transform3D();
+ t3d.setScale(0.4);
+ objScale.setTransform(t3d);
+ objRoot.addChild(objScale);
+
+ // Create a bounds for the background and lights
+ BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
+
+ // Set up the background
+ Background bg = new Background(bgColor);
+ bg.setApplicationBounds(bounds);
+ objScale.addChild(bg);
+
+ // Create a Sphere object, generate one copy of the sphere,
+ // and add it into the scene graph.
+ ShaderAppearance a = new ShaderAppearance();
+ Material m = new Material(objColor, eColor, objColor, sColor, 100.0f);
+ m.setLightingEnable(true);
+ String vertexProgram = null;
+ String fragmentProgram = null;
+ try
+ {
+ vertexProgram = StringIO.readFully(
+ new File(System.getProperty("user.dir") + "/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.vert"));
+ fragmentProgram = StringIO.readFully(
+ new File(System.getProperty("user.dir") + "/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.frag"));
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ Shader[] shaders = new Shader[2];
+ shaders[0] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_VERTEX, vertexProgram);
+ shaders[1] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_FRAGMENT, fragmentProgram);
+ ShaderProgram shaderProgram = new GLSLShaderProgram();
+ shaderProgram.setShaders(shaders);
+
+ a.setShaderProgram(shaderProgram);
+ a.setMaterial(m);
+ Sphere sph = new Sphere(1.0f, Sphere.GENERATE_NORMALS, 200, a);
+ objScale.addChild(sph);
+
+ // Create the transform group node for the each light and initialize
+ // it to the identity. Enable the TRANSFORM_WRITE capability so that
+ // our behavior code can modify it at runtime. Add them to the root
+ // of the subgraph.
+ TransformGroup l1RotTrans = new TransformGroup();
+ l1RotTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ objScale.addChild(l1RotTrans);
+
+ TransformGroup l2RotTrans = new TransformGroup();
+ l2RotTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ objScale.addChild(l2RotTrans);
+
+ // Create transformations for the positional lights
+ t = new Transform3D();
+ Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0);
+ t.set(lPos1);
+ TransformGroup l1Trans = new TransformGroup(t);
+ l1RotTrans.addChild(l1Trans);
+
+ t = new Transform3D();
+ Vector3d lPos2 = new Vector3d(0.5, 0.8, 2.0);
+ t.set(lPos2);
+ TransformGroup l2Trans = new TransformGroup(t);
+ l2RotTrans.addChild(l2Trans);
+
+ // Create Geometry for point lights
+ ColoringAttributes caL1 = new ColoringAttributes();
+ ColoringAttributes caL2 = new ColoringAttributes();
+ caL1.setColor(lColor1);
+ caL2.setColor(lColor2);
+ Appearance appL1 = new SimpleShaderAppearance(false, false);
+ Appearance appL2 = new SimpleShaderAppearance(false, false);
+ appL1.setColoringAttributes(caL1);
+ appL2.setColoringAttributes(caL2);
+ l1Trans.addChild(new Sphere(0.05f, appL1));
+ l2Trans.addChild(new Sphere(0.05f, appL2));
+
+ // Create lights
+ AmbientLight aLgt = new AmbientLight(alColor);
+
+ Light lgt1 = null;
+ Light lgt2 = null;
+
+ Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f);
+ Point3f atten = new Point3f(1.0f, 0.0f, 0.0f);
+ Vector3f lDirect1 = new Vector3f(lPos1);
+ Vector3f lDirect2 = new Vector3f(lPos2);
+ lDirect1.negate();
+ lDirect2.negate();
+
+ switch (lightType)
+ {
+ case DIRECTIONAL_LIGHT:
+ lgt1 = new DirectionalLight(lColor1, lDirect1);
+ lgt2 = new DirectionalLight(lColor2, lDirect2);
+ break;
+ case POINT_LIGHT:
+ lgt1 = new PointLight(lColor1, lPoint, atten);
+ lgt2 = new PointLight(lColor2, lPoint, atten);
+ break;
+ case SPOT_LIGHT:
+ lgt1 = new SpotLight(lColor1, lPoint, atten, lDirect1, 25.0f * (float) Math.PI / 180.0f, 10.0f);
+ lgt2 = new SpotLight(lColor2, lPoint, atten, lDirect2, 25.0f * (float) Math.PI / 180.0f, 10.0f);
+ break;
+ }
+
+ // Set the influencing bounds
+ aLgt.setInfluencingBounds(bounds);
+ lgt1.setInfluencingBounds(bounds);
+ lgt2.setInfluencingBounds(bounds);
+
+ // Add the lights into the scene graph
+ objScale.addChild(aLgt);
+ l1Trans.addChild(lgt1);
+ l2Trans.addChild(lgt2);
+
+ // Create a new Behavior object that will perform the desired
+ // operation on the specified transform object and add it into the
+ // scene graph.
+ Transform3D yAxis = new Transform3D();
+ Alpha rotor1Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);
+ RotationInterpolator rotator1 = new RotationInterpolator(rotor1Alpha, l1RotTrans, yAxis, 0.0f, (float) Math.PI * 2.0f);
+ rotator1.setSchedulingBounds(bounds);
+ l1RotTrans.addChild(rotator1);
+
+ // Create a new Behavior object that will perform the desired
+ // operation on the specified transform object and add it into the
+ // scene graph.
+ Alpha rotor2Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 1000, 0, 0, 0, 0, 0);
+ RotationInterpolator rotator2 = new RotationInterpolator(rotor2Alpha, l2RotTrans, yAxis, 0.0f, 0.0f);
+ bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
+ rotator2.setSchedulingBounds(bounds);
+ l2RotTrans.addChild(rotator2);
+
+ // Create a position interpolator and attach it to the view
+ // platform
+ TransformGroup vpTrans = univ.getViewingPlatform().getViewPlatformTransform();
+ Transform3D axisOfTranslation = new Transform3D();
+ Alpha transAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 5000, 0, 0, 5000, 0, 0);
+ axisOfTranslation.rotY(-Math.PI / 2.0);
+ PositionInterpolator translator = new PositionInterpolator(transAlpha, vpTrans, axisOfTranslation, 2.0f, 3.5f);
+ translator.setSchedulingBounds(bounds);
+ objScale.addChild(translator);
+
+ // Let Java 3D perform optimizations on this scene graph.
+ objRoot.compile();
+
+ return objRoot;
+ }
+
+ private Canvas3D createUniverse()
+ {
+ // Get the preferred graphics configuration for the default screen
+ GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
+
+ // Create a Canvas3D using the preferred configuration
+ Canvas3D c = new Canvas3D(config);
+
+ // 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.
+ univ.getViewingPlatform().setNominalViewingTransform();
+
+ // Ensure at least 5 msec per frame (i.e., < 200Hz)
+ univ.getViewer().getView().setMinimumFrameCycleTime(5);
+
+ return c;
+ }
+
+ /**
+ * Creates new form SphereMotion
+ */
+ public SphereMotionGL2ES2(final String[] args)
+ {
+
+ // Parse the Input Arguments
+ String usage = "Usage: java SphereMotion [-point | -spot | -dir]";
+ for (int i = 0; i < args.length; i++)
+ {
+ if (args[i].startsWith("-"))
+ {
+ if (args[i].equals("-point"))
+ {
+ System.out.println("Using point lights");
+ lightType = POINT_LIGHT;
+ }
+ else if (args[i].equals("-spot"))
+ {
+ System.out.println("Using spot lights");
+ lightType = SPOT_LIGHT;
+ }
+ else if (args[i].equals("-dir"))
+ {
+ System.out.println("Using directional lights");
+ lightType = DIRECTIONAL_LIGHT;
+ }
+ else
+ {
+ System.out.println(usage);
+ System.exit(0);
+ }
+ }
+ else
+ {
+ System.out.println(usage);
+ System.exit(0);
+ }
+ }
+
+ // 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.
+ */
+ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
+ private void initComponents()
+ {
+ drawingPanel = new javax.swing.JPanel();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle("SphereMotionGL2ES2");
+ drawingPanel.setLayout(new java.awt.BorderLayout());
+
+ drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700));
+ getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER);
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(final String args[])
+ {
+ System.setProperty("sun.awt.noerasebackground", "true");
+ System.setProperty("j3d.rend", "jogl2es2");
+ System.setProperty("j3d.displaylist", "false");
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
+ public void run()
+ {
+ SphereMotionGL2ES2 sphereMotion = new SphereMotionGL2ES2(args);
+ sphereMotion.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/sphere_motion/SphereMotionGL2ES3_Texture.java b/src/classes/org/jdesktop/j3d/examples/sphere_motion/SphereMotionGL2ES3_Texture.java
new file mode 100644
index 0000000..a1cee22
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/sphere_motion/SphereMotionGL2ES3_Texture.java
@@ -0,0 +1,376 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+package org.jdesktop.j3d.examples.sphere_motion;
+
+import java.awt.GraphicsConfiguration;
+import java.io.File;
+import java.io.IOException;
+
+import org.jdesktop.j3d.examples.Resources;
+import org.jdesktop.j3d.examples.gl2es2pipeline.SimpleShaderAppearance;
+import org.jogamp.java3d.Alpha;
+import org.jogamp.java3d.AmbientLight;
+import org.jogamp.java3d.Appearance;
+import org.jogamp.java3d.Background;
+import org.jogamp.java3d.BoundingSphere;
+import org.jogamp.java3d.BranchGroup;
+import org.jogamp.java3d.Canvas3D;
+import org.jogamp.java3d.ColoringAttributes;
+import org.jogamp.java3d.DirectionalLight;
+import org.jogamp.java3d.GLSLShaderProgram;
+import org.jogamp.java3d.Light;
+import org.jogamp.java3d.Material;
+import org.jogamp.java3d.PointLight;
+import org.jogamp.java3d.PositionInterpolator;
+import org.jogamp.java3d.RotationInterpolator;
+import org.jogamp.java3d.Shader;
+import org.jogamp.java3d.ShaderAppearance;
+import org.jogamp.java3d.ShaderAttributeSet;
+import org.jogamp.java3d.ShaderAttributeValue;
+import org.jogamp.java3d.ShaderProgram;
+import org.jogamp.java3d.SourceCodeShader;
+import org.jogamp.java3d.SpotLight;
+import org.jogamp.java3d.Texture;
+import org.jogamp.java3d.Transform3D;
+import org.jogamp.java3d.TransformGroup;
+import org.jogamp.java3d.utils.geometry.Sphere;
+import org.jogamp.java3d.utils.image.TextureLoader;
+import org.jogamp.java3d.utils.shader.StringIO;
+import org.jogamp.java3d.utils.universe.SimpleUniverse;
+import org.jogamp.vecmath.Color3f;
+import org.jogamp.vecmath.Point3d;
+import org.jogamp.vecmath.Point3f;
+import org.jogamp.vecmath.Vector3d;
+import org.jogamp.vecmath.Vector3f;
+
+public class SphereMotionGL2ES3_Texture extends javax.swing.JFrame
+{
+
+ private SimpleUniverse univ = null;
+ private BranchGroup scene = null;
+
+ // Constants for type of light to use
+ private static final int DIRECTIONAL_LIGHT = 0;
+ private static final int POINT_LIGHT = 1;
+ private static final int SPOT_LIGHT = 2;
+
+ // Flag indicates type of lights: directional, point, or spot
+ // lights. This flag is set based on command line argument
+ private static int lightType = POINT_LIGHT;
+
+ public BranchGroup createSceneGraph()
+ {
+ Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
+ Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
+ Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f);
+ Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f);
+ Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f);
+ Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
+ Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
+
+ Transform3D t;
+
+ // Create the root of the branch graph
+ BranchGroup objRoot = new BranchGroup();
+
+ // Create a Transformgroup to scale all objects so they
+ // appear in the scene.
+ TransformGroup objScale = new TransformGroup();
+ Transform3D t3d = new Transform3D();
+ t3d.setScale(0.4);
+ objScale.setTransform(t3d);
+ objRoot.addChild(objScale);
+
+ // Create a bounds for the background and lights
+ BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
+
+ // Set up the background
+ Background bg = new Background(bgColor);
+ bg.setApplicationBounds(bounds);
+ objScale.addChild(bg);
+
+ // Create a Sphere object, generate one copy of the sphere,
+ // and add it into the scene graph.
+ ShaderAppearance a = new ShaderAppearance();
+ Material m = new Material(objColor, eColor, objColor, sColor, 100.0f);
+ m.setLightingEnable(true);
+ String vertexProgram = null;
+ String fragmentProgram = null;
+ try
+ {
+ vertexProgram = StringIO.readFully(
+ new File(System.getProperty("user.dir") + "/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.vert"));
+ fragmentProgram = StringIO.readFully(
+ new File(System.getProperty("user.dir") + "/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.frag"));
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ Shader[] shaders = new Shader[2];
+ shaders[0] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_VERTEX, vertexProgram);
+ shaders[1] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_FRAGMENT, fragmentProgram);
+ ShaderProgram shaderProgram = new GLSLShaderProgram();
+ shaderProgram.setShaders(shaders);
+ shaderProgram.setShaderAttrNames(new String[] { "BaseMap" });
+
+ a.setShaderProgram(shaderProgram);
+
+ ShaderAttributeSet shaderAttributeSet = new ShaderAttributeSet();
+ shaderAttributeSet.put(new ShaderAttributeValue("BaseMap", new Integer(0)));
+ a.setShaderAttributeSet(shaderAttributeSet);
+
+
+ a.setMaterial(m);
+ Texture txtr = new TextureLoader(Resources.getResource("resources/images/earth.jpg"), this).getTexture();
+ a.setTexture(txtr);
+ Sphere sph = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, 200, a);
+ objScale.addChild(sph);
+
+ // Create the transform group node for the each light and initialize
+ // it to the identity. Enable the TRANSFORM_WRITE capability so that
+ // our behavior code can modify it at runtime. Add them to the root
+ // of the subgraph.
+ TransformGroup l1RotTrans = new TransformGroup();
+ l1RotTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ objScale.addChild(l1RotTrans);
+
+ TransformGroup l2RotTrans = new TransformGroup();
+ l2RotTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ objScale.addChild(l2RotTrans);
+
+ // Create transformations for the positional lights
+ t = new Transform3D();
+ Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0);
+ t.set(lPos1);
+ TransformGroup l1Trans = new TransformGroup(t);
+ l1RotTrans.addChild(l1Trans);
+
+ t = new Transform3D();
+ Vector3d lPos2 = new Vector3d(0.5, 0.8, 2.0);
+ t.set(lPos2);
+ TransformGroup l2Trans = new TransformGroup(t);
+ l2RotTrans.addChild(l2Trans);
+
+ // Create Geometry for point lights
+ ColoringAttributes caL1 = new ColoringAttributes();
+ ColoringAttributes caL2 = new ColoringAttributes();
+ caL1.setColor(lColor1);
+ caL2.setColor(lColor2);
+ Appearance appL1 = new SimpleShaderAppearance(false, false);
+ Appearance appL2 = new SimpleShaderAppearance(false, false);
+ appL1.setColoringAttributes(caL1);
+ appL2.setColoringAttributes(caL2);
+ l1Trans.addChild(new Sphere(0.05f, appL1));
+ l2Trans.addChild(new Sphere(0.05f, appL2));
+
+ // Create lights
+ AmbientLight aLgt = new AmbientLight(alColor);
+
+ Light lgt1 = null;
+ Light lgt2 = null;
+
+ Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f);
+ Point3f atten = new Point3f(1.0f, 0.0f, 0.0f);
+ Vector3f lDirect1 = new Vector3f(lPos1);
+ Vector3f lDirect2 = new Vector3f(lPos2);
+ lDirect1.negate();
+ lDirect2.negate();
+
+ switch (lightType)
+ {
+ case DIRECTIONAL_LIGHT:
+ lgt1 = new DirectionalLight(lColor1, lDirect1);
+ lgt2 = new DirectionalLight(lColor2, lDirect2);
+ break;
+ case POINT_LIGHT:
+ lgt1 = new PointLight(lColor1, lPoint, atten);
+ lgt2 = new PointLight(lColor2, lPoint, atten);
+ break;
+ case SPOT_LIGHT:
+ lgt1 = new SpotLight(lColor1, lPoint, atten, lDirect1, 25.0f * (float) Math.PI / 180.0f, 10.0f);
+ lgt2 = new SpotLight(lColor2, lPoint, atten, lDirect2, 25.0f * (float) Math.PI / 180.0f, 10.0f);
+ break;
+ }
+
+ // Set the influencing bounds
+ aLgt.setInfluencingBounds(bounds);
+ lgt1.setInfluencingBounds(bounds);
+ lgt2.setInfluencingBounds(bounds);
+
+ // Add the lights into the scene graph
+ objScale.addChild(aLgt);
+ l1Trans.addChild(lgt1);
+ l2Trans.addChild(lgt2);
+
+ // Create a new Behavior object that will perform the desired
+ // operation on the specified transform object and add it into the
+ // scene graph.
+ Transform3D yAxis = new Transform3D();
+ Alpha rotor1Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);
+ RotationInterpolator rotator1 = new RotationInterpolator(rotor1Alpha, l1RotTrans, yAxis, 0.0f, (float) Math.PI * 2.0f);
+ rotator1.setSchedulingBounds(bounds);
+ l1RotTrans.addChild(rotator1);
+
+ // Create a new Behavior object that will perform the desired
+ // operation on the specified transform object and add it into the
+ // scene graph.
+ Alpha rotor2Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 1000, 0, 0, 0, 0, 0);
+ RotationInterpolator rotator2 = new RotationInterpolator(rotor2Alpha, l2RotTrans, yAxis, 0.0f, 0.0f);
+ bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
+ rotator2.setSchedulingBounds(bounds);
+ l2RotTrans.addChild(rotator2);
+
+ // Create a position interpolator and attach it to the view
+ // platform
+ TransformGroup vpTrans = univ.getViewingPlatform().getViewPlatformTransform();
+ Transform3D axisOfTranslation = new Transform3D();
+ Alpha transAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 5000, 0, 0, 5000, 0, 0);
+ axisOfTranslation.rotY(-Math.PI / 2.0);
+ PositionInterpolator translator = new PositionInterpolator(transAlpha, vpTrans, axisOfTranslation, 2.0f, 3.5f);
+ translator.setSchedulingBounds(bounds);
+ objScale.addChild(translator);
+
+ // Let Java 3D perform optimizations on this scene graph.
+ objRoot.compile();
+
+ return objRoot;
+ }
+
+ private Canvas3D createUniverse()
+ {
+ // Get the preferred graphics configuration for the default screen
+ GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
+
+ // Create a Canvas3D using the preferred configuration
+ Canvas3D c = new Canvas3D(config);
+
+ // 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.
+ univ.getViewingPlatform().setNominalViewingTransform();
+
+ // Ensure at least 5 msec per frame (i.e., < 200Hz)
+ univ.getViewer().getView().setMinimumFrameCycleTime(5);
+
+ return c;
+ }
+
+ /**
+ * Creates new form SphereMotion
+ */
+ public SphereMotionGL2ES3_Texture(final String[] args)
+ {
+
+ // Parse the Input Arguments
+ String usage = "Usage: java SphereMotion [-point | -spot | -dir]";
+ for (int i = 0; i < args.length; i++)
+ {
+ if (args[i].startsWith("-"))
+ {
+ if (args[i].equals("-point"))
+ {
+ System.out.println("Using point lights");
+ lightType = POINT_LIGHT;
+ }
+ else if (args[i].equals("-spot"))
+ {
+ System.out.println("Using spot lights");
+ lightType = SPOT_LIGHT;
+ }
+ else if (args[i].equals("-dir"))
+ {
+ System.out.println("Using directional lights");
+ lightType = DIRECTIONAL_LIGHT;
+ }
+ else
+ {
+ System.out.println(usage);
+ System.exit(0);
+ }
+ }
+ else
+ {
+ System.out.println(usage);
+ System.exit(0);
+ }
+ }
+
+ // 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.
+ */
+ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
+ private void initComponents()
+ {
+ drawingPanel = new javax.swing.JPanel();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle("SphereMotionGL2ES2_Texture");
+ drawingPanel.setLayout(new java.awt.BorderLayout());
+
+ drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700));
+ getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER);
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(final String args[])
+ {
+ System.setProperty("sun.awt.noerasebackground", "true");
+ System.setProperty("j3d.rend", "jogl2es2");
+ System.setProperty("j3d.displaylist", "false");
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
+ public void run()
+ {
+ SphereMotionGL2ES3_Texture sphereMotion = new SphereMotionGL2ES3_Texture(args);
+ sphereMotion.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/sphere_motion/SphereMotionGLSL_FFP.java b/src/classes/org/jdesktop/j3d/examples/sphere_motion/SphereMotionGLSL_FFP.java
new file mode 100644
index 0000000..ce1fdc0
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/sphere_motion/SphereMotionGLSL_FFP.java
@@ -0,0 +1,361 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+package org.jdesktop.j3d.examples.sphere_motion;
+
+import java.awt.GraphicsConfiguration;
+import java.io.File;
+import java.io.IOException;
+
+import org.jogamp.java3d.Alpha;
+import org.jogamp.java3d.AmbientLight;
+import org.jogamp.java3d.Appearance;
+import org.jogamp.java3d.Background;
+import org.jogamp.java3d.BoundingSphere;
+import org.jogamp.java3d.BranchGroup;
+import org.jogamp.java3d.Canvas3D;
+import org.jogamp.java3d.ColoringAttributes;
+import org.jogamp.java3d.DirectionalLight;
+import org.jogamp.java3d.GLSLShaderProgram;
+import org.jogamp.java3d.Light;
+import org.jogamp.java3d.Material;
+import org.jogamp.java3d.PointLight;
+import org.jogamp.java3d.PositionInterpolator;
+import org.jogamp.java3d.RotationInterpolator;
+import org.jogamp.java3d.Shader;
+import org.jogamp.java3d.ShaderAppearance;
+import org.jogamp.java3d.ShaderProgram;
+import org.jogamp.java3d.SourceCodeShader;
+import org.jogamp.java3d.SpotLight;
+import org.jogamp.java3d.Transform3D;
+import org.jogamp.java3d.TransformGroup;
+import org.jogamp.java3d.utils.geometry.Sphere;
+import org.jogamp.java3d.utils.shader.StringIO;
+import org.jogamp.java3d.utils.universe.SimpleUniverse;
+import org.jogamp.vecmath.Color3f;
+import org.jogamp.vecmath.Point3d;
+import org.jogamp.vecmath.Point3f;
+import org.jogamp.vecmath.Vector3d;
+import org.jogamp.vecmath.Vector3f;
+
+public class SphereMotionGLSL_FFP extends javax.swing.JFrame
+{
+
+ private SimpleUniverse univ = null;
+ private BranchGroup scene = null;
+
+ // Constants for type of light to use
+ private static final int DIRECTIONAL_LIGHT = 0;
+ private static final int POINT_LIGHT = 1;
+ private static final int SPOT_LIGHT = 2;
+
+ // Flag indicates type of lights: directional, point, or spot
+ // lights. This flag is set based on command line argument
+ private static int lightType = POINT_LIGHT;
+
+ public BranchGroup createSceneGraph()
+ {
+ Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
+ Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
+ Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f);
+ Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f);
+ Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f);
+ Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
+ Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
+
+ Transform3D t;
+
+ // Create the root of the branch graph
+ BranchGroup objRoot = new BranchGroup();
+
+ // Create a Transformgroup to scale all objects so they
+ // appear in the scene.
+ TransformGroup objScale = new TransformGroup();
+ Transform3D t3d = new Transform3D();
+ t3d.setScale(0.4);
+ objScale.setTransform(t3d);
+ objRoot.addChild(objScale);
+
+ // Create a bounds for the background and lights
+ BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
+
+ // Set up the background
+ Background bg = new Background(bgColor);
+ bg.setApplicationBounds(bounds);
+ objScale.addChild(bg);
+
+ // Create a Sphere object, generate one copy of the sphere,
+ // and add it into the scene graph.
+ ShaderAppearance a = new ShaderAppearance();
+ Material m = new Material(objColor, eColor, objColor, sColor, 100.0f);
+ m.setLightingEnable(true);
+ String vertexProgram = null;
+ String fragmentProgram = null;
+ try
+ {
+ vertexProgram = StringIO.readFully(
+ new File(System.getProperty("user.dir") + "/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_ffp.vert"));
+ fragmentProgram = StringIO.readFully(
+ new File(System.getProperty("user.dir") + "/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_ffp.frag"));
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ Shader[] shaders = new Shader[2];
+ shaders[0] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_VERTEX, vertexProgram);
+ shaders[1] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_FRAGMENT, fragmentProgram);
+ ShaderProgram shaderProgram = new GLSLShaderProgram();
+ shaderProgram.setShaders(shaders);
+
+ a.setShaderProgram(shaderProgram);
+ a.setMaterial(m);
+ Sphere sph = new Sphere(1.0f, Sphere.GENERATE_NORMALS, 200, a);
+ objScale.addChild(sph);
+
+ // Create the transform group node for the each light and initialize
+ // it to the identity. Enable the TRANSFORM_WRITE capability so that
+ // our behavior code can modify it at runtime. Add them to the root
+ // of the subgraph.
+ TransformGroup l1RotTrans = new TransformGroup();
+ l1RotTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ objScale.addChild(l1RotTrans);
+
+ TransformGroup l2RotTrans = new TransformGroup();
+ l2RotTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
+ objScale.addChild(l2RotTrans);
+
+ // Create transformations for the positional lights
+ t = new Transform3D();
+ Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0);
+ t.set(lPos1);
+ TransformGroup l1Trans = new TransformGroup(t);
+ l1RotTrans.addChild(l1Trans);
+
+ t = new Transform3D();
+ Vector3d lPos2 = new Vector3d(0.5, 0.8, 2.0);
+ t.set(lPos2);
+ TransformGroup l2Trans = new TransformGroup(t);
+ l2RotTrans.addChild(l2Trans);
+
+ // Create Geometry for point lights
+ ColoringAttributes caL1 = new ColoringAttributes();
+ ColoringAttributes caL2 = new ColoringAttributes();
+ caL1.setColor(lColor1);
+ caL2.setColor(lColor2);
+ Appearance appL1 = new Appearance();
+ Appearance appL2 = new Appearance();
+ appL1.setColoringAttributes(caL1);
+ appL2.setColoringAttributes(caL2);
+ l1Trans.addChild(new Sphere(0.05f, appL1));
+ l2Trans.addChild(new Sphere(0.05f, appL2));
+
+ // Create lights
+ AmbientLight aLgt = new AmbientLight(alColor);
+
+ Light lgt1 = null;
+ Light lgt2 = null;
+
+ Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f);
+ Point3f atten = new Point3f(1.0f, 0.0f, 0.0f);
+ Vector3f lDirect1 = new Vector3f(lPos1);
+ Vector3f lDirect2 = new Vector3f(lPos2);
+ lDirect1.negate();
+ lDirect2.negate();
+
+ switch (lightType)
+ {
+ case DIRECTIONAL_LIGHT:
+ lgt1 = new DirectionalLight(lColor1, lDirect1);
+ lgt2 = new DirectionalLight(lColor2, lDirect2);
+ break;
+ case POINT_LIGHT:
+ lgt1 = new PointLight(lColor1, lPoint, atten);
+ lgt2 = new PointLight(lColor2, lPoint, atten);
+ break;
+ case SPOT_LIGHT:
+ lgt1 = new SpotLight(lColor1, lPoint, atten, lDirect1, 25.0f * (float) Math.PI / 180.0f, 10.0f);
+ lgt2 = new SpotLight(lColor2, lPoint, atten, lDirect2, 25.0f * (float) Math.PI / 180.0f, 10.0f);
+ break;
+ }
+
+ // Set the influencing bounds
+ aLgt.setInfluencingBounds(bounds);
+ lgt1.setInfluencingBounds(bounds);
+ lgt2.setInfluencingBounds(bounds);
+
+ // Add the lights into the scene graph
+ objScale.addChild(aLgt);
+ l1Trans.addChild(lgt1);
+ l2Trans.addChild(lgt2);
+
+
+ // Create a new Behavior object that will perform the desired
+ // operation on the specified transform object and add it into the
+ // scene graph.
+ Transform3D yAxis = new Transform3D();
+ Alpha rotor1Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);
+ RotationInterpolator rotator1 = new RotationInterpolator(rotor1Alpha, l1RotTrans, yAxis, 0.0f, (float) Math.PI * 2.0f);
+ rotator1.setSchedulingBounds(bounds);
+ l1RotTrans.addChild(rotator1);
+
+ // Create a new Behavior object that will perform the desired
+ // operation on the specified transform object and add it into the
+ // scene graph.
+ Alpha rotor2Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 1000, 0, 0, 0, 0, 0);
+ RotationInterpolator rotator2 = new RotationInterpolator(rotor2Alpha, l2RotTrans, yAxis, 0.0f, 0.0f);
+ bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
+ rotator2.setSchedulingBounds(bounds);
+ l2RotTrans.addChild(rotator2);
+
+ // Create a position interpolator and attach it to the view
+ // platform
+ TransformGroup vpTrans = univ.getViewingPlatform().getViewPlatformTransform();
+ Transform3D axisOfTranslation = new Transform3D();
+ Alpha transAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 5000, 0, 0, 5000, 0, 0);
+ axisOfTranslation.rotY(-Math.PI / 2.0);
+ PositionInterpolator translator = new PositionInterpolator(transAlpha, vpTrans, axisOfTranslation, 2.0f, 3.5f);
+ translator.setSchedulingBounds(bounds);
+ objScale.addChild(translator);
+
+ // Let Java 3D perform optimizations on this scene graph.
+ objRoot.compile();
+
+ return objRoot;
+ }
+
+ private Canvas3D createUniverse()
+ {
+ // Get the preferred graphics configuration for the default screen
+ GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
+
+ // Create a Canvas3D using the preferred configuration
+ Canvas3D c = new Canvas3D(config);
+
+ // 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.
+ univ.getViewingPlatform().setNominalViewingTransform();
+
+ // Ensure at least 5 msec per frame (i.e., < 200Hz)
+ univ.getViewer().getView().setMinimumFrameCycleTime(5);
+
+ return c;
+ }
+
+ /**
+ * Creates new form SphereMotion
+ */
+ public SphereMotionGLSL_FFP(final String[] args)
+ {
+
+ // Parse the Input Arguments
+ String usage = "Usage: java SphereMotion [-point | -spot | -dir]";
+ for (int i = 0; i < args.length; i++)
+ {
+ if (args[i].startsWith("-"))
+ {
+ if (args[i].equals("-point"))
+ {
+ System.out.println("Using point lights");
+ lightType = POINT_LIGHT;
+ }
+ else if (args[i].equals("-spot"))
+ {
+ System.out.println("Using spot lights");
+ lightType = SPOT_LIGHT;
+ }
+ else if (args[i].equals("-dir"))
+ {
+ System.out.println("Using directional lights");
+ lightType = DIRECTIONAL_LIGHT;
+ }
+ else
+ {
+ System.out.println(usage);
+ System.exit(0);
+ }
+ }
+ else
+ {
+ System.out.println(usage);
+ System.exit(0);
+ }
+ }
+
+ // 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.
+ */
+ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
+ private void initComponents()
+ {
+ drawingPanel = new javax.swing.JPanel();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle("SphereMotionGLSL_FFP");
+ drawingPanel.setLayout(new java.awt.BorderLayout());
+
+ drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700));
+ getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER);
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(final String args[])
+ {
+ System.setProperty("sun.awt.noerasebackground", "true");
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
+ public void run()
+ {
+ SphereMotionGLSL_FFP sphereMotion = new SphereMotionGLSL_FFP(args);
+ sphereMotion.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/sphere_motion/phong_ffp.frag b/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_ffp.frag
new file mode 100644
index 0000000..ba72696
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_ffp.frag
@@ -0,0 +1,66 @@
+#version 120
+
+// Per-pixel normal (input from vertex shader)
+varying vec3 normalDirection;
+varying vec3 viewDirection;
+varying vec4 position;
+
+const int numberOfLights = 2;
+
+void main()
+{
+ vec3 lightDirection;
+ float attenuation;
+
+ // initialize total lighting with ambient lighting
+ vec3 totalLighting = vec3(gl_FrontMaterial.emission) + (vec3(gl_LightModel.ambient) * vec3(gl_FrontMaterial.ambient));
+
+ for (int index = 0; index < numberOfLights; index++) // for all light sources
+ {
+ if (0.0 == gl_LightSource[index].position.w) // directional light?
+ {
+ attenuation = 1.0; // no attenuation
+ lightDirection = normalize(vec3(gl_LightSource[index].position));
+ }
+ else // point light or spotlight (or other kind of light)
+ {
+ vec3 positionToLightSource = vec3(gl_LightSource[index].position - position);
+ float distance = length(positionToLightSource);
+ lightDirection = normalize(positionToLightSource);
+ attenuation = 1.0 / (gl_LightSource[index].constantAttenuation
+ + gl_LightSource[index].linearAttenuation * distance
+ + gl_LightSource[index].quadraticAttenuation * distance * distance);
+
+
+ if (gl_LightSource[index].spotCutoff <= 90.0) // spotlight?
+ {
+ float clampedCosine = max(0.0, dot(-lightDirection, normalize(gl_LightSource[index].spotDirection)));
+ if (clampedCosine < cos(radians(gl_LightSource[index].spotCutoff))) // outside of spotlight cone?
+ {
+ attenuation = 0.0;
+ }
+ else
+ {
+ attenuation = attenuation * pow(clampedCosine, gl_LightSource[index].spotExponent);
+ }
+ }
+ }
+
+ vec3 diffuseReflection = attenuation * vec3(gl_LightSource[index].diffuse) * vec3(gl_FrontMaterial.diffuse)* max(0.0, dot(normalDirection, lightDirection));
+
+ vec3 specularReflection;
+ if (dot(normalDirection, lightDirection) < 0.0) // light source on the wrong side?
+ {
+ specularReflection = vec3(0.0, 0.0, 0.0); // no specular reflection
+ }
+ else // light source on the right side
+ {
+ specularReflection = attenuation * vec3(gl_LightSource[index].specular) * vec3(gl_FrontMaterial.specular)
+ * pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), gl_FrontMaterial.shininess);
+ }
+
+ totalLighting = totalLighting + diffuseReflection + specularReflection;
+ }
+
+ gl_FragColor = vec4(totalLighting, 1.0);
+}
diff --git a/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_ffp.vert b/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_ffp.vert
new file mode 100644
index 0000000..caf1732
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_ffp.vert
@@ -0,0 +1,19 @@
+
+
+// A GLSL vertex program for doing Phone shading (per-fragment lighting)
+
+// Per-pixel normal (output to fragment shader)
+varying vec3 normalDirection;
+varying vec3 viewDirection;
+varying vec4 position;
+
+void main()
+{
+ normalDirection = normalize(vec3(gl_NormalMatrix * gl_Normal));
+ vec3 v = vec3(gl_ModelViewMatrix * gl_Vertex);
+ viewDirection = normalize(-v.xyz);
+ position = vec4(v,1);
+
+ // Transform the vertex
+ gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+}
diff --git a/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.frag b/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.frag
new file mode 100644
index 0000000..af65808
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.frag
@@ -0,0 +1,96 @@
+#version 120
+
+// Per-pixel normal (input from vertex shader)
+varying vec3 normalDirection;
+varying vec3 viewDirection;
+varying vec4 position;
+
+uniform vec4 glLightModelambient;
+
+
+struct material
+{
+ int lightEnabled;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 emission;// note vec4 extra 1.0 sent through for ease
+ vec3 specular;
+ float shininess;
+};
+uniform material glFrontMaterial;
+
+struct lightSource
+{
+ int enabled;
+ vec4 position;
+ vec4 diffuse;
+ vec4 specular;
+ float constantAttenuation, linearAttenuation, quadraticAttenuation;
+ float spotCutoff, spotExponent;
+ vec3 spotDirection;
+};
+
+uniform int numberOfLights;
+const int maxLights = 2;
+uniform lightSource glLightSource[maxLights];
+
+void main()
+{
+ vec3 lightDirection;
+ float attenuation;
+
+ // initialize total lighting with ambient lighting
+ vec3 totalLighting = vec3(glFrontMaterial.emission) + (vec3(glLightModelambient) * vec3(glFrontMaterial.ambient));
+
+ for (int index = 0; index < numberOfLights; index++) // for all light sources
+ {
+ if(glLightSource[index].enabled == 1)
+ {
+ if (0.0 == glLightSource[index].position.w) // directional light?
+ {
+ attenuation = 1.0; // no attenuation
+ lightDirection = normalize(vec3(glLightSource[index].position));
+
+ }
+ else // point light or spotlight (or other kind of light)
+ {
+ vec3 positionToLightSource = vec3(glLightSource[index].position - position);
+ float distance = length(positionToLightSource);
+ lightDirection = normalize(positionToLightSource);
+ attenuation = 1.0 / (glLightSource[index].constantAttenuation
+ + glLightSource[index].linearAttenuation * distance
+ + glLightSource[index].quadraticAttenuation * distance * distance);
+
+ if (glLightSource[index].spotCutoff <= 90.0) // spotlight?
+ {
+ float clampedCosine = max(0.0, dot(-lightDirection, normalize(glLightSource[index].spotDirection)));
+ if (clampedCosine < cos(radians(glLightSource[index].spotCutoff))) // outside of spotlight cone?
+ {
+ attenuation = 0.0;
+ }
+ else
+ {
+ attenuation = attenuation * pow(clampedCosine, glLightSource[index].spotExponent);
+ }
+ }
+ }
+
+ vec3 diffuseReflection = attenuation * vec3(glLightSource[index].diffuse) * vec3(glFrontMaterial.diffuse)* max(0.0, dot(normalDirection, lightDirection));
+
+ vec3 specularReflection;
+ if (dot(normalDirection, lightDirection) < 0.0) // light source on the wrong side?
+ {
+ specularReflection = vec3(0.0, 0.0, 0.0); // no specular reflection
+ }
+ else // light source on the right side
+ {
+ specularReflection = attenuation * vec3(glLightSource[index].specular) * vec3(glFrontMaterial.specular)
+ * pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), glFrontMaterial.shininess);
+ }
+
+ totalLighting = totalLighting + diffuseReflection + specularReflection;
+ }
+ }
+
+ gl_FragColor = vec4(totalLighting, 1.0);
+}
diff --git a/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.vert b/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.vert
new file mode 100644
index 0000000..4d8fb67
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.vert
@@ -0,0 +1,31 @@
+// GL2ES2: Java3D built-in attributes, these are calculated and passsed in if declared here
+attribute vec4 glVertex;
+attribute vec3 glNormal;
+
+// GL2ES2: Java3D built-in uniforms, these are calculated and passsed in if declared here
+uniform mat4 glModelViewProjectionMatrix;
+uniform mat4 glModelViewMatrix;
+uniform mat3 glNormalMatrix;
+
+
+// Per-pixel normal (output to fragment shader)
+varying vec3 normalDirection;
+varying vec3 viewDirection;
+varying vec4 position;
+
+void main()
+{
+ normalDirection = normalize(vec3(glNormalMatrix * glNormal));
+ vec3 v = vec3(glModelViewMatrix * glVertex);
+ viewDirection = normalize(-v.xyz);
+ position = vec4(v,1);
+
+ // Transform the vertex
+ gl_Position = glModelViewProjectionMatrix * glVertex;
+}
+
+
+
+
+
+
diff --git a/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.frag b/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.frag
new file mode 100644
index 0000000..2b1a258
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.frag
@@ -0,0 +1,105 @@
+#version 120
+
+// Per-pixel normal (input from vertex shader)
+varying vec3 normalDirection;
+varying vec3 viewDirection;
+varying vec4 position;
+
+varying vec2 glTexCoord0;
+uniform sampler2D BaseMap;
+
+uniform vec4 glLightModelambient;
+
+
+struct material
+{
+ int lightEnabled;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 emission;
+ vec3 specular;
+ float shininess;
+};
+uniform material glFrontMaterial;
+
+struct lightSource
+{
+ int enabled;
+ vec4 position;
+ vec4 diffuse;
+ vec4 specular;
+ float constantAttenuation, linearAttenuation, quadraticAttenuation;
+ float spotCutoff, spotExponent;
+ vec3 spotDirection;
+};
+
+uniform int numberOfLights;
+const int maxLights = 2;
+uniform lightSource glLightSource[maxLights];
+
+void main()
+{
+ vec4 baseMap = texture2D( BaseMap, glTexCoord0.st );
+
+ vec3 lightDirection;
+ float attenuation;
+
+ // initialize total lighting with ambient lighting
+ vec3 totalDiffuseLighting = vec3(glFrontMaterial.emission) + (vec3(glLightModelambient) * vec3(glFrontMaterial.ambient));
+ vec3 totalSpecularLighting;
+
+ for (int index = 0; index < numberOfLights; index++) // for all light sources
+ {
+ if(glLightSource[index].enabled == 1)
+ {
+ if (0.0 == glLightSource[index].position.w) // directional light?
+ {
+ attenuation = 1.0; // no attenuation
+ lightDirection = normalize(vec3(glLightSource[index].position));
+
+ }
+ else // point light or spotlight (or other kind of light)
+ {
+ vec3 positionToLightSource = vec3(glLightSource[index].position - position);
+ float distance = length(positionToLightSource);
+ lightDirection = normalize(positionToLightSource);
+ attenuation = 1.0 / (glLightSource[index].constantAttenuation
+ + glLightSource[index].linearAttenuation * distance
+ + glLightSource[index].quadraticAttenuation * distance * distance);
+
+ if (glLightSource[index].spotCutoff <= 90.0) // spotlight?
+ {
+ float clampedCosine = max(0.0, dot(-lightDirection, normalize(glLightSource[index].spotDirection)));
+ if (clampedCosine < cos(radians(glLightSource[index].spotCutoff))) // outside of spotlight cone?
+ {
+ attenuation = 0.0;
+ }
+ else
+ {
+ attenuation = attenuation * pow(clampedCosine, glLightSource[index].spotExponent);
+ }
+ }
+ }
+
+ vec3 diffuseReflection = attenuation * vec3(glLightSource[index].diffuse) * vec3(glFrontMaterial.diffuse)* max(0.0, dot(normalDirection, lightDirection));
+
+ vec3 specularReflection;
+ if (dot(normalDirection, lightDirection) < 0.0) // light source on the wrong side?
+ {
+ specularReflection = vec3(0.0, 0.0, 0.0); // no specular reflection
+ }
+ else // light source on the right side
+ {
+ specularReflection = attenuation * vec3(glLightSource[index].specular) * vec3(glFrontMaterial.specular)
+ * pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), glFrontMaterial.shininess);
+ }
+
+ totalDiffuseLighting = totalDiffuseLighting + diffuseReflection;
+ totalSpecularLighting = totalSpecularLighting + specularReflection;
+ }
+ }
+
+ totalDiffuseLighting = totalDiffuseLighting * baseMap.rgb;
+
+ gl_FragColor = vec4(totalDiffuseLighting + totalSpecularLighting, 1.0);
+}
diff --git a/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.vert b/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.vert
new file mode 100644
index 0000000..7e492e3
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.vert
@@ -0,0 +1,35 @@
+// GL2ES2: Java3D built-in attributes, these are calculated and passsed in if declared here
+attribute vec4 glVertex;
+attribute vec3 glNormal;
+attribute vec2 glMultiTexCoord0;
+
+// GL2ES2: Java3D built-in uniforms, these are calculated and passsed in if declared here
+uniform mat4 glModelViewProjectionMatrix;
+uniform mat4 glModelViewMatrix;
+uniform mat3 glNormalMatrix;
+
+
+// Per-pixel normal (output to fragment shader)
+varying vec3 normalDirection;
+varying vec3 viewDirection;
+varying vec4 position;
+
+varying vec2 glTexCoord0;
+
+void main()
+{
+ normalDirection = normalize(vec3(glNormalMatrix * glNormal));
+ vec3 v = vec3(glModelViewMatrix * glVertex);
+ viewDirection = normalize(-v.xyz);
+ position = vec4(v,1);
+ glTexCoord0 = glMultiTexCoord0.st;
+
+ // Transform the vertex
+ gl_Position = glModelViewProjectionMatrix * glVertex;
+}
+
+
+
+
+
+