2D image 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.
Dark_Exodus
Posts: 23
Joined: Thu Jan 29, 2004 4:07 pm
Location: Birmingham, UK
Contact:

2D image transparency?

Post by Dark_Exodus »

Hi

I'm trying to draw a 2D image over my quake 3 map (like a HUD) but I can’t get transparency to work. The complete image is drawn to the screen.
:(

Here is the code I’m using:
driver->makeColorKeyTexture(lives,core::position2d<s32>(0,0));

driver->draw2DImage(lives,core::position2d<s32>(500,0));
Dark_Exodus
Posts: 23
Joined: Thu Jan 29, 2004 4:07 pm
Location: Birmingham, UK
Contact:

Post by Dark_Exodus »

no one able to help? :(
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

i had a problem like this in a earlier version of irrlicht. I'm not sure if the alpha setting affects 2d images, or i may be a problem with the format your image is stored in.
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

You might try rt's png load, since png's support transparency. (I know thats not really what you want but maybe it will work for you until you can get the other figured out)
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Post by rt »

thesmileman wrote:You might try rt's png load, since png's support transparency. (I know thats not really what you want but maybe it will work for you until you can get the other figured out)
if you don't want to bulid in .png supprt, you can use 32bit .tga which also supports an alpha channel. you have to tweak some of the render settings in the engine since they don't seems to be set correctly for image alpha blending .. check out my PNG thread to learn more
Dark_Exodus
Posts: 23
Joined: Thu Jan 29, 2004 4:07 pm
Location: Birmingham, UK
Contact:

Post by Dark_Exodus »

Ok thanks guys I'll try using a different picture format.
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

let us know if you find a solution
Dark_Exodus
Posts: 23
Joined: Thu Jan 29, 2004 4:07 pm
Location: Birmingham, UK
Contact:

Post by Dark_Exodus »

sure thing :D
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post by shurijo »

I'm having a similiar problem. The transparency (makeColorKeyTexture) almost works... my ugly purple (target color) becomes black instead of transparent, so it covers the stuff underneath it.
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

transparency for one color works, look at the 2D tutorial. I have previously used the command without a problem but i haven't tried it with 0.5 yet. Have your declared makeColoeKeyTexture the same as in the 2D graphic tutorial?.
Dark_Exodus
Posts: 23
Joined: Thu Jan 29, 2004 4:07 pm
Location: Birmingham, UK
Contact:

Post by Dark_Exodus »

I think I did. :roll: I'll go back and have a look at that.
Xception
Posts: 22
Joined: Tue Feb 24, 2004 10:05 am

Post by Xception »

There are 2 "draw2DImage" methods.
You have to use the other one with more parameters that supports transparency like in the 2DGraphics example:

Code: Select all

// draw flying imp 
driver->draw2DImage(images, core::position2d<s32>(164,125),(time/500 % 2) ? imp1 : imp2, 0, video::SColor(255,255,255,255), true);
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

I have just thought of a cheap hack that might be useful. This used to be used on website with DHTML to create transparent images. Take you image and load into a editor like photoshop. Then make evey second pixel of the image the same color as your are using for makeColorKeyTexture. Now when the image i drawn every 2nd pixel is tranparent, which give te impression of a transparent image. However if your are using small images, or images with a lot of detail this would probably not be the best method. You can also change which pixels you change to try for slight different level o transparency, like using interlacing (evey 2nd or so line use the ugly purple color)
Luke923
Posts: 59
Joined: Wed Nov 05, 2003 5:26 am

Post by Luke923 »

I know that this might be a stupid question, but is the first pixel in your image the transparent color? Otherwise, try using "dirver->makeColorKeyTexture(lives, video::SColor(255,255,255,255));"
"Object-oriented programming is an exceptionally bad idea which could only have originated in California."
- E.W. Dijkstra
NecromanX
Posts: 16
Joined: Sat Jan 24, 2004 6:01 pm

Post by NecromanX »

listen to what Xception says.
The function you use simply draws an image as stated in the API,
the second function will also apply the alpha channel when setting the last parameter to true. try this instead:

driver->makeColorKeyTexture(lives,core::position2d<s32>(0,0));

driver->draw2DImage(lives,core::position2d<s32>(500,0),core::rect<s32>(0,0,x,x), 0,video::SColor(255,255,255,255), true);

change the 2 x values with the size of your picture minus 1 then it will apply the alpha channel and your image will be transparent
Post Reply