Missing texture

hi i am just starting with jme and i was trying to apply a texture to a box i made.



here is my code:





 



Box b=new Box("my box",new Vector3f(1,1,1),new Vector3f(6,6,6));



URL crateTex;

  crateTex=HelloStates.class.getClassLoader().getResource("crate.png");

  Image crateIm = Toolkit.getDefaultToolkit().getImage(crateTex);

   // Get a TextureState

  TextureState ts=display.getRenderer().createTextureState();

  // Use the TextureManager to load a texture

  Texture t =

   TextureManager.loadTexture(crateIm,

   Texture.MM_LINEAR,

   Texture.FM_LINEAR,true);

  // Assign the texture to the TextureState

  ts.setTexture(t);



 b.setRenderState(ts);





when i load up the program the box is displayed but instead of the crate image it says "texture missing" on it.



can anyone help?

the image crate.png is in my classpath

For troubleshooting purposes, try replacing the piece of your code with the following:


URL crateTex;
  crateTex=HelloStates.class.getClassLoader().getResource("crate.png");
  Image crateIm = Toolkit.getDefaultToolkit().getImage(crateTex);
  System.out.println(crateIm == null ? "My image path is incorrect." : "Image path is ok, problem is somewhere else.");
   // Get a TextureState
  TextureState ts=display.getRenderer().createTextureState();
  // Use the TextureManager to load a texture
  Texture t =
   TextureManager.loadTexture(crateIm,
   Texture.MM_LINEAR,
   Texture.FM_LINEAR,true);
  // Assign the texture to the TextureState
  ts.setTexture(t);



Look in the console, if you see "My image path is incorrect." then double check your image path vs your package structure. If you image in inside "com.mycompany.mypackage" then the resource string should be "com/mycompany/mypackage/myimage.png"

its ok i found the problem in the end, renamed it to a jpg and it worked fine!

does that mean that png's cant be used?



nevermind not too bothered anyway.



i have a new problem now though, in the example codes he uses Text to create a crosshair.

can the same be done with an uber cool crosshair Image? (like this one:  http://sniperkustoms.com/Sniper_Kustoms_Crosshair_NEWblack2.JPG)



if so how do i do it?

can i add a normal awt image to the fpsNode or do i have to use the Image class in jme or can i not do it at all :frowning:

Take into account that JPGs do not support transparency. Also  jME should be able to load TGAs, PNGs, GIFs, JPGs, etc, etc… That cannot be your problem. Maybe you are using an old JVM that does not support PNG? (like 1.4 or something)

You can check what extensions are supported by using ImageIO.getReaderFileSuffixes()