How to make transparent images?

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
seno
Posts: 34
Joined: Thu Nov 17, 2005 2:50 am
Location: Seoul Korea

How to make transparent images?

Post by seno »

Hi.

I am making a 2D puzzle game with Irrlicht engine and during making

i got problem about transparent image, which you can see from the

below example screen shot.

Image

I used IVideoDriver::draw2DImage functions and I recognized the bug

of the function and fixed that bug by referencing this post..

http://irrlicht.sourceforge.net/phpBB2/ ... ates2dmode

Then i set the parameter of draw2DImage for the mouse cursor like this.

Code: Select all

my_videoDriver->draw2DImage(
	this->my_cursorTexture.imageTexture,
	irr::core::position2d<irr::s32>(
	    my_currentMousePos.x - this->my_startPoint.x, 
	    my_currentMousePos.y - this->my_startPoint.y),
	this->my_cursorImage[this->my_currentCursorIndex].sourceRect,
	NULL,
	irr::video::SColor(130, 255, 255, 255), false);
Actually, i tried to use AlphaChannel by setting the last parameter of the

draw2DImage to 'true'. However, i realized using AlphaChannel and

transparented image can't be used together. Then,

HOW TO MAKE TRANSPARENT IMAGE WITH SETTING ALPHACHANNEL?

Above picture's cursor is TRANSPARENT IMAGE WITHOUT SETTING ALPHA

CHANNEL.


By the way, i found a post handling the similar problem.

http://irrlicht.sourceforge.net/phpBB2/ ... ding+image

But i am not sure how to use EMT_TRANSPARENT_ADD_COLOR. Is this

solution? then how can i set the value?


Any advice will be very helpful. Thanks.
Let's Take Over the World ~!!
Xaron
Posts: 310
Joined: Sun Oct 16, 2005 7:39 am
Location: Germany
Contact:

Post by Xaron »

Hi,

you don't want to make the whole image transparent but only a part, I guess? The bugfix you mentioned is only for making a complete texture more or less transparent.

You can't deal with the material flag on the texture level, you need a mesh for that.

So the easiest would be to use an image with has an alpha channel which defines the transparent and non-transparent parts. So you don't need that bugfix and just use draw2DImage with the last parameter as true.

Regards - Xaron
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Do you want the whole cursor to have some transparency, or do you just want the outside black area to go away? If you just want to make the black area of the cursor transparent, you should ba able to do this...

Code: Select all

  // after loading texture
  driver->makeColorKeyTexture(cursor, core::position2d<s32>(0,0));

  // when you render the cursor, set useAlphaChannel to true
  driver->draw2DImage(cursor, ..., true);
If you want parts of the image to be fully transparent and others to be partially transparent, you will need to add an alpha channel to your cursor image.
seno
Posts: 34
Joined: Thu Nov 17, 2005 2:50 am
Location: Seoul Korea

i want to draw the cursor image to be transparent without..

Post by seno »

Sorry. I didn't make my question clear. Actually, i changed the picture file.

previous picture file has red circle that i drew around the cursor.

Xaron, you are right.

I want to draw the cursor image to be transparent without the black

rectangle area of outside, and i thought i knew how to use draw2DImage

function. But according to what you said, the function can make separated

alpha channels to the image. For example, the black ouside rectangle area

can be unseen and the cursor image can be transparent.


Am i understanding correctly?


By the way, sorry for my short english.
Let's Take Over the World ~!!
Xaron
Posts: 310
Joined: Sun Oct 16, 2005 7:39 am
Location: Germany
Contact:

Post by Xaron »

Yes I know what you mean.

You need texture with alpha channel in which all black areas are completely transparent and all other colors do have a transparency of 128 or whatever.

So you have to create such a texture. PNG and TGA format should work for that issue, JPG doesn't, because it has no alpha channel.

Regards - Xaron
seno
Posts: 34
Joined: Thu Nov 17, 2005 2:50 am
Location: Seoul Korea

Post by seno »

Sorry about my late reponse. I spent busy weekend. :lol:

Thank you Xaron, you cleared my question. I will try two make

my image to one of those file formats.
Let's Take Over the World ~!!
killzone721
Posts: 19
Joined: Thu Feb 09, 2006 1:45 am

Post by killzone721 »

so how would make an aimer transparent. I tried to use the idea above and even converted my picture to a tga file, and also made my filebackground black so it becomes transparant but it didn't work

//this is how loaded my aimer

IGUIImage* yo = sce->addImage(driver->getTexture("Pics/aim.tga"),position2d<int>(512,384));

// i don't know what to do to make the picture transparent

please and help and thxs for all the help
TO ALL THE AMATEURS OUT THERE LIKE ME......

AIM HIGH AND YOU MAKE SOMETHING PRETTY DECENT TO SHOW THE WORLD

CURRENTLY WORKING ON MY COMPANY WITH ME CREW MEMBERS. MY COMPANY IS CALLED
BIG DREAMS
AND WE ARE MAKE VERSION 0.1 FPS GAME
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

I need to render an image that has alpha channel, with transparency. I have a custom build of irrlicht based on D3D9 driver patch. Is that possible : both trnasparent and alphachannel set ?

Purpose : fading an image that has alpha channel.

Thanks.
Xterm-in'Hate.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

I'm not familliar with D3D9 programming but I found a solution to mix texture, alphachannel and transparency.

I modified draw2DImage and setRenderStates2DMode of CD3D9Driver.cpp.

See :
http://irrlicht.sourceforge.net/phpBB2/ ... 2237#72237

Hope that change will be integrated into the Irrlicht'15. :D

Thanks,
Xterminhate.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
Post Reply