2D image transparency?
-
- Posts: 23
- Joined: Thu Jan 29, 2004 4:07 pm
- Location: Birmingham, UK
- Contact:
2D image transparency?
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));
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));
-
- Posts: 23
- Joined: Thu Jan 29, 2004 4:07 pm
- Location: Birmingham, UK
- Contact:
-
- Posts: 360
- Joined: Tue Feb 10, 2004 2:20 am
- Location: Lubbock, TX
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 morethesmileman 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)
-
- Posts: 23
- Joined: Thu Jan 29, 2004 4:07 pm
- Location: Birmingham, UK
- Contact:
-
- Posts: 23
- Joined: Thu Jan 29, 2004 4:07 pm
- Location: Birmingham, UK
- Contact:
-
- Posts: 23
- Joined: Thu Jan 29, 2004 4:07 pm
- Location: Birmingham, UK
- Contact:
There are 2 "draw2DImage" methods.
You have to use the other one with more parameters that supports transparency like in the 2DGraphics example:
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);
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)
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
- E.W. Dijkstra
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
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