Created
November 18, 2013 13:07
-
-
Save kwando/7527464 to your computer and use it in GitHub Desktop.
Auto updating shaders..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mygame; | |
import com.jme3.app.SimpleApplication; | |
import com.jme3.asset.DesktopAssetManager; | |
import com.jme3.material.Material; | |
import com.jme3.math.ColorRGBA; | |
import com.jme3.renderer.RenderManager; | |
import com.jme3.renderer.ViewPort; | |
import com.jme3.scene.Geometry; | |
import com.jme3.scene.Spatial; | |
import com.jme3.scene.control.AbstractControl; | |
import com.jme3.scene.shape.Box; | |
import com.jme3.system.AppSettings; | |
/** | |
* test | |
* | |
* @author kwando | |
*/ | |
public class Main extends SimpleApplication { | |
public static void main(String[] args) { | |
Main app = new Main(); | |
AppSettings settings = new AppSettings(true); | |
settings.setResolution(1280, 720); | |
settings.setVSync(true); | |
settings.setSamples(16); | |
app.setSettings(settings); | |
app.setShowSettings(false); | |
app.start(); | |
} | |
private boolean recreate = true; | |
private Material material; | |
@Override | |
public void simpleInitApp() { | |
Box b = new Box(1, 1, 1); | |
Geometry interpolatedBox = new Geometry("Box", b); | |
setPauseOnLostFocus(false); | |
flyCam.setDragToRotate(true); | |
geom = new Geometry("", b); | |
geom.setCullHint(Spatial.CullHint.Never); | |
geom.updateModelBound(); | |
geom.updateGeometricState(); | |
geom.move(0, 0, 1); | |
geom.addControl(new AbstractControl() { | |
@Override | |
protected void controlUpdate(float tpf) { | |
spatial.rotate(0, 2 * tpf, 0); | |
} | |
@Override | |
protected void controlRender(RenderManager rm, ViewPort vp) { | |
} | |
}); | |
} | |
private Geometry geom; | |
private float acc = 0; | |
@Override | |
public void simpleUpdate(float tpf) { | |
acc += tpf; | |
if (acc > 1) { | |
acc -= 1; | |
recreate = true; | |
} | |
geom.updateLogicalState(tpf); | |
} | |
@Override | |
public void simpleRender(RenderManager rm) { | |
geom.updateGeometricState(); | |
if (recreate) { | |
((DesktopAssetManager) assetManager).clearCache(); | |
material = new Material(assetManager, "MatDefs/Unshaded.j3md"); | |
material.setColor("Color", ColorRGBA.Red); | |
geom.setMaterial(material); | |
recreate = false; | |
} | |
rm.setCamera(cam, false); | |
geom.updateGeometricState(); | |
try { | |
rm.renderGeometry(geom); | |
} catch (Exception ex) { | |
recreate = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment