Camera in StandardGame

I don't know how to create a camera for StandardGame.

I copied the code of the camera from DebugGameState, but if I use this method, I get a serious error




26.09.2008 09:47:52 com.jme.input.joystick.DummyJoystickInput <init>
INFO: Joystick support is disabled
26.09.2008 09:47:52 com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
26.09.2008 09:47:53 com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W:  800H: 600
26.09.2008 09:47:53 com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
26.09.2008 09:47:54 com.jmex.audio.openal.OpenALSystem setupSourcePool
INFO: max source channels: 64
26.09.2008 09:47:54 com.jmex.game.state.GameStateManager create
INFO: Created GameStateManager
26.09.2008 09:47:54 com.jme.util.lwjgl.LWJGLTimer <init>
INFO: Timer resolution: 1000 ticks per second
26.09.2008 09:47:54 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:47:54 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:47:54 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:47:54 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:08 com.jme.scene.Node attachChild
INFO: Child (default##0) attached to this node (default)
26.09.2008 09:48:08 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:08 com.jme.scene.Node attachChild
INFO: Child (default) attached to this node (TDS Scene)
26.09.2008 09:48:08 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:08 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:08 com.jme.util.TextureManager loadImage
WARNUNG: loadImage(String fileExt, InputStream stream, boolean flipped): no imageData found.  defaultTexture used.
26.09.2008 09:48:08 com.jme.scene.Node attachChild
INFO: Child (TDS Scene) attached to this node (null)
26.09.2008 09:48:09 com.jme.scene.Node attachChild
INFO: Child (null) attached to this node (null)
26.09.2008 09:48:09 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:09 com.jme.scene.Node attachChild
INFO: Child (particles) attached to this node (null)
26.09.2008 09:48:09 com.jme.scene.Node attachChild
INFO: Child (null) attached to this node (null)
26.09.2008 09:48:09 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:09 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:14 com.jme.scene.Node attachChild
INFO: Child (default##0) attached to this node (default)
26.09.2008 09:48:14 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:14 com.jme.scene.Node attachChild
INFO: Child (default) attached to this node (TDS Scene)
26.09.2008 09:48:14 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:14 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:15 com.jme.util.TextureManager loadImage
WARNUNG: loadImage(String fileExt, InputStream stream, boolean flipped): no imageData found.  defaultTexture used.
26.09.2008 09:48:15 com.jme.scene.Node attachChild
INFO: Child (TDS Scene) attached to this node (null)
26.09.2008 09:48:15 com.jme.scene.Node attachChild
INFO: Child (null) attached to this node (null)
26.09.2008 09:48:15 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:15 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:15 com.jme.scene.Node attachChild
INFO: Child (default##0) attached to this node (default)
26.09.2008 09:48:15 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:15 com.jme.scene.Node attachChild
INFO: Child (default) attached to this node (TDS Scene)
26.09.2008 09:48:15 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:15 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:15 com.jme.util.TextureManager loadImage
WARNUNG: loadImage(String fileExt, InputStream stream, boolean flipped): no imageData found.  defaultTexture used.
26.09.2008 09:48:15 com.jme.scene.Node attachChild
INFO: Child (TDS Scene) attached to this node (null)
26.09.2008 09:48:15 com.jme.scene.Node attachChild
INFO: Child (null) attached to this node (null)
26.09.2008 09:48:15 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:15 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:15 com.jme.scene.Node attachChild
INFO: Child (default##0) attached to this node (default)
26.09.2008 09:48:15 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:15 com.jme.scene.Node attachChild
INFO: Child (default) attached to this node (TDS Scene)
26.09.2008 09:48:16 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:16 com.jme.scene.Node <init>
INFO: Node created.
26.09.2008 09:48:16 com.jme.util.TextureManager loadImage
WARNUNG: loadImage(String fileExt, InputStream stream, boolean flipped): no imageData found.  defaultTexture used.
26.09.2008 09:48:16 com.jme.scene.Node attachChild
INFO: Child (TDS Scene) attached to this node (null)
26.09.2008 09:48:16 com.jme.scene.Node attachChild
INFO: Child (null) attached to this node (null)
26.09.2008 09:48:16 com.jme.scene.Node attachChild
INFO: Child (null) attached to this node (Background: RootNode)
26.09.2008 09:48:16 game.bin.DefaultUncaughtExceptionHandler uncaughtException
SCHWERWIEGEND: Main game loop broken by uncaught exception
org.lwjgl.opengl.OpenGLException: Invalid value (1281)
   at org.lwjgl.opengl.Util.checkGLError(Util.java:50)
   at org.lwjgl.opengl.Display.swapBuffers(Display.java:606)
   at org.lwjgl.opengl.Display.update(Display.java:625)
   at com.jme.renderer.lwjgl.LWJGLRenderer.displayBackBuffer(LWJGLRenderer.java:517)
   at game.bin.GameEngine.run(GameEngine.java:200)
   at java.lang.Thread.run(Unknown Source)



The problem is the camera. I looked for examples, but I haven't found a good one, therefore I looked inside the DebugGameState. What should I do?

public static void main(String[] args) throws Exception{
       
       // Instantiate StandardGame
      game = new GameEngine("Project Zero");
      // Show settings screen
      if (EngineGameSettings.prompt(game.getSettings())) {
         // Start StandardGame, it will block until it has initialized successfully, then return
         game.start();
      
      
         /*Menu
          *
          */
         
         //DebugGameState backgroundscreen = new DebugGameState();
         BasicGameState backgroundscreen = new BasicGameState("Background");
         GameStateManager.getInstance().attachChild(backgroundscreen);
         backgroundscreen.setActive(true);
         
          backgroundscreen.getRootNode().attachChild(new BackgroundMenu());
         backgroundscreen.getRootNode().updateRenderState();
         
         /*Camera
          * X=-6.192075, Y=-3.2746232, Z=29.483051
          */
         
         DisplaySystem display = DisplaySystem.getDisplaySystem();
           Camera cam = display.getRenderer().getCamera();
float aspect = (float) display.getWidth() / display.getHeight();
           cam.setFrustum(-100.0f, 1000.0f, -50.0f * aspect, 50.0f * aspect,
                   -50.0f, 50.0f);
           cam.setParallelProjection(false);
           cam.update();
          }
    }




EDIT:
Seems the problem!--> backgroundscreen.setActive(true);

A couple questions come to mind:

  1. Is there a specific reason you're explicitly creating a camera?  I don't have the code in front of me, but StandardGame creates a camera for you.  I believe game.getCamera() will fetch it for you, and you can then modify it's properties if you want.


  2. I'm curious why you're attaching BackgroundMenu to the backgroundscreen gamestate.  If I understand what you're trying to do, I would create another gamestate ("BackgroundMenuState") and attach the menu in the constructor of that state.  If you set both states active, both will be visible and you should get the desired effect.  Besides that, I believe the problem causing your error is that you're trying to modify the scenegraph in the main thread.  I believe creating the BackgroundMenuState will "fix" this problem, but if you want to do what you've done without creating another state, you'll need to put the calls to attachChild and updateRenderState inside an update call to the GameTaskQueueManager (you should be able to find an example of this) so they will be executed in the OpenGL thread.



    Good luck.

If you're using an extension of any GameState, you already have a camera initialized.



All of my gamestates extend DebugGameState, cause it does most of the work for me.