Starter Tutorial Problem. Can not change color

Hello. I have been programming java applications for a while, and I thought it was time to move forward towards making 3D programs and games. So I downloaded jME and installed it following the tutorial for installing jME on Netbeans. After a lot of effort I succeded, and now it runs smoothly. So I started reading a starting tutorial about jME. The first chapter worked fine, but in the second ("Hello_Node") i encountered a problem. I couldn't change the color of objects in the room. The tutorial said that the code would be:


b.setSolidColor(ColorRGBA.blue);



Now I wonder why everything I try to draw on the screen appear in a boring gray color.

Here is the link to the tutorial I am following at the moment:

http://www.jmonkeyengine.com/wiki/doku.php?id=starter:hello_node

Here is my full code:


import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
public class MainClass extends SimpleGame
{
    public static void main(String[] args)
    {
        MainClass app=new MainClass();
        app.start();
    }
    protected void simpleInitGame()
    {
        Box b=new Box("My Little Box",new Vector3f(0,0,0),new Vector3f(1,1,1));
        b.setModelBound(new BoundingSphere());
        b.updateModelBound();
        b.setLocalTranslation(new Vector3f(0,2,0));
        b.setSolidColor(ColorRGBA.red);
        Sphere s=new Sphere("My Little Sphere",50,50,1f);
        s.setModelBound(new BoundingBox());
        s.updateModelBound();
        s.setRandomColors();
        Node n=new Node("My Little Node");
        n.attachChild(b);
        n.attachChild(s);
        n.setLocalScale(5);
        rootNode.attachChild(n);
    }
}



You missed this out:


rootNode.setLightCombineMode(LightState.OFF);



An explanation is provided at the bottom of the  wiki entry you linked. In short, solid colors are for displaying things without lighting.
If you want shaded objects, with lighting in your scene, look in to Textures and Materials. You can use both of these to color your object.

Edit: PS welcome to the wonderful world of JME!

I did use it at first, but then when I tried to compile the application Netbeans told me:



init:
deps-jar:
Compiling 1 source file to C:UsersduncanDocumentsprojectjMonkeyjMonkey_Tutorial_1_HelloNodebuildclasses
C:UsersduncanDocumentsprojectjMonkeyjMonkey_Tutorial_1_HelloNodesrcMainClass.java:14: cannot find symbol
symbol  : variable ALWAYS_SHOW_PROPS_DIALOG
location: class com.jme.app.SimpleGame
        app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
C:UsersduncanDocumentsprojectjMonkeyjMonkey_Tutorial_1_HelloNodesrcMainClass.java:32: cannot find symbol
symbol  : variable LightState
location: class MainClass
        rootNode.setLightCombineMode(LightState.OFF);
2 errors
BUILD FAILED (total time: 2 seconds)


that most propably is because you use jme 1.0 code and compile for jme 2.0.



rootNode.setLightCombineMode(LightCombineMode.Off);



Search the forum for further changes from 1.0 to 2.0

http://www.jmonkeyengine.com/wiki/doku.php?id=jme_to_jme2_changes  :slight_smile:

Ok, I read the paper with the changes, and replaced parts of the code, but the same line is still not working.


init:
deps-jar:
Compiling 1 source file to C:UsersduncanDocumentsprojectjMonkeyjMonkey_Tutorial_1_HelloNodebuildclasses
C:UsersduncanDocumentsprojectjMonkeyjMonkey_Tutorial_1_HelloNodesrcMainClass.java:32: cannot find symbol
symbol  : variable LightCombineMode
location: class MainClass
        rootNode.setLightCombineMode(LightCombineMode.Off);                     //Does not work correctly.
1 error
BUILD FAILED (total time: 1 second)





There is also a problem in a later tutorial called "HelloTriMesh". I do not think netbeans can find the "reconstruct" symbol.

Here's my code:


import com.jme.app.SimpleGame;
import com.jme.scene.TriMesh;
import com.jme.math.Vector3f;
import com.jme.math.Vector2f;
import com.jme.renderer.ColorRGBA;
import com.jme.bounding.BoundingBox;
import com.jme.util.geom.BufferUtils;
public class MainClass extends SimpleGame
{
    public static void main(String[] args)
    {
        MainClass app = new MainClass();
        //app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);          //Does not work correctly. Ignore.
        app.start();
    }
    protected void simpleInitGame()
    {
        // TriMesh is what most of what is drawn in jME actually is
        TriMesh m=new TriMesh("My Little Mesh");
        // Vertex positions for the mesh
        Vector3f[] vertexes=
        {
            new Vector3f(0,0,0),
            new Vector3f(1,0,0),
            new Vector3f(0,1,0),
            new Vector3f(1,1,0)
        };
        // Normal directions for each vertex position
        Vector3f[] normals=
        {
            new Vector3f(0,0,1),
            new Vector3f(0,0,1),
            new Vector3f(0,0,1),
            new Vector3f(0,0,1)
        };
        // Color for each vertex position
        ColorRGBA[] colors=
        {
            new ColorRGBA(1,0,0,1),
            new ColorRGBA(1,0,0,1),
            new ColorRGBA(0,1,0,1),
            new ColorRGBA(0,1,0,1)
        };
        // Texture Coordinates for each position
        Vector2f[] texCoords=
        {
            new Vector2f(0,0),
            new Vector2f(1,0),
            new Vector2f(0,1),
            new Vector2f(1,1)
        };
        // The indexes of Vertex/Normal/Color/TexCoord sets. Every 3
        // makes a triangle.
        int[] indexes=
        {
            0,1,2,1,2,3
        };
        // Feed the information to the TriMesh
        m.reconstruct(                                                          //Can not find symbol.
                BufferUtils.createFloatBuffer(vertexes),
                BufferUtils.createFloatBuffer(normals),
                BufferUtils.createFloatBuffer(colors),
                BufferUtils.createFloatBuffer(texCoords),
                BufferUtils.createIntBuffer(indexes));
        // Create a bounds
        m.setModelBound(new BoundingBox());
        m.updateModelBound();
        // Attach the mesh to my scene graph
        rootNode.attachChild(m);
        // Let us see the per vertex colors
        lightState.setEnabled(false);
    }
}




And here is the error I get:


init:
deps-jar:
Compiling 1 source file to C:UsersduncanDocumentsprojectjMonkeyjMonkey_Tutorial_2_HelloTrimeshbuildclasses
C:UsersduncanDocumentsprojectjMonkeyjMonkey_Tutorial_2_HelloTrimeshsrcMainClass.java:59: cannot find symbol
symbol  : method reconstruct(java.nio.FloatBuffer,java.nio.FloatBuffer,java.nio.FloatBuffer,java.nio.FloatBuffer,java.nio.IntBuffer)
location: class com.jme.scene.TriMesh
        m.reconstruct(                                                          //Can not find symbol.
1 error
BUILD FAILED (total time: 1 second)



hmm, this seems to be an issue concerning Netbeans, and since I'm not a masochist and use Eclipse ( }:-@), someone else will have to take a look at it  :wink:

I think this is a 1.0/2.0 issue, I would recommend you use jME 2.0…



either get it from http://code.google.com/p/jmonkeyengine/downloads/list

or by SVN: http://code.google.com/p/jmonkeyengine/source/checkout





to test which version you have now try these commands



1.0

app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);



2.0

app.setConfigShowMode(ConfigShowMode.AlwaysShow);



Whichever one compiles is the version you are running...

I use jME 2.0. But I am pretty sure the guide I am following use 1.0. Should I use that instead?

Nope, use 2.0 (the guides need to be changed…)