Source Code Cross Referenced for TextureImageNPOT.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3d » examples » texture » 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.texture 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: TextureImageNPOT.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.7 $
041:         * $Date: 2007/04/24 18:55:58 $
042:         * $State: Exp $
043:         */
044:
045:        package org.jdesktop.j3d.examples.texture;
046:
047:        import com.sun.j3d.utils.applet.MainFrame;
048:        import com.sun.j3d.utils.geometry.Box;
049:        import com.sun.j3d.utils.image.TextureLoader;
050:        import com.sun.j3d.utils.universe.SimpleUniverse;
051:        import java.applet.Applet;
052:        import java.awt.BorderLayout;
053:        import java.awt.GraphicsConfiguration;
054:        import java.util.Map;
055:        import javax.media.j3d.*;
056:        import javax.swing.JOptionPane;
057:        import javax.vecmath.Point3d;
058:        import org.jdesktop.j3d.examples.Resources;
059:
060:        public class TextureImageNPOT extends Applet {
061:
062:            private static final String defaultFileName = "resources/images/Java3d.jpg";
063:            private java.net.URL texImage = null;
064:
065:            private SimpleUniverse u = null;
066:            private boolean allowNonPowerOfTwo = true;
067:            private boolean mipmap = true;
068:
069:            public BranchGroup createSceneGraph() {
070:                // Create the root of the branch graph
071:                BranchGroup objRoot = new BranchGroup();
072:
073:                // Create the transform group node and initialize it to the
074:                // identity.  Enable the TRANSFORM_WRITE capability so that
075:                // our behavior code can modify it at runtime.  Add it to the
076:                // root of the subgraph.
077:                TransformGroup objTrans = new TransformGroup();
078:                objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
079:                objRoot.addChild(objTrans);
080:
081:                // Create the scaling transform group node and initialize it to the
082:                // identity.  Enable the TRANSFORM_WRITE capability so that
083:                // our behavior code can modify it at runtime.  Add it to the
084:                // objTrans group
085:                TransformGroup objScale = new TransformGroup();
086:                objScale.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
087:                objTrans.addChild(objScale);
088:
089:                // Create appearance object for textured cube
090:                Appearance app = new Appearance();
091:                int flags = TextureLoader.BY_REFERENCE | TextureLoader.Y_UP;
092:
093:                if (allowNonPowerOfTwo) {
094:                    flags |= TextureLoader.ALLOW_NON_POWER_OF_TWO;
095:                }
096:                if (mipmap) {
097:                    flags |= TextureLoader.GENERATE_MIPMAP;
098:                }
099:                Texture tex = new TextureLoader(texImage, flags, this )
100:                        .getTexture();
101:                tex.setMagFilter(Texture.BASE_LEVEL_LINEAR);
102:                if (mipmap) {
103:                    tex.setMinFilter(Texture.MULTI_LEVEL_LINEAR);
104:                } else {
105:                    tex.setMinFilter(Texture.BASE_LEVEL_LINEAR);
106:                }
107:                app.setTexture(tex);
108:                TextureAttributes texAttr = new TextureAttributes();
109:                texAttr.setTextureMode(TextureAttributes.MODULATE);
110:                app.setTextureAttributes(texAttr);
111:
112:                // Create textured cube and add it to the scene graph.
113:                Box textureCube = new Box(0.4f, 0.4f, 0.4f,
114:                        Box.GENERATE_TEXTURE_COORDS
115:                                | Box.GENERATE_TEXTURE_COORDS_Y_UP, app);
116:                objScale.addChild(textureCube);
117:
118:                // Create a new Behavior object that will perform the desired
119:                // operation on the specified transform object and add it into
120:                // the scene graph.
121:                Transform3D yAxis = new Transform3D();
122:                Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0,
123:                        0, 50000, 0, 0, 0, 0, 0);
124:
125:                RotationInterpolator rotator = new RotationInterpolator(
126:                        rotationAlpha, objTrans, yAxis, 0.0f,
127:                        (float) Math.PI * 2.0f);
128:                BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,
129:                        0.0, 0.0), 100.0);
130:                rotator.setSchedulingBounds(bounds);
131:                objTrans.addChild(rotator);
132:
133:                // Create a new Behavior object that will perform the desired
134:                // operation on the specified transform object and add it into
135:                // the scene graph.
136:                Alpha scaleAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE
137:                        | Alpha.DECREASING_ENABLE, 0, 0, 8000, 0, 0, 8000, 0, 0);
138:
139:                ScaleInterpolator scaler = new ScaleInterpolator(scaleAlpha,
140:                        objScale, yAxis, 0.01f, 1.5f);
141:                scaler.setSchedulingBounds(bounds);
142:                objScale.addChild(scaler);
143:
144:                // Have Java 3D perform optimizations on this scene graph.
145:                objRoot.compile();
146:
147:                return objRoot;
148:            }
149:
150:            public TextureImageNPOT() {
151:            }
152:
153:            public TextureImageNPOT(java.net.URL url) {
154:                texImage = url;
155:            }
156:
157:            public void init() {
158:                if (texImage == null) {
159:                    // the path to the image for an applet
160:                    texImage = Resources.getResource(defaultFileName);
161:                    if (texImage == null) {
162:                        System.err.println(defaultFileName + " not found");
163:                        System.exit(1);
164:                    }
165:                }
166:                setLayout(new BorderLayout());
167:                GraphicsConfiguration config = SimpleUniverse
168:                        .getPreferredConfiguration();
169:
170:                Canvas3D c = new Canvas3D(config);
171:
172:                Map map = c.queryProperties();
173:                Boolean value = (Boolean) map
174:                        .get("textureNonPowerOfTwoAvailable");
175:                String errorStr = null;
176:                if (value == null) {
177:                    errorStr = "Canvas3D: textureNonPowerOfTwoAvailable property not found";
178:                } else if (!value) {
179:                    errorStr = "Non-power-of-two textures are not available";
180:                }
181:
182:                if (errorStr != null) {
183:                    String errorMessage = errorStr
184:                            + "\n"
185:                            + "You should expect to see a white cube as a result";
186:                    //            System.err.println(errorMessage);
187:                    JOptionPane.showMessageDialog(this , errorMessage,
188:                            "Insufficient Capabilities",
189:                            JOptionPane.ERROR_MESSAGE);
190:                }
191:
192:                add("Center", c);
193:
194:                // Create a simple scene and attach it to the virtual universe
195:                BranchGroup scene = createSceneGraph();
196:                u = new SimpleUniverse(c);
197:
198:                // This will move the ViewPlatform back a bit so the
199:                // objects in the scene can be viewed.
200:                u.getViewingPlatform().setNominalViewingTransform();
201:
202:                u.addBranchGraph(scene);
203:            }
204:
205:            public void destroy() {
206:                u.cleanup();
207:            }
208:
209:            //
210:            // The following allows TextureImageNPOT to be run as an application
211:            // as well as an applet
212:            //
213:            public static void main(String[] args) {
214:                java.net.URL url = null;
215:                if (args.length > 0) {
216:                    try {
217:                        url = new java.net.URL("file:" + args[0]);
218:                    } catch (java.net.MalformedURLException ex) {
219:                        System.out.println(ex.getMessage());
220:                        System.exit(1);
221:                    }
222:                } else {
223:                    // the path to the image for an application
224:                    url = Resources.getResource(defaultFileName);
225:                    if (url == null) {
226:                        System.err.println(defaultFileName + " not found");
227:                        System.exit(1);
228:                    }
229:                }
230:                new MainFrame(new TextureImageNPOT(url), 512, 512);
231:            }
232:
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.