Author Topic: Texture Opacity  (Read 4771 times)

Offline Hsaka

  • byte
  • *
  • Posts: 8
    • View Profile
Texture Opacity
« on: April 15, 2009, 08:08:57 am »
Hi. I have a tile map made by blitting a set of textures onto the screen. I'm trying to place a textured plane onto the map. The texture image is a png file with an alpha channel:
http://img12.imageshack.us/my.php?image=build1.png



I use this to create the texture:
Code: [Select]
game.getTextureManager().addTexture("build1", new Texture("res/build1.png",true));
I'd like the opaque areas of the texture to remain opaque on the textured plane. However, this is what I get:
http://img12.imageshack.us/my.php?image=83972871.png

Code: [Select]
plane.setTransparency(-1);
http://img22.imageshack.us/my.php?image=76106834.png

Code: [Select]
plane.setTransparency(0);
http://img11.imageshack.us/my.php?image=43452437.png

Code: [Select]
plane.setTransparency(0);
plane.setTransparencyMode(Object3D.TRANSPARENCY_MODE_ADD);

Any help will be appreciated.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Texture Opacity
« Reply #1 on: April 15, 2009, 08:22:39 am »
Looks to me as if some light source, ambient light or additional color lights up the plane...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Texture Opacity
« Reply #2 on: April 15, 2009, 09:11:17 am »
..or maybe RGB-Scaling is active? Why is the building a plane at all? Why don't you blit it like the rest of the map?
« Last Edit: April 15, 2009, 10:49:09 am by EgonOlsen »

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: Texture Opacity
« Reply #3 on: April 15, 2009, 12:07:37 pm »
I've found something like this with my game, which is in software mode.  The billboard trees look pretty opaque unless I put a creature behind them and then I can see translucency in the texture.
click here->Fireside 7 Games<-

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Texture Opacity
« Reply #4 on: April 15, 2009, 01:35:43 pm »
Oh, i thought the problem was that everything is so bright...i should have read your post better. Just use a higher transparency setting like 10 or 15 and the opaque parts should be opaque.

Offline Hsaka

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Texture Opacity
« Reply #5 on: April 16, 2009, 02:06:53 am »
Thanks for the quick answers guys.

As it turns out, I was drawing in the wrong order. I had something like this:
Code: [Select]
buffer.clear(java.awt.Color.BLACK);               
world.renderScene(buffer);               
world.draw(buffer);               
buffer.update();
...
currentMap.render(buffer);

Now I've changed it to this:
Code: [Select]
buffer.clear(java.awt.Color.BLACK);               
world.renderScene(buffer);   
currentMap.render(buffer);           
world.draw(buffer);               
buffer.update();
...

Is there any problem if I do this? Then reason I ask is because my map will now not show for a short while (I suspect until all the Object3Ds in the world are displayed), and this:
"renderScene: When using the OpenGL renderer, this method has to be called at least once before blitting into the OpenGL FrameBuffer will work correctly. If you are not abusing jPCT as a pure 2D blitting engine, then this shouldn't be a problem anyway."

Quote
Why is the building a plane at all? Why don't you blit it like the rest of the map?
I'm building a 2D RTS, and I'd like the buildings to be built anywhere on the map, and I think I'm pretty close to abusing jPCT as a blitting engine  ;D

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Texture Opacity
« Reply #6 on: April 16, 2009, 07:24:53 am »
Order is fine. Blitting in OpenGL-mode may not work until one render pass has been completed. You may try to place some renderScene()/draw()-call before your actual game loop just to warm up things. That may help with the map. I'm a bit confused about your former order and the actual outcome. I would have expected something else, but as long as it works now, all is fine i guess.

Offline Hsaka

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Texture Opacity
« Reply #7 on: April 16, 2009, 09:21:59 am »
Thanks Egon.

In the former order, the map was blitted with transparency, so that was why I could still see the planes through the map even though the map was being blitted on top of the planes.