Ok, got my terrain to display… I ended up subclassing SimplePassGame and using the terrain from TestIsland. It looks beautiful.
Then I added a skybox. I have it following the camera around… but it displays in front of everything.
I know enough to know that a ZBufferState should fix things…
I've tried different combinations (the ZBufferState on the skybox, on the terrain, on the rootnode) and the best I could do was to make the skybox render behind the black background (is that even possible? It just disappeared).
So, I'm asking my stupid question. I hope that the answer isn't as simple as I suspect it will be
And additionally, does the order in which you add things matter much? Can I add everything to the root and then modify the properties without worrying about the order?
public class MyGame extends SimplePassGame {
MyGameState gameState;
Skybox skybox;
public static void main(String[] args) {
MyGame app = new MyGame();
app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
app.start();
}
protected void simpleInitGame() {
display.setTitle("Test Terrainsplatting");
GameStateManager.create();
// create a game state
gameState = new MyGameState();
Node scene = gameState.getRootNode();
/** Create a ZBuffer to display pixels closest to the camera above farther ones. */
ZBufferState buf = display.getRenderer().createZBufferState();
buf.setEnabled(true);
buf.setFunction(ZBufferState.CF_LEQUAL);
scene.setRenderState(buf);
// Set up the lighting and camera
setupEnvironment();
TerrainManager tm = new TerrainManager();
// attach terrain
Spatial terrain = tm.createTerrain();
scene.attachChild(terrain);
// attach skybox
skybox = tm.createSkybox();
skybox.setLocalTranslation(cam.getLocation());
scene.attachChild(skybox);
RenderPass rootPass = new RenderPass();
rootPass.add(scene);
pManager.add(rootPass);
// update the scene graph for rendering
scene.updateGeometricState(0.0f, true);
scene.updateRenderState();
}
private void setupEnvironment() {
cam.setFrustumPerspective(50.0f, (float) display.getWidth()
/ (float) display.getHeight(), 1f, 1000f);
cam.setLocation( new Vector3f( -270, 180, -270 ) );
cam.lookAt( new Vector3f( 0, 0, 0 ), Vector3f.UNIT_Y );
cam.update();
CullState cs = display.getRenderer().createCullState();
cs.setCullMode(CullState.CS_BACK);
gameState.getRootNode().setRenderState(cs);
gameState.getRootNode().setLightCombineMode(LightState.OFF);
}
protected void simpleUpdate(){
// Update the GameStates
GameStateManager.getInstance().update(-1.0f);
skybox.setLocalTranslation(cam.getLocation());
skybox.updateGeometricState(0.0f, true);
}
protected void simpleRender(){
GameStateManager.getInstance().render(-1.0f);
}
public Skybox createSkybox(){
Skybox skybox = new Skybox("skybox", 10, 10, 10);
String dir = "data/texture/";
Texture north = TextureManager.loadTexture(
this.getClass().getClassLoader().getResource(
dir + "north.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture south = TextureManager.loadTexture(
this.getClass().getClassLoader().getResource(
dir + "south.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture east = TextureManager.loadTexture(
this.getClass().getClassLoader().getResource(
dir + "east.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture west = TextureManager.loadTexture(
this.getClass().getClassLoader().getResource(
dir + "west.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture up = TextureManager.loadTexture(
this.getClass().getClassLoader().getResource(
dir + "top.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
Texture down = TextureManager.loadTexture(
this.getClass().getClassLoader().getResource(
dir + "bottom.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR);
skybox.setTexture(Skybox.NORTH, north);
skybox.setTexture(Skybox.WEST, west);
skybox.setTexture(Skybox.SOUTH, south);
skybox.setTexture(Skybox.EAST, east);
skybox.setTexture(Skybox.UP, up);
skybox.setTexture(Skybox.DOWN, down);
skybox.preloadTextures();
return skybox;
}