All my models are white

I'm trying to figure out how to use FixedLogicrateGame in jME 2.0, but all the models I load in the scene are plain monocolor-white. There isn't even any shading. My model importer code worked fine for SimpleGame (it even loads the texture). I thought maybe I just had to add a light:

      //Create a Basic Directional Light
      DirectionalLight dl = new DirectionalLight();
      dl.setDirection(Vector3f.UNIT_XYZ);
      dl.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
      dl.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
      dl.setEnabled(true);

      LightState ls = display.getRenderer().createLightState();
      ls.setEnabled(true);
      ls.attach(dl);
      
      sceneRoot.setRenderState(ls);
      sceneRoot.updateRenderState();

But it's still not working. Is there something wrong with my lighting code, or am I missing something else? How are you supposed to add lights?

You need to apply a MaterialState to you models for light to have an effect.

That's not true… that usually results from a missing updateRenderState on the models…

I think often its white when a LightState is missing at all :), but you have that one obviously.

So there are a few pitfalls to double check.

That's not very helpful guys. Here's my attempt to reproduce the problem as simply as possible:

import java.util.prefs.BackingStoreException;

import java.util.prefs.Preferences;



import com.jme.app.FixedLogicrateGame;

import com.jme.input.KeyBindingManager;

import com.jme.input.KeyInput;

import com.jme.light.DirectionalLight;

import com.jme.math.Vector3f;

import com.jme.renderer.Camera;

import com.jme.renderer.ColorRGBA;

import com.jme.scene.CameraNode;

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.scene.state.ZBufferState;

import com.jme.system.DisplaySystem;

import com.jme.system.GameSettings;

import com.jme.system.JmeException;

import com.jme.system.PreferencesGameSettings;



public class HelloAgainWorld extends FixedLogicrateGame{



   public static void main(String[] args) {

      HelloAgainWorld app = new HelloAgainWorld();

      app.setConfigShowMode(HelloAgainWorld.ConfigShowMode.AlwaysShow);

      app.start();

   }



   private CameraNode camNode;

   private Camera cam;

   private Node rootNode;

   private int width, height, depth, freq;

   private boolean fullscreen;

   private ZBufferState buf;

   private MaterialState mat;



   private void buildOverheadCamera()   {

      camNode = new CameraNode("Camera Node", cam);

      camNode.setCamera(cam);

      camNode.setLocalTranslation(new Vector3f(0, 0, -100));

   }

   

   private void initZBuf() {

      buf = display.getRenderer().createZBufferState();

      buf.setEnabled(true);

      buf.setFunction(ZBufferState.TestFunction.Always);

      rootNode.setRenderState(buf);

   }

   

   private void initMat() {

      // add a material state?

      mat = display.getRenderer().createMaterialState();

      mat.setEnabled(true);

      rootNode.setRenderState(mat);

   }

   

   private void initLight() {

      //Create a Basic Directional Light?

      DirectionalLight dl = new DirectionalLight();

      dl.setDirection(Vector3f.UNIT_XYZ);

      dl.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));

      dl.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));

      dl.setEnabled(true);

      // add a light state?

      LightState ls = display.getRenderer().createLightState();

      ls.setEnabled(true);

      ls.attach(dl);

      rootNode.setRenderState(ls);

   }

   

   private void initialize() {

      rootNode = new Node();

      buildOverheadCamera();

      setLogicTicksPerSecond(20);

      // private helper methods

      initZBuf();

      initMat();

      initLight();

      // apply the render states

      rootNode.updateRenderState();

   }

   

   @Override

   protected void cleanup() {

      // so far, not needed?

   }



   @Override

   protected void initGame() {

      initialize();

      // generate a box and set name, initial position, and scale

      Box box1 = new Box("box1", new Vector3f(0,1,0),1,2,3);

      // attach it to the scene graph

      rootNode.attachChild(box1);

      // rotate a little

      box1.getLocalRotation().fromAngleAxis(1, Vector3f.UNIT_XYZ);

   }



   @Override

   protected void initSystem() {   

      //store the properties information

      width = this.settings.getWidth();

      height = this.settings.getHeight();

      depth = this.settings.getDepth();

      freq = this.settings.getFrequency();

      fullscreen = this.settings.isFullscreen();         



      //cam init

      try {

         display = DisplaySystem.getDisplaySystem(

               this.getNewSettings().getRenderer());         

         display.createWindow(width, height, depth, freq, fullscreen);



         cam = display.getRenderer().createCamera(width, height);

      } catch (JmeException e) {

         e.printStackTrace();

         System.exit(1);

      }



      //set the background to black

      display.getRenderer().setBackgroundColor(ColorRGBA.black);



      display.getRenderer().setCamera(cam);

      cam.setFrustumPerspective(45.0f,

            (float)display.getWidth()/(float)display.getHeight(),

            1, 1000);



      cam.setFrame(

            new Vector3f(0,12,0),

            Vector3f.UNIT_X,

            Vector3f.UNIT_Y,

            Vector3f.UNIT_Z);

      cam.update();



      KeyBindingManager.getKeyBindingManager().set("exit",

            KeyInput.KEY_ESCAPE);

      

   }



   @Override

   protected void reinit() {

      display.recreateWindow(width, height, depth, freq, fullscreen);

   }



   @Override

   protected void render(float arg0) {

      // Clear the screen

      display.getRenderer().clearBuffers();

      // Draw the scene

      display.getRenderer().draw(rootNode);

   }



   @Override

   protected void update(float interpolation) {

      //check for keyboard input

      if (KeyBindingManager.getKeyBindingManager(

            ).isValidCommand("exit")) {

         finished = true;

      }



      rootNode.updateGeometricState(interpolation, true);

      //update Overhead Camera

      camNode.updateWorldData(interpolation);      

   }



   @Override

   protected GameSettings getNewSettings() {

      boolean newNode = true;

      Preferences userPrefsRoot = Preferences.userRoot();

      try {

         newNode = !userPrefsRoot.nodeExists("");

      } catch (BackingStoreException bse) {

         bse.printStackTrace();

      }



      return new PreferencesGameSettings(userPrefsRoot.node(""), newNode,

         "game-defaults.properties");

   }



}

It extends FixedLogicrateGame and renders a box. Still no shading. I really don't understand how renderstates are supposed to work, so I don't know if I'm doing it wrong.

You added the Box to the rootNode without updating the RenderState afterwards.

Add a rootNode.updateRenderState(); at the end of initGame()

Trussell.setScore(Trussell.getScore() + 1);

lol, thanks it's working now.