GameState problem

Hi,

I’m learning about SimpleGame and I tried to create a GameState using scene from “JME 2.X - Material Tutorial 3 - Object transparency”.



The problem is that the same code from this tutorial is rendered differently when used in a SimpleGame vs in a GameState (to make it more readable I render only 2 teapots):



SimpleGame





GameState





Here’s the code for the GameState:

public class TransparentScene extends GameState
{

   Node rootNode; //A root node for our GameState, just like SimpleGame has.

   LightState lightState; //A light to shine on our box.

   DirectionalLight myLight; //The light that plugs into the LightState

   /**
    * A node to rotate two teapots at a time.
    */
   private Node teapots;

   /**
    * Initialization code of the tutorial
    */
   protected TransparentScene()
   {
      rootNode = new Node("t3h n0d3zk");

      // hide the mouse cursor
      MouseInput.get().setCursorVisible(false);

      lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState(); //Set up a lightState

      // our light
      final PointLight light = new PointLight();
      light.setDiffuse(ColorRGBA.white);
      light.setSpecular(ColorRGBA.white);
      light.setLocation(new Vector3f(100.0f, 100.0f, 100.0f));
      light.setEnabled(true);

      // attach the light to a lightState
      lightState.attach(light);

      teapots = new Node("teapots");

      // first teapot
      final Teapot teapot = new Teapot("teapot");
      teapot.setLocalTranslation(0.0f, -2.0f, 6.0f);
      teapots.attachChild(teapot);

      // second teapot
      final Teapot farTeapot = new Teapot("farTeapot");
      farTeapot.setLocalTranslation(0.0f, -2.0f, -6.0f);
      teapots.attachChild(farTeapot);

      // attach it to the root node
      rootNode.attachChild(teapots);

      rootNode.updateRenderState();
   }

   @Override
   public void render(float tpf)
   {
      DisplaySystem.getDisplaySystem().getRenderer().clearBuffers(); //Standard render cycle, clear buffers then render
      rootNode.draw(DisplaySystem.getDisplaySystem().getRenderer());
   }

   @Override
   public void cleanup()
   {
      //Do nothing
   }

   @Override
   public void update(float tpf)
   {
      rootNode.updateGeometricState(tpf, true); //Stanard update cycle for geometry and rendering
      rootNode.updateRenderState();
   }
}



What to do to get same results using GameState?

Wow, cool, if you can figure out how you got the matrix teapots I'd like to know :D  It's probably buffer overload somewhere, but still it's gnarly.

almost right, but you only created the lightstate, its never used by anything.



rootNode.setRenderState(lightState);



And updateRenderState is not needed in the update method.

I added

rootNode.setRenderState(lightState);



But still something must be wrong:
Without rootNode.updateRenderState scene looks like this:


And with rootNode.updateRenderState enabled it looks like only the inside surfaces are rendered:


Thank you for your patience helping out a noob :)

The matrix teapots are cool :), they result of the missing updateRenderState() (i cant reproduce that problem tho).

rootNode.updateRenderState() needs to be the last call in your gamestates constructor. (or anytime you add a object to the scene on the fly)



The 2nd problem is because of a missing ZBufferState.

You can take a look at BasicGameState to see how to set up the ZBufferState.

Thanks Core-Dump!



Just in case somebody needs it:


ZBufferState buf = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
buf.setEnabled(true);
buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
rootNode.setRenderState(buf);

Serpardum said:

Wow, cool, if you can figure out how you got the matrix teapots I'd like to know :D  It's probably buffer overload somewhere, but still it's gnarly.


its just inheriting some random texture (from defaultfont.tga in this case)