www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: Hsaka on April 15, 2009, 08:08:57 am

Title: Texture Opacity
Post by: Hsaka 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 (http://img12.imageshack.us/my.php?image=build1.png)
(http://img12.imageshack.us/img12/2678/build1.th.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 (http://img12.imageshack.us/my.php?image=83972871.png)
(http://img12.imageshack.us/img12/7884/83972871.th.png)
Code: [Select]
plane.setTransparency(-1);
http://img22.imageshack.us/my.php?image=76106834.png (http://img22.imageshack.us/my.php?image=76106834.png)
(http://img22.imageshack.us/img22/6531/76106834.th.png)
Code: [Select]
plane.setTransparency(0);
http://img11.imageshack.us/my.php?image=43452437.png (http://img11.imageshack.us/my.php?image=43452437.png)
(http://img11.imageshack.us/img11/8802/43452437.th.png)
Code: [Select]
plane.setTransparency(0);
plane.setTransparencyMode(Object3D.TRANSPARENCY_MODE_ADD);

Any help will be appreciated.
Title: Re: Texture Opacity
Post by: EgonOlsen 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...
Title: Re: Texture Opacity
Post by: EgonOlsen 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?
Title: Re: Texture Opacity
Post by: fireside 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.
Title: Re: Texture Opacity
Post by: EgonOlsen 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.
Title: Re: Texture Opacity
Post by: Hsaka 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
Title: Re: Texture Opacity
Post by: EgonOlsen 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.
Title: Re: Texture Opacity
Post by: Hsaka 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.