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
 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();
    // Map the texture coordinate
    TexCoord2f[] texCoords = new TexCoord2f[24];
    for (int i = 0; i < texCoords.length; i += 4) {
      texCoords[i] = new TexCoord2f(0.0f, 0.0f);
      texCoords[i + 1] = new TexCoord2f(0.0f, 1.0f);
      texCoords[i + 2] = new TexCoord2f(1.0f, 1.0f);
      texCoords[i + 3] = new TexCoord2f(1.0f, 0.0f);
    QuadArray quadArray=(QuadArray)box.getGeometry();
    quadArray.setTextureCoordinates(0, 0, texCoords);