Source Code Cross Referenced for ShaderTestGLSL.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3d » examples » glsl_shader » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » java 3d » org.jdesktop.j3d.examples.glsl_shader 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: ShaderTestGLSL.java,v $
003:         *
004:         * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * - Redistribution of source code must retain the above copyright
011:         *   notice, this list of conditions and the following disclaimer.
012:         *
013:         * - Redistribution in binary form must reproduce the above copyright
014:         *   notice, this list of conditions and the following disclaimer in
015:         *   the documentation and/or other materials provided with the
016:         *   distribution.
017:         *
018:         * Neither the name of Sun Microsystems, Inc. or the names of
019:         * contributors may be used to endorse or promote products derived
020:         * from this software without specific prior written permission.
021:         *
022:         * This software is provided "AS IS," without a warranty of any
023:         * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024:         * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025:         * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026:         * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027:         * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028:         * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029:         * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030:         * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031:         * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032:         * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033:         * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034:         * POSSIBILITY OF SUCH DAMAGES.
035:         *
036:         * You acknowledge that this software is not designed, licensed or
037:         * intended for use in the design, construction, operation or
038:         * maintenance of any nuclear facility.
039:         *
040:         * $Revision: 1.4 $
041:         * $Date: 2007/02/09 17:21:41 $
042:         * $State: Exp $
043:         */
044:
045:        package org.jdesktop.j3d.examples.glsl_shader;
046:
047:        import com.sun.j3d.utils.geometry.Sphere;
048:        import com.sun.j3d.utils.shader.StringIO;
049:        import com.sun.j3d.utils.universe.*;
050:        import javax.media.j3d.*;
051:        import javax.vecmath.*;
052:        import java.awt.GraphicsConfiguration;
053:        import java.io.IOException;
054:        import javax.swing.JOptionPane;
055:        import org.jdesktop.j3d.examples.Resources;
056:
057:        public class ShaderTestGLSL extends javax.swing.JFrame {
058:
059:            static final int GOLD = 1;
060:            static final int SILVER = 2;
061:
062:            static final int DIMPLE_SHADER = 1;
063:            static final int BRICK_SHADER = 2;
064:            static final int WOOD_SHADER = 3;
065:            static final int POLKADOT3D_SHADER = 4;
066:
067:            static final String[] shaderAttrNames1 = { "Density", "Size",
068:                    "LightPosition", "Color" };
069:
070:            static final String[] shaderAttrNames2 = { "BrickColor",
071:                    "LightPosition" };
072:
073:            private SimpleUniverse univ = null;
074:            private View view;
075:            private BranchGroup transpObj;
076:            private BranchGroup scene = null;
077:            private int shaderSelected = DIMPLE_SHADER;
078:            private float density = 16.0f;
079:            private int color = GOLD;
080:
081:            private Color3f eColor = new Color3f(0.2f, 0.2f, 0.2f);
082:            private Color3f sColor = new Color3f(0.8f, 0.8f, 0.8f);
083:            private Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f);
084:            private Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
085:            private Color3f gold = new Color3f(0.7f, 0.6f, 0.18f);
086:            private Color3f silver = new Color3f(0.75f, 0.75f, 0.75f);
087:
088:            // Handlers for doing update
089:            private ShaderAppearance sApp1 = null;
090:            private ShaderAppearance sApp2 = null;
091:            private ShaderAppearance sApp3 = null;
092:            private ShaderAppearance sApp4 = null;
093:            private ShaderProgram sp1 = null;
094:            private ShaderProgram sp2 = null;
095:            private ShaderProgram sp3 = null;
096:            private ShaderProgram sp4 = null;
097:            private ShaderAttributeSet sas1 = null;
098:            private ShaderAttributeSet sas2 = null;
099:            private ShaderAttributeObject sao1 = null;
100:            private ShaderAttributeObject sao2 = null;
101:            private Sphere sphere = null;
102:            private Shape3D s3d = null;
103:
104:            private Material createMaterial() {
105:                Material m;
106:                m = new Material(objColor, eColor, objColor, sColor, 100.0f);
107:                m.setLightingEnable(true);
108:                return m;
109:            }
110:
111:            private ShaderProgram createGLSLShaderProgram(int index) {
112:                String vertexProgram = null;
113:                String fragmentProgram = null;
114:                try {
115:                    switch (index) {
116:                    case DIMPLE_SHADER:
117:                        vertexProgram = StringIO.readFully(Resources
118:                                .getResource("glsl_shader/dimple.vert"));
119:                        fragmentProgram = StringIO.readFully(Resources
120:                                .getResource("glsl_shader/dimple.frag"));
121:                        break;
122:                    case BRICK_SHADER:
123:                        vertexProgram = StringIO.readFully(Resources
124:                                .getResource("glsl_shader/aabrick.vert"));
125:                        fragmentProgram = StringIO.readFully(Resources
126:                                .getResource("glsl_shader/aabrick.frag"));
127:                        break;
128:                    case WOOD_SHADER:
129:                        vertexProgram = StringIO.readFully(Resources
130:                                .getResource("glsl_shader/wood.vert"));
131:                        fragmentProgram = StringIO.readFully(Resources
132:                                .getResource("glsl_shader/wood.frag"));
133:                        break;
134:                    case POLKADOT3D_SHADER:
135:                        vertexProgram = StringIO.readFully(Resources
136:                                .getResource("glsl_shader/polkadot3d.vert"));
137:                        fragmentProgram = StringIO.readFully(Resources
138:                                .getResource("glsl_shader/polkadot3d.frag"));
139:                        break;
140:                    default:
141:                    }
142:                } catch (IOException e) {
143:                    throw new RuntimeException(e);
144:                }
145:                Shader[] shaders = new Shader[2];
146:                shaders[0] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL,
147:                        Shader.SHADER_TYPE_VERTEX, vertexProgram);
148:                shaders[1] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL,
149:                        Shader.SHADER_TYPE_FRAGMENT, fragmentProgram);
150:                ShaderProgram shaderProgram = new GLSLShaderProgram();
151:                shaderProgram.setShaders(shaders);
152:                return shaderProgram;
153:            }
154:
155:            private ShaderAttributeSet createShaderAttributeSet(int index) {
156:                ShaderAttributeSet shaderAttributeSet = new ShaderAttributeSet();
157:                ShaderAttributeObject shaderAttribute = null;
158:
159:                switch (index) {
160:                case DIMPLE_SHADER:
161:                    //  "Density", "Size", "Scale", "Color", "LightPosition"
162:                    shaderAttribute = new ShaderAttributeValue("Size",
163:                            new Float(0.25));
164:                    shaderAttributeSet.put(shaderAttribute);
165:                    shaderAttribute = new ShaderAttributeValue("LightPosition",
166:                            new Point3f(0.0f, 0.0f, 0.5f));
167:                    shaderAttributeSet.put(shaderAttribute);
168:
169:                    sao1 = new ShaderAttributeValue("Density", new Float(
170:                            density));
171:                    sao1.setCapability(ShaderAttributeObject.ALLOW_VALUE_READ);
172:                    sao1.setCapability(ShaderAttributeObject.ALLOW_VALUE_WRITE);
173:                    shaderAttributeSet.put(sao1);
174:
175:                    if (color == GOLD) {
176:                        sao2 = new ShaderAttributeValue("Color", gold);
177:                    } else if (color == SILVER) {
178:                        sao2 = new ShaderAttributeValue("Color", silver);
179:                    }
180:                    sao2.setCapability(ShaderAttributeObject.ALLOW_VALUE_READ);
181:                    sao2.setCapability(ShaderAttributeObject.ALLOW_VALUE_WRITE);
182:                    shaderAttributeSet.put(sao2);
183:                    break;
184:
185:                case BRICK_SHADER:
186:                    // "BrickColor", "LightPosition"
187:                    shaderAttribute = new ShaderAttributeValue("BrickColor",
188:                            new Color3f(1.0f, 0.3f, 0.2f));
189:                    shaderAttributeSet.put(shaderAttribute);
190:                    shaderAttribute = new ShaderAttributeValue("LightPosition",
191:                            new Point3f(0.0f, 0.0f, 0.5f));
192:                    shaderAttributeSet.put(shaderAttribute);
193:                    break;
194:                default:
195:                    assert false;
196:                }
197:                return shaderAttributeSet;
198:            }
199:
200:            private ShaderAppearance createShaderAppearance() {
201:                ShaderAppearance sApp = new ShaderAppearance();
202:                sApp.setMaterial(createMaterial());
203:                return sApp;
204:            }
205:
206:            private BranchGroup createSubSceneGraph() {
207:                // Create the sub-root of the branch graph
208:                BranchGroup subRoot = new BranchGroup();
209:
210:                //
211:                // Create 1 spheres with a GLSLShader and add it into the scene graph.
212:                //
213:                sApp1 = createShaderAppearance();
214:                sApp1.setCapability(ShaderAppearance.ALLOW_SHADER_PROGRAM_READ);
215:                sApp1
216:                        .setCapability(ShaderAppearance.ALLOW_SHADER_PROGRAM_WRITE);
217:                sApp1
218:                        .setCapability(ShaderAppearance.ALLOW_SHADER_ATTRIBUTE_SET_READ);
219:                sApp1
220:                        .setCapability(ShaderAppearance.ALLOW_SHADER_ATTRIBUTE_SET_WRITE);
221:
222:                sp1 = createGLSLShaderProgram(1);
223:                sp1.setShaderAttrNames(shaderAttrNames1);
224:                sas1 = createShaderAttributeSet(1);
225:                sas1.setCapability(ShaderAttributeSet.ALLOW_ATTRIBUTES_READ);
226:                sas1.setCapability(ShaderAttributeSet.ALLOW_ATTRIBUTES_WRITE);
227:                sApp1.setShaderProgram(sp1);
228:                sApp1.setShaderAttributeSet(sas1);
229:
230:                // Setup Brick shader
231:                sp2 = createGLSLShaderProgram(2);
232:                sp2.setShaderAttrNames(shaderAttrNames2);
233:                sas2 = createShaderAttributeSet(2);
234:                sApp2 = createShaderAppearance();
235:                sApp2.setShaderProgram(sp2);
236:                sApp2.setShaderAttributeSet(sas2);
237:
238:                // Setup Wood shader
239:                sp3 = createGLSLShaderProgram(3);
240:                sApp3 = createShaderAppearance();
241:                sApp3.setShaderProgram(sp3);
242:
243:                // Setup Polkadot3d shader
244:                sp4 = createGLSLShaderProgram(4);
245:                sApp4 = createShaderAppearance();
246:                sApp4.setShaderProgram(sp4);
247:
248:                sphere = new Sphere(1.5f, Sphere.GENERATE_NORMALS, 200, null);
249:                s3d = (Shape3D) sphere.getShape();
250:                s3d.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
251:                s3d.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
252:                s3d.setAppearance(sApp1);
253:
254:                TransformGroup objTG;
255:                Transform3D t = new Transform3D();
256:                t.set(new Vector3d(0.0, 0.0, 0.0));
257:                objTG = new TransformGroup(t);
258:                objTG.addChild(sphere);
259:                subRoot.addChild(objTG);
260:
261:                return subRoot;
262:            }
263:
264:            private BranchGroup createSceneGraph(int selectedScene) {
265:                // Create the root of the branch graph
266:                BranchGroup objRoot = new BranchGroup();
267:                objRoot.setCapability(BranchGroup.ALLOW_DETACH);
268:
269:                // Create a Transformgroup to scale all objects so they
270:                // appear in the scene.
271:                TransformGroup objScale = new TransformGroup();
272:                Transform3D t3d = new Transform3D();
273:                t3d.setScale(0.4);
274:                objScale.setTransform(t3d);
275:                objRoot.addChild(objScale);
276:
277:                // Create a bounds for the background and lights
278:                BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,
279:                        0.0, 0.0), 100.0);
280:
281:                // Set up the background
282:                Background bg = new Background(bgColor);
283:                bg.setApplicationBounds(bounds);
284:                objScale.addChild(bg);
285:
286:                objScale.addChild(createSubSceneGraph());
287:
288:                // Create a position interpolator and attach it to the view
289:                // platform
290:                TransformGroup vpTrans = univ.getViewingPlatform()
291:                        .getViewPlatformTransform();
292:                Transform3D axisOfTranslation = new Transform3D();
293:                Alpha transAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE
294:                        | Alpha.DECREASING_ENABLE, 0, 0, 5000, 0, 0, 5000, 0, 0);
295:                axisOfTranslation.rotY(-Math.PI / 2.0);
296:                PositionInterpolator translator = new PositionInterpolator(
297:                        transAlpha, vpTrans, axisOfTranslation, 2.0f, 3.5f);
298:                translator.setSchedulingBounds(bounds);
299:                objScale.addChild(translator);
300:
301:                // Let Java 3D perform optimizations on this scene graph.
302:                objRoot.compile();
303:
304:                return objRoot;
305:            }
306:
307:            private Canvas3D initScene() {
308:                GraphicsConfiguration config = SimpleUniverse
309:                        .getPreferredConfiguration();
310:
311:                Canvas3D c = new Canvas3D(config);
312:
313:                univ = new SimpleUniverse(c);
314:
315:                // Add a ShaderErrorListener
316:                univ.addShaderErrorListener(new ShaderErrorListener() {
317:                    public void errorOccurred(ShaderError error) {
318:                        error.printVerbose();
319:                        JOptionPane.showMessageDialog(ShaderTestGLSL.this ,
320:                                error.toString(), "ShaderError",
321:                                JOptionPane.ERROR_MESSAGE);
322:                    }
323:                });
324:
325:                ViewingPlatform viewingPlatform = univ.getViewingPlatform();
326:                // This will move the ViewPlatform back a bit so the
327:                // objects in the scene can be viewed.
328:                viewingPlatform.setNominalViewingTransform();
329:
330:                view = univ.getViewer().getView();
331:
332:                return c;
333:            }
334:
335:            /**
336:             * Creates new form ShaderTestGLSL
337:             */
338:            public ShaderTestGLSL() {
339:                // Initialize the GUI components
340:                initComponents();
341:
342:                // Create the scene and add the Canvas3D to the drawing panel
343:                Canvas3D c = initScene();
344:                drawingPanel.add(c, java.awt.BorderLayout.CENTER);
345:            }
346:
347:            // ----------------------------------------------------------------
348:
349:            /** This method is called from within the constructor to
350:             * initialize the form.
351:             * WARNING: Do NOT modify this code. The content of this method is
352:             * always regenerated by the Form Editor.
353:             */
354:            // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
355:            private void initComponents() {
356:                java.awt.GridBagConstraints gridBagConstraints;
357:
358:                densityButtonGroup = new javax.swing.ButtonGroup();
359:                colorButtonGroup = new javax.swing.ButtonGroup();
360:                sceneGraphButtonGroup = new javax.swing.ButtonGroup();
361:                mainPanel = new javax.swing.JPanel();
362:                guiPanel = new javax.swing.JPanel();
363:                densityPanel = new javax.swing.JPanel();
364:                zeroButton = new javax.swing.JRadioButton();
365:                halfButton = new javax.swing.JRadioButton();
366:                fullButton = new javax.swing.JRadioButton();
367:                colorPanel = new javax.swing.JPanel();
368:                goldButton = new javax.swing.JRadioButton();
369:                silverButton = new javax.swing.JRadioButton();
370:                sceneGraphPanel = new javax.swing.JPanel();
371:                DetachButton = new javax.swing.JToggleButton();
372:                AttachButton = new javax.swing.JToggleButton();
373:                replaceSPButton = new javax.swing.JButton();
374:                drawingPanel = new javax.swing.JPanel();
375:                jMenuBar1 = new javax.swing.JMenuBar();
376:                fileMenu = new javax.swing.JMenu();
377:                exitMenuItem = new javax.swing.JMenuItem();
378:
379:                setTitle("Window Title");
380:                addWindowListener(new java.awt.event.WindowAdapter() {
381:                    public void windowClosing(java.awt.event.WindowEvent evt) {
382:                        exitForm(evt);
383:                    }
384:                });
385:
386:                mainPanel.setLayout(new java.awt.BorderLayout());
387:
388:                guiPanel.setLayout(new javax.swing.BoxLayout(guiPanel,
389:                        javax.swing.BoxLayout.X_AXIS));
390:
391:                guiPanel.setBorder(new javax.swing.border.LineBorder(
392:                        new java.awt.Color(0, 0, 0)));
393:                densityPanel.setLayout(new java.awt.GridBagLayout());
394:
395:                densityPanel.setBorder(new javax.swing.border.TitledBorder(
396:                        "Density"));
397:                densityButtonGroup.add(zeroButton);
398:                zeroButton.setText("Zero");
399:                zeroButton
400:                        .addActionListener(new java.awt.event.ActionListener() {
401:                            public void actionPerformed(
402:                                    java.awt.event.ActionEvent evt) {
403:                                zeroButtonActionPerformed(evt);
404:                            }
405:                        });
406:
407:                gridBagConstraints = new java.awt.GridBagConstraints();
408:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
409:                densityPanel.add(zeroButton, gridBagConstraints);
410:
411:                densityButtonGroup.add(halfButton);
412:                halfButton.setText("Half");
413:                halfButton
414:                        .addActionListener(new java.awt.event.ActionListener() {
415:                            public void actionPerformed(
416:                                    java.awt.event.ActionEvent evt) {
417:                                halfButtonActionPerformed(evt);
418:                            }
419:                        });
420:
421:                gridBagConstraints = new java.awt.GridBagConstraints();
422:                gridBagConstraints.gridx = 0;
423:                gridBagConstraints.gridy = 1;
424:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
425:                densityPanel.add(halfButton, gridBagConstraints);
426:
427:                densityButtonGroup.add(fullButton);
428:                fullButton.setSelected(true);
429:                fullButton.setText("Full");
430:                fullButton
431:                        .addActionListener(new java.awt.event.ActionListener() {
432:                            public void actionPerformed(
433:                                    java.awt.event.ActionEvent evt) {
434:                                fullButtonActionPerformed(evt);
435:                            }
436:                        });
437:
438:                gridBagConstraints = new java.awt.GridBagConstraints();
439:                gridBagConstraints.gridx = 0;
440:                gridBagConstraints.gridy = 2;
441:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
442:                densityPanel.add(fullButton, gridBagConstraints);
443:
444:                guiPanel.add(densityPanel);
445:                densityPanel.getAccessibleContext().setAccessibleName(
446:                        "ShaderAttributeValue \n");
447:
448:                colorPanel.setLayout(new java.awt.GridBagLayout());
449:
450:                colorPanel.setBorder(new javax.swing.border.TitledBorder(
451:                        "Color"));
452:                colorButtonGroup.add(goldButton);
453:                goldButton.setSelected(true);
454:                goldButton.setText("Gold");
455:                goldButton
456:                        .addActionListener(new java.awt.event.ActionListener() {
457:                            public void actionPerformed(
458:                                    java.awt.event.ActionEvent evt) {
459:                                goldButtonActionPerformed(evt);
460:                            }
461:                        });
462:
463:                gridBagConstraints = new java.awt.GridBagConstraints();
464:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
465:                colorPanel.add(goldButton, gridBagConstraints);
466:
467:                colorButtonGroup.add(silverButton);
468:                silverButton.setText("Silver");
469:                silverButton
470:                        .addActionListener(new java.awt.event.ActionListener() {
471:                            public void actionPerformed(
472:                                    java.awt.event.ActionEvent evt) {
473:                                silverButtonActionPerformed(evt);
474:                            }
475:                        });
476:
477:                gridBagConstraints = new java.awt.GridBagConstraints();
478:                gridBagConstraints.gridx = 0;
479:                gridBagConstraints.gridy = 1;
480:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
481:                colorPanel.add(silverButton, gridBagConstraints);
482:
483:                guiPanel.add(colorPanel);
484:
485:                sceneGraphPanel.setLayout(new java.awt.GridBagLayout());
486:
487:                sceneGraphPanel.setBorder(new javax.swing.border.TitledBorder(
488:                        "Scene Graph"));
489:                sceneGraphButtonGroup.add(DetachButton);
490:                DetachButton.setSelected(true);
491:                DetachButton.setText("Detach");
492:                DetachButton
493:                        .addActionListener(new java.awt.event.ActionListener() {
494:                            public void actionPerformed(
495:                                    java.awt.event.ActionEvent evt) {
496:                                DetachButtonActionPerformed(evt);
497:                            }
498:                        });
499:
500:                gridBagConstraints = new java.awt.GridBagConstraints();
501:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
502:                sceneGraphPanel.add(DetachButton, gridBagConstraints);
503:
504:                sceneGraphButtonGroup.add(AttachButton);
505:                AttachButton.setText("Create");
506:                AttachButton
507:                        .addActionListener(new java.awt.event.ActionListener() {
508:                            public void actionPerformed(
509:                                    java.awt.event.ActionEvent evt) {
510:                                AttachButtonActionPerformed(evt);
511:                            }
512:                        });
513:
514:                gridBagConstraints = new java.awt.GridBagConstraints();
515:                gridBagConstraints.gridx = 0;
516:                gridBagConstraints.gridy = 1;
517:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
518:                sceneGraphPanel.add(AttachButton, gridBagConstraints);
519:
520:                replaceSPButton.setText("Replace Shader");
521:                replaceSPButton.setEnabled(false);
522:                replaceSPButton
523:                        .addActionListener(new java.awt.event.ActionListener() {
524:                            public void actionPerformed(
525:                                    java.awt.event.ActionEvent evt) {
526:                                replaceSPButtonActionPerformed(evt);
527:                            }
528:                        });
529:
530:                gridBagConstraints = new java.awt.GridBagConstraints();
531:                gridBagConstraints.gridx = 0;
532:                gridBagConstraints.gridy = 2;
533:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
534:                sceneGraphPanel.add(replaceSPButton, gridBagConstraints);
535:
536:                guiPanel.add(sceneGraphPanel);
537:
538:                mainPanel.add(guiPanel, java.awt.BorderLayout.NORTH);
539:
540:                drawingPanel.setLayout(new java.awt.BorderLayout());
541:
542:                drawingPanel.setPreferredSize(new java.awt.Dimension(500, 500));
543:                mainPanel.add(drawingPanel, java.awt.BorderLayout.CENTER);
544:
545:                getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER);
546:
547:                fileMenu.setText("File");
548:                exitMenuItem.setText("Exit");
549:                exitMenuItem
550:                        .addActionListener(new java.awt.event.ActionListener() {
551:                            public void actionPerformed(
552:                                    java.awt.event.ActionEvent evt) {
553:                                exitMenuItemActionPerformed(evt);
554:                            }
555:                        });
556:
557:                fileMenu.add(exitMenuItem);
558:
559:                jMenuBar1.add(fileMenu);
560:
561:                setJMenuBar(jMenuBar1);
562:
563:                pack();
564:            }
565:
566:            // </editor-fold>//GEN-END:initComponents
567:
568:            private void silverButtonActionPerformed(
569:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_silverButtonActionPerformed
570:                color = SILVER;
571:                if (scene != null) {
572:                    sao2.setValue(silver);
573:                }
574:            }//GEN-LAST:event_silverButtonActionPerformed
575:
576:            private void goldButtonActionPerformed(
577:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goldButtonActionPerformed
578:                color = GOLD;
579:                if (scene != null) {
580:                    sao2.setValue(gold);
581:                }
582:            }//GEN-LAST:event_goldButtonActionPerformed
583:
584:            private void replaceSPButtonActionPerformed(
585:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_replaceSPButtonActionPerformed
586:                if (shaderSelected != DIMPLE_SHADER) {
587:                    goldButton.setEnabled(false);
588:                    silverButton.setEnabled(false);
589:                    zeroButton.setEnabled(false);
590:                    halfButton.setEnabled(false);
591:                    fullButton.setEnabled(false);
592:                }
593:
594:                switch (shaderSelected) {
595:                case DIMPLE_SHADER:
596:                    s3d.setAppearance(sApp1);
597:                    goldButton.setEnabled(true);
598:                    silverButton.setEnabled(true);
599:                    zeroButton.setEnabled(true);
600:                    halfButton.setEnabled(true);
601:                    fullButton.setEnabled(true);
602:                    shaderSelected = BRICK_SHADER;
603:                    break;
604:                case BRICK_SHADER:
605:                    s3d.setAppearance(sApp2);
606:                    shaderSelected = WOOD_SHADER;
607:                    break;
608:                case WOOD_SHADER:
609:                    s3d.setAppearance(sApp3);
610:                    shaderSelected = POLKADOT3D_SHADER;
611:                    break;
612:                case POLKADOT3D_SHADER:
613:                    s3d.setAppearance(sApp4);
614:                    shaderSelected = DIMPLE_SHADER;
615:                    break;
616:                default:
617:                    assert false;
618:                }
619:
620:            }//GEN-LAST:event_replaceSPButtonActionPerformed
621:
622:            private void fullButtonActionPerformed(
623:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fullButtonActionPerformed
624:                density = 16.0f;
625:                if (scene != null) {
626:                    sao1.setValue(new Float(density));
627:                }
628:            }//GEN-LAST:event_fullButtonActionPerformed
629:
630:            private void DetachButtonActionPerformed(
631:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DetachButtonActionPerformed
632:                if (scene != null) {
633:                    scene.detach();
634:                    scene = null;
635:                    replaceSPButton.setEnabled(false);
636:                    goldButton.setEnabled(true);
637:                    silverButton.setEnabled(true);
638:                    zeroButton.setEnabled(true);
639:                    halfButton.setEnabled(true);
640:                    fullButton.setEnabled(true);
641:                    shaderSelected = DIMPLE_SHADER;
642:                }
643:            }//GEN-LAST:event_DetachButtonActionPerformed
644:
645:            private void AttachButtonActionPerformed(
646:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AttachButtonActionPerformed
647:                if (scene == null) {
648:                    scene = createSceneGraph(1);
649:                    univ.addBranchGraph(scene);
650:                    replaceSPButton.setEnabled(true);
651:                    shaderSelected = BRICK_SHADER;
652:                }
653:            }//GEN-LAST:event_AttachButtonActionPerformed
654:
655:            private void halfButtonActionPerformed(
656:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_halfButtonActionPerformed
657:                density = 8.0f;
658:                if (scene != null) {
659:                    sao1.setValue(new Float(density));
660:                }
661:            }//GEN-LAST:event_halfButtonActionPerformed
662:
663:            private void zeroButtonActionPerformed(
664:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zeroButtonActionPerformed
665:                density = 0.0f;
666:                if (scene != null) {
667:                    sao1.setValue(new Float(density));
668:                }
669:
670:            }//GEN-LAST:event_zeroButtonActionPerformed
671:
672:            private void exitMenuItemActionPerformed(
673:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
674:                System.exit(0);
675:            }//GEN-LAST:event_exitMenuItemActionPerformed
676:
677:            /** Exit the Application */
678:            private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
679:                System.exit(0);
680:            }//GEN-LAST:event_exitForm
681:
682:            /**
683:             * @param args the command line arguments
684:             */
685:            public static void main(String args[]) {
686:                new ShaderTestGLSL().setVisible(true);
687:            }
688:
689:            // Variables declaration - do not modify//GEN-BEGIN:variables
690:            private javax.swing.JToggleButton AttachButton;
691:            private javax.swing.JToggleButton DetachButton;
692:            private javax.swing.ButtonGroup colorButtonGroup;
693:            private javax.swing.JPanel colorPanel;
694:            private javax.swing.ButtonGroup densityButtonGroup;
695:            private javax.swing.JPanel densityPanel;
696:            private javax.swing.JPanel drawingPanel;
697:            private javax.swing.JMenuItem exitMenuItem;
698:            private javax.swing.JMenu fileMenu;
699:            private javax.swing.JRadioButton fullButton;
700:            private javax.swing.JRadioButton goldButton;
701:            private javax.swing.JPanel guiPanel;
702:            private javax.swing.JRadioButton halfButton;
703:            private javax.swing.JMenuBar jMenuBar1;
704:            private javax.swing.JPanel mainPanel;
705:            private javax.swing.JButton replaceSPButton;
706:            private javax.swing.ButtonGroup sceneGraphButtonGroup;
707:            private javax.swing.JPanel sceneGraphPanel;
708:            private javax.swing.JRadioButton silverButton;
709:            private javax.swing.JRadioButton zeroButton;
710:            // End of variables declaration//GEN-END:variables
711:
712:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.