How to draw transparent 2D sprites?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Cairon
Posts: 40
Joined: Sun Apr 11, 2004 12:52 am
Contact:

How to draw transparent 2D sprites?

Post by Cairon »

Hello everybody :)

I tried every function i found in the docu, to draw a 2d image with an alpha value, but nothing seams to work.

F.e. I made this function, which draws an 2d image at every resolution at the same position with same size:

#define SX(val) ( (int)(device->getVideoDriver()->getScreenSize().Width*(float)(val)/1280.0f) )
#define SY(val) ( (int)(device->getVideoDriver()->getScreenSize().Height*(float)(val)/960.0f) )

void CGame::DrawHUDElement(core::position2d<s32> pos, video::ITexture* texture, int alpha)
{
video::IVideoDriver* driver = device->getVideoDriver();
core::dimension2d<s32> size = texture->getOriginalSize();
driver->draw2DImage(texture, core::position2d<s32>(SX(pos.X), SY(pos.Y)), core::rect<s32>(0,0, size.Width, size.Height), NULL, video::SColor(alpha, 255,255,255), false );
}

But the alpha values is not used, the image is not transparent.
If I set the last paramter to true, the image is transparent, but the alpha values is completly ignored.

Is there another way of drawing a 2d image, is this a bug ?

Thanks
Artur Hallmann
Nessie
Posts: 14
Joined: Thu Apr 08, 2004 4:27 pm
Location: Madison, WI, USA

Post by Nessie »

It seems to me that I had problems with textures having an alpha channel rendering correctly. Are you using openGL? DirectX?

In either, case the problem didn't seem too hard to fix. But, in general, I think IrrLicht could really use some work on the material system.
"Build a man a fire and he'll be warm for the evening. Set a man on fire and he'll be warm for the rest of his life." -unknown
Cairon
Posts: 40
Joined: Sun Apr 11, 2004 12:52 am
Contact:

Post by Cairon »

Its the same with opengl, directx8.1, and directx9. The image I use, are jpg's.
In either, case the problem didn't seem too hard to fix.
Well, who can i fix it then? ;)
Post Reply