Loading textures HELP PLZ

Im trying to load and apply a texture to a sphere using this code but it doesn't work…

Sphere player = new Sphere( "Player Avatar", 20, 20, 15 );
        player.setLocalTranslation( 0, 0, -40 );

        ts = display.getRenderer().createTextureState();
        ts.setEnabled(true);
        ts.setTexture(TextureManager.loadTexture(
                    "C:/texture.jpg",
                    Texture.MinificationFilter.BilinearNearestMipMap,
                    Texture.MagnificationFilter.Bilinear));


        player.setRenderState(ts);



I get this warning:

WARNING: Unable to locate: C:/texture.jpg



can anyone tell me what im doing wrong...

URL should look like this: file://c:/something.jpg i guess.

still doesn't work

You should place your texture in the classpath. Let's say you have following package-structure:



org.aqua



Game.java



org.aqua.res





  texture.jpg



then you can get it like this in the Game.java:


        ts.setTexture(TextureManager.loadTexture(
                    Game.class.getClassLoader().getResource("org/aqua/res/texture.jpg"),
                    Texture.MinificationFilter.BilinearNearestMipMap,
                    Texture.MagnificationFilter.Bilinear));



Something like this. Hope I didn't misspelled anything


Actually this is my helper-class for loading textures:


   public static TextureState loadTexture(String ressource)
   {
       TextureState ts  = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
       ts.setTexture(
         TextureManager.loadTexture(
         Utils.class.getClassLoader().getResource(
         ressource),
         Texture.MinificationFilter.Trilinear,
         Texture.MagnificationFilter.Bilinear));
       return ts;
   }



Replace "Utils" by the name of your class and you should get a ready texturestate by calling
the static-method  loadTexture("org/aqua/res/texture.jpg")

You must use

TextureManager.loadTexture(URL); with "C:/texture.jpg"



or you can use directly

TextureManager.loadTexture("texture.jpg")

if you specify a resource locator :

ResourceLocatorTool.addResourceLocator(

ResourceLocatorTool.TYPE_TEXTURE,

new SimpleResourceLocator(UrlDirectory)

);

I have had the same problem.



I use


YOURCLASS.getClass().getResource("myresource.jpg");



Now that is given if the resource is in the same folder/package of your java/class file, if its different then:


YOURCLASS.getClass().getResource("folder/res.jpg");



So what I use is:


        TextureState ts = display.getRenderer().createTextureState();
        Texture t = TextureManager.loadTexture(this.getClass().getResource("folder/res.jpg"), Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear);
        ts.setTexture(t);



Hope i was useful :)

hehe,…so now you can choose from all that possible ways :smiley: