2D texture transparency

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Yotunii
Posts: 16
Joined: Sun Aug 13, 2006 9:44 am

2D texture transparency

Post by Yotunii »

Hey everyone =)
I just started using the Irrlicht engine yesterday, so I have a lot to learn.

I have a transparent texture that I have to render as 2D (draw2DImage), but I cannot figure out how to make it render it with the transparency.
I tried to make a color key for the texture, but of course this doesn't work anywhere near optimally, since the transparent parts aren't a single color.

Thanks for your help,
Rasmus Larsen
terence
Posts: 12
Joined: Sat Apr 01, 2006 2:22 pm
Contact:

Post by terence »

From what I know:

1) Have your source image be able to support an alpha channel (i.e. PNG or TGA). Make sure the alpha channel is properly set oon the image
2) OR designed a specific color to be transparent(I use 255,0,255(rgb).
For this make sure all parts of your image that you want transparent use this color. Make sure the pixel at 0,0 is using your transparent color.
3) Next load the image using getTexture()
a) You are doing step 2. call makeColorTexture using 0,0 as your alpha color..(The other call which uses color r,g,b values may not work properly because your source image may have had colors changed upon load..for different bit depths etc.)

check the API reference of draw2DImage:
virtual void irr::video::IVideoDriver::draw2DImage ( video::ITexture * texture,
const core::position2d< s32 > & destPos,
const core::rect< s32 > & sourceRect,
const core::rect< s32 > * clipRect = 0,
SColor color = SColor(255, 255, 255, 255),
bool useAlphaChannelOfTexture = false
)

Make sure you last parameter is true.

Funny ..alpha transparency using an alpha channel work with Software2 renderer but doesn't seem to work with the default Software render.
Yotunii
Posts: 16
Joined: Sun Aug 13, 2006 9:44 am

Post by Yotunii »

Yeah, my image is a PNG saved with Photoshop, and it has a correct alpha channel. The problem is that Irrlicht renders it white instead of transparent. The second method won't work, since some parts are only partly transparent.
terence
Posts: 12
Joined: Sat Apr 01, 2006 2:22 pm
Contact:

Post by terence »

Check the driver you are using...

When I use the default software one, transparency seem broken...

When I use the apel(wacha macallit one) software renderer...trasprencies are fine..
Works with directx, opengl as well..

Could be a driver issue with specific cards...not sure? Only have about 2 more days on you with Irrilicht...with my 2D game conversion...so far..not so good..well i got to refactor my code..clean up the stupid stuff I did in my game a 2 months ago..
Yotunii
Posts: 16
Joined: Sun Aug 13, 2006 9:44 am

Post by Yotunii »

Yeah, well, I've written my own engine before, and it worked perfect there. I am using OpenGL device currently, but it doesn't work with ANY device.

In my engine I loaded images with the Corona library, and then simply drew them. All I had to do to make transparency work was enabling GL_BLEND and setting glBlendFunc. This, unfortunately, doesn't work here.

Anyone?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You should not mess around with OpenGL states in general. These are usually overwritten. Use Irrlicht materials for that. Read the tutorials, they are already doing many of those things.
Yotunii
Posts: 16
Joined: Sun Aug 13, 2006 9:44 am

Post by Yotunii »

Can you please give me a simple example of materials? Cause I don't understand how to implement them.
Post Reply