Multitexture multiple textures acts strange

I have a terrain object that is multitextured with 3 textures. One is the base texture, it rarely changes. The other two are regenerated often (after mouse release and so forth). Originally there were only two textures, the base and one changing texture but I am working on adding the 3rd. The problem is, the addition of the 3rd texture causes the terrain to turn black at about 50% transparency. I checked the generated texture image and it is fine. Also, if I replace the original changing texture, everything works fine. Here is how the terrain textures are initially setup:


 TextureUnitState[] texUnitStates = new TextureUnitState[] { new TextureUnitState(null, null, null), new TextureUnitState(null, null, null), new TextureUnitState(null, null, null) };
                                                                                                                                                              
... (other intialization for the class) ...

    geo = new IndexedTriangleArray(
        MAX_VERTICES,
        GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.COLOR_3 | GeometryArray.TEXTURE_COORDINATE_2 |
        GeometryArray.BY_REFERENCE,
        texUnitStates.length, new int[texUnitStates.length], MAX_INDICES);

...


    TextureAttributes texAttribs = new TextureAttributes();
    texAttribs.setTextureMode(TextureAttributes.NICEST);
                                                                                                                                                              
    texUnitStates[0] = new TextureUnitState(tm.getTexture(), texAttribs, null);
    a.setTextureUnitState(texUnitStates);
                                                                                                                                                              
    shape = new Shape3D(geo,a);

texUnitStates[1] and texUnitStates[2] are the textures that are updated. I do this by removing the old texture and generating a new one with Java2D buffered images, then adding the texture with this method. texIndex is the index into texUnitStates above:


  public void addTexture(Texture texture, int texIndex) {
                                                                                                                                                              
    System.err.println("addTexture(" + texture + ", " + texIndex + ")");
                                                                                                                                                              
    TextureAttributes texAttribs = new TextureAttributes();
    texAttribs.setTextureMode(TextureAttributes.NICEST);
                                                                                                                                                              
    TextureUnitState texUnitState = new TextureUnitState(texture, texAttribs, null);
                                                                                                                                                              
    TransparencyAttributes transAttrib = new TransparencyAttributes();
    transAttrib.setMode(TransparencyAttributes.BLENDED);
    transAttrib.setTransparency(0.5f);
                                                                                                                                                              
    Appearance appearance = shape.getAppearance();
    appearance.setTransparencyAttributes(transAttrib);
    texUnitStates[texIndex] = texUnitState;
    appearance.setTextureUnitState(texUnitStates);                                                                                                                                                              
                                                                                                                                                              
    shape.setAppearance(appearance);
  }

and to remove the texture:


  public void removeTexture(int texUnitStateIndex) {
    texUnitStates[texUnitStateIndex] = new TextureUnitState(null, null, null);
    Appearance appearance = shape.getAppearance();
    appearance.setTextureUnitState(texUnitStates);
    shape.setAppearance(appearance);
  }

The problem is, with the addition of the third texture, when the add and remove methods are called, the whole terrain shape turns black. The first two textures appear on the shape but the last (and newest) texture does not. As I said, if I go back to loading just the two textures, then the new texture will load fine. Has anyone seen this before?

I think :-/ that your video card requires support for the third texture for this to work. An alternate approach is describe in a texture tutorial I wrote on the xith.org site. Basically yoy can use an orderedgroup to layer multiple textures…give it a look. In one example I have two textures blend giving grass-on-rock with an animated texture layered on top

I’m using a Radeon 9800 Pro. I think it has support for up to 5 textures (?). I looked at the DecalGroup tutorial but I’m not sure how I can apply those concepts to my terrain. It looks like in the sample source there are a number of textured quads overlaid on one another. I’m applying my textures across the entire terrain so I don’t want to store all that data multiple times. I guess I’ll have to do pre-generation of the image and apply it to the base texture.