|
| 1 | +/* |
| 2 | + * Copyright (c) 2009-2021 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 | +package jme3test.renderer; |
| 33 | + |
| 34 | +import com.jme3.app.SimpleApplication; |
| 35 | +import com.jme3.input.KeyInput; |
| 36 | +import com.jme3.input.controls.ActionListener; |
| 37 | +import com.jme3.input.controls.KeyTrigger; |
| 38 | +import com.jme3.material.Material; |
| 39 | +import com.jme3.math.ColorRGBA; |
| 40 | +import com.jme3.math.FastMath; |
| 41 | +import com.jme3.math.Quaternion; |
| 42 | +import com.jme3.renderer.RenderManager; |
| 43 | +import com.jme3.renderer.ViewPort; |
| 44 | +import com.jme3.scene.Geometry; |
| 45 | +import com.jme3.scene.control.AbstractControl; |
| 46 | +import com.jme3.scene.shape.Box; |
| 47 | +import com.jme3.system.AppSettings; |
| 48 | + |
| 49 | +/** |
| 50 | + * Tests whether gamma correction works after a context restart. This test |
| 51 | + * generates a series of boxes, each one with a slightly different shade from |
| 52 | + * the other. If the boxes look the same before and after the restart, that |
| 53 | + * means that gamma correction is working properly. |
| 54 | + * <p> |
| 55 | + * Note that for testing, it may be helpful to bypass the test chooser and run |
| 56 | + * this class directly, since it can be easier to define your own settings |
| 57 | + * beforehand. Of course, it should still workif all you need to test is the |
| 58 | + * gamma correction, as long as you enable it in the settings dialog. |
| 59 | + * </p> |
| 60 | + * |
| 61 | + * @author Markil 3 |
| 62 | + */ |
| 63 | +public class TestContextRestart extends SimpleApplication |
| 64 | +{ |
| 65 | + public static final String INPUT_RESTART_CONTEXT = "SIMPLEAPP_Restart"; |
| 66 | + |
| 67 | + public static void main(String[] args) |
| 68 | + { |
| 69 | + TestContextRestart app = new TestContextRestart(); |
| 70 | + AppSettings settings = new AppSettings(true); |
| 71 | + settings.setGammaCorrection(true); |
| 72 | +// settings.setRenderer(AppSettings.LWJGL_OPENGL32); |
| 73 | + app.setSettings(settings); |
| 74 | + app.start(); |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public void simpleInitApp() |
| 79 | + { |
| 80 | + for (int i = 0, l = 256; i < l; i += 8) |
| 81 | + { |
| 82 | + Geometry box = new Geometry("Box" + i, new Box(10, 200, 10)); |
| 83 | + Material mat = new Material(this.assetManager, |
| 84 | + "Common/MatDefs/Misc/Unshaded.j3md"); |
| 85 | + mat.setColor("Color", new ColorRGBA((float) i / 255F, 0, 0, 1)); |
| 86 | + box.setMaterial(mat); |
| 87 | + box.setLocalTranslation(-2.5F * (l / 2 - i), 0, -700); |
| 88 | + box.addControl(new AbstractControl() |
| 89 | + { |
| 90 | + @Override |
| 91 | + protected void controlUpdate(float tpf) |
| 92 | + { |
| 93 | + float[] angles = this.getSpatial() |
| 94 | + .getLocalRotation() |
| 95 | + .toAngles(new float[3]); |
| 96 | + angles[0] = angles[0] + (FastMath.PI / 500F); |
| 97 | + this.getSpatial() |
| 98 | + .setLocalRotation(new Quaternion().fromAngles(angles)); |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + protected void controlRender(RenderManager rm, ViewPort vp) |
| 103 | + { |
| 104 | + |
| 105 | + } |
| 106 | + }); |
| 107 | + this.rootNode.attachChild(box); |
| 108 | + } |
| 109 | + |
| 110 | + this.viewPort.setBackgroundColor(ColorRGBA.Yellow); |
| 111 | + |
| 112 | + this.flyCam.setEnabled(false); |
| 113 | + this.inputManager.setCursorVisible(true); |
| 114 | + |
| 115 | + inputManager.addMapping(INPUT_RESTART_CONTEXT, new KeyTrigger( |
| 116 | + KeyInput.KEY_TAB)); |
| 117 | + this.inputManager.addListener(new ActionListener() |
| 118 | + { |
| 119 | + @Override |
| 120 | + public void onAction(String name, boolean isPressed, float tpf) |
| 121 | + { |
| 122 | + if (name.equals(INPUT_RESTART_CONTEXT)) |
| 123 | + { |
| 124 | + restart(); |
| 125 | + } |
| 126 | + } |
| 127 | + }, INPUT_RESTART_CONTEXT); |
| 128 | + } |
| 129 | +} |
0 commit comments