Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (429)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (468)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Multitexture multiple textures acts strange  (Read 611 times)
0 Members and 1 Guest are viewing this topic.
Offline Planner1

Senior Newbie





« Posted 2004-05-04 16:57:35 »

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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
 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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
  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:

1  
2  
3  
4  
5  
6  
  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?
Offline hawkwind

Junior Member




Java games rock!


« Reply #1 - Posted 2004-05-05 00:23:39 »

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
Offline Planner1

Senior Newbie





« Reply #2 - Posted 2004-05-05 13:31:14 »

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.  
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (81 views)
2014-04-15 18:08:23

BurntPizza (73 views)
2014-04-15 03:46:01

UprightPath (84 views)
2014-04-14 17:39:50

UprightPath (67 views)
2014-04-14 17:35:47

Porlus (84 views)
2014-04-14 15:48:38

tom_mai78101 (107 views)
2014-04-10 04:04:31

BurntPizza (167 views)
2014-04-08 23:06:04

tom_mai78101 (263 views)
2014-04-05 13:34:39

trollwarrior1 (214 views)
2014-04-04 12:06:45

CJLetsGame (223 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!