Missing light?

Hello guys, I'm trying to make my first app using BaseGame. But my nodes gets all white. So I searched and now I know that it is caused by a Missing Light problem. So I tried to add my own light, this is my initGame:


protected void initGame() {
        // Root Node
        scene = new Node("Scene graph root");

        // Lights
        SpotLight light = new SpotLight();
        light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
        light.setAmbient(new ColorRGBA(0.75f, 0.75f, 0.75f, 1.0f));
        light.setDirection(new Vector3f(0, 0, 0));
        light.setLocation(new Vector3f(0, 10, 0));
        light.setAngle(25);
        light.setEnabled(true);

        LightState ls = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
        ls.attach(light);
        ls.setTwoSidedLighting(true);
        scene.setRenderState(ls);
        scene.updateRenderState();

        Box b = new Box("Floor", Vector3f.ZERO, new Vector3f(10f, 10f, 10f));

        TextureState ts = display.getRenderer().createTextureState();
        ts.setEnabled(true);
        ts.setTexture(TextureManager.loadTexture(
                    Main.class.getClassLoader().getResource("jme/data/texture/wall.jpg"),
                    Texture.MinificationFilter.BilinearNearestMipMap,
                    Texture.MagnificationFilter.Bilinear));
 
        b.setRenderState(ts);

        b.setModelBound(new BoundingBox());
        b.updateModelBound();

        scene.attachChild(b);
        scene.updateGeometricState(0.0f, true);

        cam.update();
    }




I really don't know why this is happening. I will be happy if someone could help me.

You should just call scene.updateRenderstate() once after all things have been added, especially those with renderstates (box). Otherwise the renderstates does not get applied to the whole tree. So just put that line right after scene.attachChild(b);



Cheers,

Normen

Okay, now I see all black :confused:


protected void initGame() {
        // Root Node
        scene = new Node("Scene graph root");

        // Lights
        SpotLight light = new SpotLight();
        light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
        light.setAmbient(new ColorRGBA(0.75f, 0.75f, 0.75f, 1.0f));
        light.setDirection(new Vector3f(0, 0, 0));
        light.setLocation(new Vector3f(0, 10, 0));
        light.setAngle(25);
        light.setEnabled(true);

        LightState ls = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
        ls.attach(light);
        ls.setTwoSidedLighting(true);
        scene.setRenderState(ls);
       
        Box b = new Box("Floor", Vector3f.ZERO, new Vector3f(10f, 10f, 10f));

        TextureState ts = display.getRenderer().createTextureState();
        ts.setEnabled(true);
        ts.setTexture(TextureManager.loadTexture(
                    Main.class.getClassLoader().getResource("jme/data/texture/wall.jpg"),
                    Texture.MinificationFilter.BilinearNearestMipMap,
                    Texture.MagnificationFilter.Bilinear));
 
        b.setRenderState(ts);

        b.setModelBound(new BoundingBox());
        b.updateModelBound();

        scene.attachChild(b);
        scene.updateRenderState();

        scene.updateGeometricState(0.0f, true);

        cam.update();
    }

That is a good sign! :slight_smile: Its a spotlight and you set the direction to 0,0,0 which is no direction. So you cant know where its aimed at right now…

Sorry, my problem, I used the wrong light thing. What's the Light class that SimpleGame uses?

The problem is not the light but the direction, anyway simplegame uses directionallight i think.

My cube spawns at 0, 0, 0 and this is my light config:


// Lights
        DirectionalLight light = new DirectionalLight();
        light.setDirection(new Vector3f(0, 10, 0));
        light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
        light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
        light.setEnabled(true);

        LightState ls = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
        ls.attach(light);
        ls.setTwoSidedLighting(true);
        scene.setRenderState(ls);



This is what I got:



:/

It looks like you are missing a ZBufferstate, thats why you cube gets rendered funny and you see the insides of it.

Take a look at BaseSimpleGame to see how things are set up.

http://code.google.com/p/jmonkeyengine/source/browse/trunk/src/com/jme/app/BaseSimpleGame.java