import com.jme.app.*;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.TextureManager;
import com.jme.util.Timer;
public class Syphasias extends BaseGame {
public static void main(String[] args) {
Syphasias app = new Syphasias();
app.setConfigShowMode(ConfigShowMode.AlwaysShow,
Syphasias.class.getResource("FlagRush.png"));
app.start();
}
private int width, height, depth, freq;
private boolean fullscreen;
private Camera cam;
protected Timer timer;
protected void update(float interpolation) {
timer.update();
interpolation = timer.getTimePerFrame();
//if escape was pressed, we exit
if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
finished = true;
}
}
protected void render(float interpolation) {
//Clear the screen
display.getRenderer().clearBuffers();
display.getRenderer().draw(scene);
}
protected void initSystem() {
}
protected void initGame() {
scene = new Node("Scene graph node"); //Create our Sphere
Sphere s = new Sphere("Sphere", 30, 30, 25);
s.setLocalTranslation(new Vector3f(0, 0, -40));
s.setModelBound(new BoundingBox());
s.updateModelBound();
ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
ts.setTexture(TextureManager.loadTexture(Syphasias.class.
getClassLoader().getResource("FlagRush.png"), Texture.MinificationFilter.BilinearNearestMipMap, Texture.MagnificationFilter.Bilinear));
s.setRenderState(ts);
scene.attachChild(s);
//update the scene graph for rendering
scene.updateGeometricState(0.0f, true);
scene.updateRenderState();
//store the properties information
width = this.settings.getWidth();
height = this.settings.getHeight();
depth = this.settings.getDepth();
freq = this.settings.getFrequency();
fullscreen = this.settings.isFullscreen();
try {
display = DisplaySystem.getDisplaySystem(this.getNewSettings().getRenderer());
display.createWindow(width, height, depth, freq, fullscreen);
cam = display.getRenderer().createCamera(width, height);
} catch (JmeException e) {
e.printStackTrace();
System.exit(1);
}
//set the background to black
display.getRenderer().setBackgroundColor(ColorRGBA.black);
//initialize the camera
cam.setFrustumPerspective(45.0f, (float)width / (float)height, 1, 1000);
Vector3f loc = new Vector3f(0.0f, 0.0f, 25.0f);
Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
// Move our camera to a correct place and orientation.
cam.setFrame(loc, left, up, dir);
/** Signal that we've changed our camera's location/frustum. */
cam.update();
/** Get a high resolution timer for FPS updates. */
timer = Timer.getTimer();
display.getRenderer().setCamera(cam);
KeyBindingManager.getKeyBindingManager().set("exit",
KeyInput.KEY_ESCAPE);
}
//the root node of the scene graph
private Node scene;
//TextureState to show the monkey on the sphere.
private TextureState ts;
protected void reinit() {
display.recreateWindow(width, height, depth, freq, fullscreen);
}
protected void cleanup() {
ts.deleteAll();
}
}
That is the code, but I get this error while trying to run it:
Jan 13, 2009 3:56:36 PM com.jme.app.BaseGame start
INFO: Application started.
Jan 13, 2009 3:56:36 PM com.jme.system.PropertiesGameSettings <init>
INFO: PropertiesGameSettings created
Jan 13, 2009 3:56:36 PM com.jme.system.PropertiesGameSettings load
INFO: Read properties
Jan 13, 2009 3:56:45 PM com.jme.system.PropertiesGameSettings save
INFO: Saved properties
Jan 13, 2009 3:56:45 PM com.jme.app.AbstractGame assertDisplayCreated
SEVERE: Display system is null.
Jan 13, 2009 3:56:45 PM class Syphasias start()
SEVERE: Exception in game loop
com.jme.system.JmeException: Window must be created during initialization.
at com.jme.app.AbstractGame.assertDisplayCreated(AbstractGame.java:142)
at com.jme.app.BaseGame.start(BaseGame.java:72)
at Syphasias.main(Syphasias.java:24)
Exception in thread "main" java.lang.NullPointerException
at Syphasias.cleanup(Syphasias.java:119)
at com.jme.app.BaseGame.start(BaseGame.java:102)
at Syphasias.main(Syphasias.java:24)
It's suppose to show the sphere, or at least that is what the tutorial says, after the logo.
:D Fixed. The code is correct, but the properties wasn't.