|
Using TexCoordGeneration to generate the texture coordinates |
|
|
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,
TexCoordGeneration.TEXTURE_COORDINATE_2);
appear.setTexCoordGeneration(tcg);
// 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);
texture.setEnable(true);
appear.setTexture(texture);
return appear;
}
public BranchGroup createSceneGraph() {
...
Sphere sphere=new Sphere(0.4f,createAppearance());
objSpin.addChild(sphere);
...
}
}
|
Related Tips
|
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.