Activate light, white blobs with Box [solved]

Hey! Trying to activate light but keep getting those white blobs (that is, the shape of the spatial is just compact white, like there's no LightState activated). I use BaseGame. I've ripped code from flagrush into my initGame():



       /** Set up a basic, default light. /

       DirectionalLight light = new DirectionalLight();

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

       light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, .5f));

       light.setDirection(new Vector3f(1, -1, 0));

       light.setShadowCaster(true);

       light.setEnabled(true);



       /
* Attach the light to a lightState and the lightState to rootNode. */

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

       lightState.setEnabled(true);

       lightState.setGlobalAmbient(new ColorRGBA(.2f, .2f, .2f, 1f));

       lightState.attach(light);

       scene.setRenderState(lightState);

       scene.updateRenderState();



I add a Box to the root node:



       Vector3f v = new Vector3f(x, y, 0);

       Box b = new Box(id, v, 5, 5, 5);

       b.setLocalTranslation(new Vector3f(0, 0, -40));

       b.setModelBound(new BoundingBox());

       b.updateModelBound();

       scene.attachChild(b);



Adding the following code does not change anything:



                 MaterialState ms = display.getRenderer().createMaterialState();

                 ms.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 0.5f));

                 ms.setEmissive(new ColorRGBA(0, 0.75f, 0, 0.5f));

                 ms.setDiffuse(new ColorRGBA(0, 1, 0, 0.5f));

                 ms.setSpecular(new ColorRGBA(1, 0, 0, 0.5f));

                 ms.setShininess(100);

                 b.setRenderState(ms);

                 b.updateRenderState();



Anyone know what's missing?

Define: those white blobs

Sorry :slight_smile:



If a sphere should look like this:



http://www.jmonkeyengine.com/jme/wiki-data/userref/sphere.png



it doesn't, it's just compact white.

I see, look here OpenGL Light - Creating Light Sources in OpenGL, Light Types (ambient, diffuse, material color and specular highlight). just ignore the opengl lowlevel stuff, since jme hides the lowest calls fro you, still the way it works is identical

make sure to add a rootNode.updateRenderstate() at the end of the scene initialisation.



In your code you do s.updateRenderState() but its not clear what s might be.

Right, so updateRenderState() has to be called every time you add a new spatial to the scene graph. It's working as it should now. Thank you very much for your help!