Java 3D Texture Mapping Error

165 views Asked by At

I am new to Java 3D and I am trying to use texture mapping. I want to add a texture to either a custom shape or a default sphere. When I attempt to do it, the whole shape is set to the color of the bottom left pixel. I looked at this problem Java3d: Texture is not applied to OBJ model properly

and I tried the code given there and that did not work either. Here is what I did.

Sphere sphere = new Sphere(.5f);
sphere.getAppearance().getMaterial().setShininess(10f);




try{
    File f = new File("Texture1.bmp");
    TextureLoader Texget=new TextureLoader(f.toURI().toURL(), null);

    ImageComponent2D image = Texget.getImage();
    Texture2D ourTex = new Texture2D( Texture.BASE_LEVEL,Texture.RGBA,image.getWidth(),image.getHeight() );
    ourTex.setImage(0, image);
    ourTex.setEnable(true);

    sphere.getAppearance().setTexture(ourTex);




}
catch (java.net.MalformedURLException e)
{
    System.err.println("error loading textures");
    e.printStackTrace();
}

Any ideas? Thanks.

0

There are 0 answers