java left logo
java middle logo
java right logo
 

Home arrow Other API Tips arrow Java3D arrow How to change the texture mode of Texture
 
 
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: 4091
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 change the texture mode of Texture E-mail
User Rating: / 5
PoorBest 

The texture mode setting is a major factor in determining how the texel value (color and/or alpha) affects the non-texture pixel color and alpha values. The actual texturing operation depends on the combination of the texture format and the texture mode.

The default texture mode is REPLACE, the other options are BLEND, DECAL, and MODULATE.

This program shows the effect of a Textured Box with different texture mode.


Image

private BranchGroup createSceneGraph(SimpleUniverse su){

    ...
    
    // Create a textured box with REPLACE mode
    MyBox box1=new MyBox(0.6f,0.6f);
    Appearance appear=box1.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(1.0f0.0f);
      texCoords[i + 1new TexCoord2f(0.0f0.0f);
      texCoords[i + 2new TexCoord2f(0.0f1.0f);
      texCoords[i + 3new TexCoord2f(1.0f1.0f);
    }
    
    QuadArray quadArray=(QuadArray)box1.getGeometry();
    quadArray.setTextureCoordinates(00, texCoords);
    tg1.addChild(box1);
    
    // Create a textured box with BLEND mode
    MyBox box2=new MyBox(0.6f,0.6f);
    appear=box2.getAppearance();
    Texture texture=createTexture();
    texture.setBoundaryModeT(Texture.CLAMP);
    texture.setBoundaryModeS(Texture.WRAP);
    appear.setTexture(texture);
    TextureAttributes ta=new TextureAttributes();
    ta.setTextureMode(TextureAttributes.BLEND);
    appear.setTextureAttributes(ta);
    
        // Map the texture coordinate
    texCoords = new TexCoord2f[24];
    for (int i = 0; i < texCoords.length; i += 4) {
      texCoords[inew TexCoord2f(1.0f0.0f);
      texCoords[i + 1new TexCoord2f(0.0f0.0f);
      texCoords[i + 2new TexCoord2f(0.0f1.0f);
      texCoords[i + 3new TexCoord2f(1.0f1.0f);
    }
    
    quadArray=(QuadArray)box2.getGeometry();
    quadArray.setTextureCoordinates(00, texCoords);
    tg2.addChild(box2);
    
    // Create a textured box with DECAL mode
    MyBox box3=new MyBox(0.6f,0.6f);
    appear=box3.getAppearance();
    texture=createTexture();
    texture.setBoundaryModeT(Texture.WRAP);
    texture.setBoundaryModeS(Texture.CLAMP);
    appear.setTexture(texture);
    ta=new TextureAttributes();
    ta.setTextureMode(TextureAttributes.DECAL);
    appear.setTextureAttributes(ta);
    
        // Map the texture coordinate
    texCoords = new TexCoord2f[24];
    for (int i = 0; i < texCoords.length; i += 4) {
      texCoords[inew TexCoord2f(1.0f0.0f);
      texCoords[i + 1new TexCoord2f(0.0f0.0f);
      texCoords[i + 2new TexCoord2f(0.0f1.0f);
      texCoords[i + 3new TexCoord2f(1.0f1.0f);
    }
    
    quadArray=(QuadArray)box3.getGeometry();
    quadArray.setTextureCoordinates(00, texCoords);
    tg3.addChild(box3);
    
    // Create a textured box with MODULATE mode
    MyBox box4=new MyBox(0.6f,0.6f);
    appear=box4.getAppearance();
    texture=createTexture();
    texture.setBoundaryModeT(Texture.CLAMP);
    texture.setBoundaryModeS(Texture.CLAMP);
    appear.setTexture(texture);
    ta=new TextureAttributes();
    ta.setTextureMode(TextureAttributes.MODULATE);
    appear.setTextureAttributes(ta);
    
        // Map the texture coordinate
    texCoords = new TexCoord2f[24];
    for (int i = 0; i < texCoords.length; i += 4) {
      texCoords[inew TexCoord2f(1.0f0.0f);
      texCoords[i + 1new TexCoord2f(0.0f0.0f);
      texCoords[i + 2new TexCoord2f(0.0f1.0f);
      texCoords[i + 3new TexCoord2f(1.0f1.0f);
    }
    
    quadArray=(QuadArray)box4.getGeometry();
    quadArray.setTextureCoordinates(00, texCoords);
    tg4.addChild(box4);
    
    ...
}

 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.