Assigning texture coordinates to each vertex of the geometry is a necessary step in texturing visual objects. This process can be time consuming as well as difficult for large and/or complex visual objects.

Texture coordinates are often assigned with code specific to a visual object. However, another solution is to automate the assignment of texture coordinates via some method. This method could be used for any visual object whether large or small, complex or simple. This approach is exactly what a TexCoordGeneration (texture coordinate generation) object does.

 public class TexCoordGenApp extends JFrame {

    Appearance createAppearance(){
        Appearance appear = new Appearance();

        // Create a TexCoordGeneration object
        TexCoordGeneration tcg = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR,

        // Prepare the Texture
        String filename = "earth.jpg";
        TextureLoader loader = new TextureLoader(filename, this);
        ImageComponent2D image = loader.getImage();

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

        Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA,
                                      image.getWidth(), image.getHeight());
        texture.setImage(0, image);


        return appear;

    public BranchGroup createSceneGraph() {
        Sphere sphere=new Sphere(0.4f,createAppearance());