Hi everyone,
this is a post for a problem I am having the last few weeks! Maybe with this topic someone else has an idea:
I extended the TestGameStateSystem and only get a black screen. Someone said something about not rendering it right!
Main:
package prototyp2;
import java.util.logging.Level;
import java.util.logging.Logger;
import prototyp2.MenuState;
import com.jme.app.AbstractGame;
import com.jme.app.BaseGame;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.renderer.Camera;
import com.jme.renderer.pass.BasicPassManager;
import com.jme.scene.Node;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.Timer;
import com.jmex.game.state.GameState;
import com.jmex.game.state.GameStateManager;
public class Main extends BaseGame{
private static final Logger logger = Logger.getLogger(Main.class.getName());
private static AbstractGame instance;
private Timer timer;
private float tpf;
public Camera cam;
private WaterState ingame;
protected BasicPassManager passManager;
public Node rootNode;
protected final void update(float interpolation){
timer.update();
tpf = timer.getTimePerFrame();
//Update the current game state
GameStateManager.getInstance().update(tpf);
}
protected final void render(float tpf){
display.getRenderer().clearBuffers();
GameStateManager.getInstance().render(tpf);
display.getRenderer().draw(rootNode);
}
protected final void initSystem(){
try{
display = DisplaySystem.getDisplaySystem(properties.getRenderer());
display.createWindow(
properties.getWidth(),
properties.getHeight(),
properties.getDepth(),
properties.getFreq(),
properties.getFullscreen());
} catch (JmeException e){
logger.log(Level.SEVERE, "Could not create displaySystem", e);
System.exit(1);
}
timer = Timer.getTimer();
// cam = display.getRenderer().createCamera( display.getWidth(),
// display.getHeight() );
}
protected final void initGame(){
instance = this;
display.setTitle("Pororoca - Surfing Different Prototyp2");
GameStateManager.create();
GameState menu = new MenuState("menu");
menu.setActive(true);
GameStateManager.getInstance().attachChild(menu);
GameState gameover = new GameOverState("gameover");
gameover.setActive(false);
GameStateManager.getInstance().attachChild(gameover);
}
protected void reinit() {
}
protected void cleanup(){
logger.info("Cleaning up resources.");
GameStateManager.getInstance().cleanup();
KeyInput.destroyIfInitalized();
MouseInput.destroyIfInitalized();
}
public static void main(String[] args){
Main app = new Main();
app.setDialogBehaviour(AbstractGame.ALWAYS_SHOW_PROPS_DIALOG);
app.start();
}
public static void exit() {
instance.finish();
}
}
MenuHandler (where the ingame is initialized)
/*
* Copyright (c) 2003-2006 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package prototyp2;
import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.action.InputAction;
import com.jme.input.action.InputActionEvent;
import com.jme.system.DisplaySystem;
import com.jmex.game.state.GameState;
import com.jmex.game.state.GameStateManager;
/**
* The input handler we use to navigate the menu. E.g. has an absolute mouse.
* If the escape key is pressed the application will be ended using the static
* exit method of TestGameStateSystem.
*
* @author Per Thulin
*/
public class MenuHandler extends InputHandler {
private GameState myState;
public MenuHandler( GameState myState ) {
setKeyBindings();
this.myState = myState;
}
private void setKeyBindings() {
KeyBindingManager.getKeyBindingManager().set("exit", KeyInput.KEY_ESCAPE);
addAction( new ExitAction(), "exit", false );
KeyBindingManager.getKeyBindingManager().set("enter", KeyInput.KEY_RETURN);
addAction( new EnterAction(), "enter", false );
KeyBindingManager.getKeyBindingManager().set("gameover", KeyInput.KEY_P);
addAction( new GameOverAction(), "gameover", false);
KeyBindingManager.getKeyBindingManager().set("mainmenu", KeyInput.KEY_M);
addAction( new MainMenuAction(), "mainmenu", false);
}
private static class ExitAction extends InputAction {
public void performAction( InputActionEvent evt ) {
Main.exit();
}
}
private class EnterAction extends InputAction {
public void performAction( InputActionEvent evt ) {
GameState ingame = new WaterState2("Pororocas Ingame");
ingame.setActive(true);
GameStateManager.getInstance().attachChild(ingame);
myState.setActive(false); // Deactivate this (the menu) state.
}
}
private class GameOverAction extends InputAction {
public void performAction( InputActionEvent evt ) {
GameState gameover = new GameOverState("GameOver");
gameover.setActive(true);
GameStateManager.getInstance().attachChild(gameover);
myState.setActive(false); // Deactivate this (the menu) state.
}
}
private class MainMenuAction extends InputAction {
public void performAction( InputActionEvent evt ) {
GameState mainmenu = new MenuState("MainMenu");
mainmenu.setActive(true);
GameStateManager.getInstance().attachChild(mainmenu);
myState.setActive(false); // Deactivate this (the menu) state.
}
}
}
And the file, where the terrain is built
/*
* Copyright (c) 2003-2006 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package prototyp2;
import javax.swing.ImageIcon;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.FirstPersonHandler;
import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector3f;
import com.jme.system.DisplaySystem;
import com.jmex.game.state.CameraGameState;
import com.jmex.game.state.GameStateManager;
import com.jmex.terrain.TerrainBlock;
import com.jmex.terrain.util.ProceduralTextureGenerator;
import com.jmex.terrain.util.RawHeightMap;
/**
* @author Per Thulin
*/
public class WaterState2 extends CameraGameState {
private InputHandler input;
private DisplaySystem display;
private TerrainBlock tb;
public WaterState2(String name) {
super(name);
display = DisplaySystem.getDisplaySystem();
cam = display.getRenderer().createCamera(display.getWidth(), display.getHeight());
cam.setLocation(new Vector3f(0,10,0));
cam.update();
buildTerrain();
initInput();
rootNode.updateGeometricState(0, true);
rootNode.updateRenderState();
}
/**
* Gets called every time the game state manager switches to this game state.
* Sets the window title.
*/
public void onActivate() {
DisplaySystem.getDisplaySystem().
setTitle("Test Game State System - Ingame State");
super.onActivate();
}
/**
* Gets called from super constructor. Sets up the input handler that let
* us walk around using the w,s,a,d keys and mouse.
*/
private void initInput() {
input = new FirstPersonHandler(cam, 10, 1);
// Bind the exit action to the escape key.
KeyBindingManager.getKeyBindingManager().set(
"exit",
KeyInput.KEY_ESCAPE);
// Bind the exit action to the escape key.
KeyBindingManager.getKeyBindingManager().set(
"gameover",
KeyInput.KEY_P);
}
protected void stateUpdate(float tpf) {
input.update(tpf);
if (KeyBindingManager.getKeyBindingManager().
isValidCommand("exit", false)) {
// Here we switch to the menu state which is already loaded
GameStateManager.getInstance().activateChildNamed("menu");
// And remove this state, because we don't want to keep it in memory.
GameStateManager.getInstance().detachChild("ingame");
}
if (KeyBindingManager.getKeyBindingManager().
isValidCommand("gameover", false)) {
// Here we switch to the menu state which is already loaded
GameStateManager.getInstance().activateChildNamed("gameover");
// And remove this state, because we don't want to keep it in memory.
GameStateManager.getInstance().detachChild("ingame");
}
}
protected void stateRender(float tpf){
display.getRenderer().draw(rootNode);
}
private void buildTerrain(){
RawHeightMap heightMap = new RawHeightMap(Main.class.getClassLoader().getResource(
"data/terrain/heights2.raw").getFile(), 129,
RawHeightMap.FORMAT_16BITLE, false);
Vector3f terrainScale = new Vector3f(20, 0.001f, 20);
heightMap.setHeightScale(0.0001f);
// create a terrainblock
tb = new TerrainBlock("Terrain", heightMap.getSize(), terrainScale,
heightMap.getHeightMap(), new Vector3f(0, -9, 0), false);
tb.setModelBound(new BoundingBox());
tb.updateModelBound();
// generate a terrain texture with 2 textures
ProceduralTextureGenerator pt = new ProceduralTextureGenerator(
heightMap);
pt.addTexture(new ImageIcon(Main.class.getClassLoader()
.getResource("data/texture/nicegrass.jpg")), -128, 0, 384);
pt.createTexture(128);
rootNode.attachChild(tb);
}
}
So it should render the terrain. But the screen stays black! It says, that the TerrainBlock is attached to the rootNode correctly.
Any further ideas?