java left logo
java middle logo
java right logo
 

Home arrow Other API Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4093
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to apply a texture to a visual object E-mail
User Rating: / 9
PoorBest 

Texturing, also called texture mapping, is a way to add the visual richness of a surface without adding the fine geometric details. The visual richness is provided by an image, also called a texture, which gives the appearance of surface detail for the visual object. The image is mapped on to the geometry of the visual object at rendering time.

You may apply a texture to a virtual object according to this recipe:

  1. Prepare texture images
  2. Load the texture
  3. Set the texture in Appearance bundle
  4. Specify TextureCoordinates of Geometry

Image

class TextureApp extends JFrame{

  // Create a Texture object
  private Texture createTexture() {
    String filename = "brick.gif";
    // Load the texture
    TextureLoader loader = new TextureLoader(filename, null);
    ImageComponent2D image = loader.getImage();

    if (image == null) {
      System.out.println("load failed for texture: " + filename);
    }

    // can't use parameterless constuctor
    Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA,
        image.getWidth(), image.getHeight());
    texture.setImage(0, image);

    return texture;
  }
  
  private BranchGroup createSceneGraph(SimpleUniverse su){
    ...
    
    MyBox box=new MyBox(0.4f,0.4f);
    // Set the texture in Appearance hundle
    Appearance appear=box.getAppearance();
    appear.setTexture(createTexture());
    
    // Map the texture coordinate
    TexCoord2f[] texCoords = new TexCoord2f[24];
    for (int i = 0; i < texCoords.length; i += 4) {
      texCoords[inew TexCoord2f(0.0f0.0f);
      texCoords[i + 1new TexCoord2f(0.0f1.0f);
      texCoords[i + 2new TexCoord2f(1.0f1.0f);
      texCoords[i + 3new TexCoord2f(1.0f0.0f);
    }
    QuadArray quadArray=(QuadArray)box.getGeometry();
    quadArray.setTextureCoordinates(00, texCoords);
    
    objSpin.addChild(box);
    
    ...
  }
  
  ...
}

 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.