I am trying to setup my first jME application for some hours now. It wont render, as it should. I read all the related tutorials and wiki pages over and over again, and I cannot find the problem in my code.
Here is, how it renders the scene:
It seems, it is rendering the inside faces of the boxes only.
Here is my straight forward code that is not working:
package de.coskunscastle.jme;
import com.jme.app.AbstractGame;
import com.jme.app.BaseGame;
import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.light.PointLight;
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.Box;
import com.jme.scene.state.LightState;
import com.jme.scene.state.MaterialState;
import com.jme.system.DisplaySystem;
import com.jme.util.Timer;
public class First3DGame extends BaseGame
{
private Camera cam;
private Timer timer;
private Node scene;
@Override
protected void initSystem()
{
final int width = this.properties.getWidth();
final int height = this.properties.getHeight();
final int depth = this.properties.getDepth();
final int freq = this.properties.getFreq();
final boolean fullscreen = this.properties.getFullscreen();
final String renderAPI = this.properties.getRenderer();
this.display = DisplaySystem.getDisplaySystem(renderAPI);
this.display.createWindow(width, height, depth, freq, fullscreen);
this.display.getRenderer().setBackgroundColor(ColorRGBA.black);
final Vector3f camLoc = new Vector3f(7.0f, 12.0f, 25.0f);
final Vector3f camLeft = new Vector3f(-1.0f, 0.0f, 0.0f);
final Vector3f camUp = new Vector3f(0.0f, 1.0f, 0.0f);
final Vector3f camDir = new Vector3f(0.0f, 0f, -1.0f);
this.cam = this.display.getRenderer().createCamera(width, height);
this.cam.setFrame(camLoc, camLeft, camUp, camDir);
this.cam.setFrustumPerspective(45.0f, (float) width / (float) height,
1, 1000);
this.cam.update();
this.display.getRenderer().setCamera(this.cam);
this.timer = Timer.getTimer();
this.scene = new Node("Scene Graph Root");
KeyBindingManager.getKeyBindingManager().set("exit",
KeyInput.KEY_ESCAPE);
}
@Override
protected void initGame()
{
// *********** Cam lookat update **************
this.cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
this.cam.update();
// *********** Light **************
final LightState lightState = this.display.getRenderer()
.createLightState();
final PointLight light = new PointLight();
light.setLocation(new Vector3f(5, 2, 0));
light.setDiffuse(ColorRGBA.red);
light.setEnabled(true);
lightState.attach(light);
lightState.setEnabled(true);
this.scene.setRenderState(lightState);
// *********** ground floor **************
final Box groundVisual = new Box("floor", Vector3f.ZERO, 15, 0.5f, 15);
this.scene.attachChild(groundVisual);
groundVisual.setModelBound(new BoundingBox());
groundVisual.updateModelBound();
final MaterialState groundMaterial = this.display.getRenderer()
.createMaterialState();
groundMaterial.setAmbient(ColorRGBA.orange);
groundMaterial.setEmissive(ColorRGBA.brown);
groundMaterial.setDiffuse(ColorRGBA.brown);
groundMaterial.setSpecular(ColorRGBA.orange);
groundMaterial.setShininess(10);
groundVisual.setRenderState(groundMaterial);
// *********** box in air **************
final Box boxVisual = new Box("ball", new Vector3f(), 2.5f, 2.5f, 2.5f);
this.scene.attachChild(boxVisual);
boxVisual.getLocalTranslation().set(0, 5, 0);
boxVisual.setModelBound(new BoundingSphere());
boxVisual.updateModelBound();
final MaterialState boxMaterial = this.display.getRenderer()
.createMaterialState();
groundMaterial.setAmbient(ColorRGBA.orange);
groundMaterial.setEmissive(ColorRGBA.red);
groundMaterial.setDiffuse(ColorRGBA.red);
groundMaterial.setSpecular(ColorRGBA.orange);
groundMaterial.setShininess(10);
boxMaterial.setEnabled(true);
boxVisual.setRenderState(boxMaterial);
// *********** update geometric and render state **************
this.scene.updateGeometricState(0.0f, true);
this.scene.updateRenderState();
}
@Override
protected void reinit()
{
final int width = this.properties.getWidth();
final int height = this.properties.getHeight();
final int depth = this.properties.getDepth();
final int freq = this.properties.getFreq();
final boolean fullscreen = this.properties.getFullscreen();
this.display.recreateWindow(width, height, depth, freq, fullscreen);
}
@Override
protected void cleanup()
{
}
@Override
protected void render(final float arg0)
{
this.display.getRenderer().clearBuffers();
this.display.getRenderer().draw(this.scene);
}
@Override
protected void update(float interpolation)
{
this.timer.update();
interpolation = this.timer.getTimePerFrame();
this.scene.updateGeometricState(interpolation, true);
if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
this.finished = true;
}
}
public static void main(final String[] args)
{
final First3DGame game = new First3DGame();
game.setDialogBehaviour(AbstractGame.ALWAYS_SHOW_PROPS_DIALOG);
game.start();
}
}
What is the problem?