Adding texture?

I used the tutorial called HelloStates and now I am trying to work through my own example to gain a better understanding. When I run the class, it isn't displaying, so I think something is wrong with the line that specifies the url…


URL circleBearLocation = HelloTextures1.class.getClassLoader().getResource("circlebear1.gif");



... I have that image in the package with my java file that I am trying to run. Is there a certain way that I define the path to the image or should I be placing it somewhere else?

if the URL isnt correct you would get a NullPointerException when loading a Texture from it.



If it just doesnt show and you dont get exceptions you should try calling geometry.updateRenderStates(); after applying the textureState.

So I should put that line of code in right after…


// set the renderState of both box1 and pyramid1 as textureState
        box1.setRenderState(textureState);
        pyramid1.setRenderState(textureState);



... and what import statement do I need for this?

Okay, I just added the following lines after setting the render state of each object…


box1.updateRenderState();
        pyramid1.updateRenderState();



... and I am still seeing nothing when I run the class... hmm?

post the source of the whole class since there could be much that is going wrong.



no lights, nothing rendered, and much more.

Here you go… I appreciate your help by the way!


// imported classes
import com.jme.app.SimpleGame;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Pyramid;
import com.jme.math.Vector3f;
import com.jme.bounding.BoundingBox;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jme.image.Texture;
import com.jme.scene.state.LightState;
import com.jme.scene.Geometry;

import java.net.URL;

public class HelloTextures1 extends SimpleGame
{
    protected void simpleInitGame()
    {
        // create the box and pyramid to be used
        Box box1 = new Box("box1", new Vector3f(0,0,0), new Vector3f(5,5,5));
        Pyramid pyramid1 = new Pyramid("p1", 5f, 5f);

        // put boundingBoxes on box1 and pyramid1
        box1.setModelBound(new BoundingBox());
        box1.updateModelBound();
        pyramid1.setModelBound(new BoundingBox());
        pyramid1.updateModelBound();

        // translate pyramid1 away from box1 along x axis
        pyramid1.setLocalTranslation(new Vector3f(10,0,0));

        // attach box1 and pyramid1 to rootNode
        rootNode.attachChild(box1);
        rootNode.attachChild(pyramid1);

        // create a location which points to the picture I want to use
        URL circleBearLocation = HelloTextures1.class.getClassLoader().getResource("circlebear1.gif");

        // create a texture state (based on LWJGL)
        TextureState textureState = display.getRenderer().createTextureState();

        // Load the texture I want to use
        Texture cbTexture = TextureManager.loadTexture
                (circleBearLocation,
                 Texture.MM_LINEAR,
                 Texture.FM_LINEAR);

        // set the textureState as cbTexture
        textureState.setTexture(cbTexture);

        // set the renderState of both box1 and pyramid1 as textureState
        box1.setRenderState(textureState);
        pyramid1.setRenderState(textureState);

        box1.updateRenderState();
        pyramid1.updateRenderState();

        // get rid of any default lighting set by simpleGame
        lightState.detachAll();
    }

    public static void main(String[] args)
    {
        HelloTextures1 textureWorld = new HelloTextures1();
        textureWorld.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
        textureWorld.start();
    }
}

Wow do I feel stupid… It is probably gonna have a hard time being visible if I use the line:


lightState.detachAll();



never mind on this one... thanks for all the help though!

nevermind, these things happen.