|
How to change the boundary mode of Texture |
|
|
The boundary mode setting determines what mapping takes place when the texture
coordinates go beyond the 0 to 1 range of the image space. The choices are to
wrap the image, or to clamp it.Wrapping, which means to repeat the image as needed,
is the default. Clamping the image uses the color from the edge of the image
anywhere outside of the 0 to 1 range. These settings are made independently
in the s and t dimensions.
private BranchGroup createSceneGraph(SimpleUniverse su){
...
MyBox box1=new MyBox(0.6f,0.6f);
Appearance appear=box1.getAppearance();
// Use the Texture with the default settings of boundary mode
appear.setTexture(createTexture());
// Map the texture coordinate
TexCoord2f[] texCoords = new TexCoord2f[24];
for (int i = 0; i < texCoords.length; i += 4) {
texCoords[i] = new TexCoord2f(1.5f, 0.0f);
texCoords[i + 1] = new TexCoord2f(0.0f, 0.0f);
texCoords[i + 2] = new TexCoord2f(0.0f, 1.5f);
texCoords[i + 3] = new TexCoord2f(1.5f, 1.5f);
}
QuadArray quadArray=(QuadArray)box1.getGeometry();
quadArray.setTextureCoordinates(0, 0, texCoords);
tg1.addChild(box1);
MyBox box2=new MyBox(0.6f,0.6f);
appear=box2.getAppearance();
Texture texture=createTexture();
// Change the boundary mode
texture.setBoundaryModeT(Texture.CLAMP);
texture.setBoundaryModeS(Texture.WRAP);
appear.setTexture(texture);
// Map the texture coordinate
texCoords = new TexCoord2f[24];
for (int i = 0; i < texCoords.length; i += 4) {
texCoords[i] = new TexCoord2f(1.5f, 0.0f);
texCoords[i + 1] = new TexCoord2f(0.0f, 0.0f);
texCoords[i + 2] = new TexCoord2f(0.0f, 1.5f);
texCoords[i + 3] = new TexCoord2f(1.5f, 1.5f);
}
quadArray=(QuadArray)box2.getGeometry();
quadArray.setTextureCoordinates(0, 0, texCoords);
tg2.addChild(box2);
MyBox box3=new MyBox(0.6f,0.6f);
appear=box3.getAppearance();
texture=createTexture();
// Change the boundary mode
texture.setBoundaryModeT(Texture.WRAP);
texture.setBoundaryModeS(Texture.CLAMP);
appear.setTexture(texture);
// Map the texture coordinate
texCoords = new TexCoord2f[24];
for (int i = 0; i < texCoords.length; i += 4) {
texCoords[i] = new TexCoord2f(1.5f, 0.0f);
texCoords[i + 1] = new TexCoord2f(0.0f, 0.0f);
texCoords[i + 2] = new TexCoord2f(0.0f, 1.5f);
texCoords[i + 3] = new TexCoord2f(1.5f, 1.5f);
}
quadArray=(QuadArray)box3.getGeometry();
quadArray.setTextureCoordinates(0, 0, texCoords);
tg3.addChild(box3);
MyBox box4=new MyBox(0.6f,0.6f);
appear=box4.getAppearance();
texture=createTexture();
// Change the boundary mode
texture.setBoundaryModeT(Texture.CLAMP);
texture.setBoundaryModeS(Texture.CLAMP);
appear.setTexture(texture);
// Map the texture coordinate
texCoords = new TexCoord2f[24];
for (int i = 0; i < texCoords.length; i += 4) {
texCoords[i] = new TexCoord2f(1.5f, 0.0f);
texCoords[i + 1] = new TexCoord2f(0.0f, 0.0f);
texCoords[i + 2] = new TexCoord2f(0.0f, 1.5f);
texCoords[i + 3] = new TexCoord2f(1.5f, 1.5f);
}
quadArray=(QuadArray)box4.getGeometry();
quadArray.setTextureCoordinates(0, 0, texCoords);
tg4.addChild(box4);
...
}
|
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.