OSDN Git Service

Set optimal mime types and executable settings.
[mikumikustudio/MikuMikuStudio.git] / src / jmetest / renderer / state / TestGLSLShaderObjectsState.java
1 /*
2  * Copyright (c) 2003-2009 jMonkeyEngine
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  *   notice, this list of conditions and the following disclaimer in the
14  *   documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 
17  *   may be used to endorse or promote products derived from this software 
18  *   without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 package jmetest.renderer.state;
34
35 import java.util.logging.Logger;
36
37 import com.jme.app.SimpleGame;
38 import com.jme.input.NodeHandler;
39 import com.jme.math.Vector3f;
40 import com.jme.renderer.ColorRGBA;
41 import com.jme.scene.shape.Quad;
42 import com.jme.scene.state.GLSLShaderObjectsState;
43
44 /**
45  * @author Thomas Hourdel
46  */
47 public class TestGLSLShaderObjectsState extends SimpleGame {
48     private static final Logger logger = Logger
49             .getLogger(TestGLSLShaderObjectsState.class.getName());
50
51     public static void main(String[] args) {
52         TestGLSLShaderObjectsState app = new TestGLSLShaderObjectsState();
53         app.setConfigShowMode(ConfigShowMode.AlwaysShow);
54         app.start();
55     }
56
57     protected void simpleInitGame() {
58         display.setTitle( "GLSL" );
59         display.getRenderer().setBackgroundColor(
60                 new ColorRGBA( 0.0f, 0.0f, 0.0f, 0.0f ) );
61
62         cam.setLocation( new Vector3f( 0, 0, 2 ) );
63         cam.update();
64         input = new NodeHandler( rootNode, 10, 2 );
65
66         Quad brick = createBrickQuad();
67         rootNode.attachChild( brick );
68
69         rootNode.updateRenderState();
70     }
71
72     private Quad createBrickQuad() {
73
74         // Check is GLSL is supported on current hardware.
75         if (!GLSLShaderObjectsState.isSupported()) {
76             logger.severe("Your graphics card does not support GLSL programs, and thus cannot run this test.");
77             quit();
78         }
79
80         GLSLShaderObjectsState so = display.getRenderer()
81                 .createGLSLShaderObjectsState();
82
83         so.load(TestGLSLShaderObjectsState.class.getClassLoader().getResource(
84                 "jmetest/data/images/shader.vert"),
85                 TestGLSLShaderObjectsState.class.getClassLoader().getResource(
86                         "jmetest/data/images/shader.frag"));
87         so.setUniform("BrickColor", 1.0f, 0.3f, 0.2f);
88         so.setUniform("MortarColor", 0.85f, 0.86f, 0.84f);
89         so.setUniform("BrickSize", 0.30f, 0.15f);
90         so.setUniform("BrickPct", 0.90f, 0.85f);
91         so.setUniform("LightPosition", 0.0f, 0.0f, 4.0f);
92         so.setEnabled(true);
93
94         //Generate the torus
95         Quad box = new Quad("glslQuad", 1f, 1f);
96         box.setRenderState(so);
97
98         return box;
99     }
100 }