Help: Transparent images for HUD

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
Ryoga2k
Posts: 21
Joined: Mon May 03, 2004 6:59 pm
Location: Asturias, Spain

Help: Transparent images for HUD

Post by Ryoga2k »

Hi guys, I´ve got troubles loading some images in Irrlicht:

I´m trying to load an image on the GUI for the HUD of my game. The size of this image is the same of the render window. I don´t use all the rectangle of the image for the HUD, because the central area of the image must be transparent in order to let seeing the geme´s action.

Well, I use the irr::video::IVideoDriver::makeColorKeyTexture to make the central part of the image transparent. The problem is that when I run the program, the "transparent" area is not transparent, but black :!: . So of course, it's not possible view the action located at the background. The code I use is like this:

Code: Select all

rect<s32> rectangle = rect<s32>(0,0,640,480);

IGUIImage* pImage = m_pGui->addImage(rectangle,NULL,imageID);
if (pImage == NULL)
	return false;
	
ITexture *pTexture = m_pDriver->getTexture("HUD.jpg");
if (pTexture == NULL)
	return false;

SColor keyColor = SColor(255,255,255,255);
m_pDriver->makeColorKeyTexture(pTexture,keyColor);

pImage->setImage(pTexture);

return true;
Where is the mistake? Can anybody help me? Thx :D
"There's always a way, if desire meets courage"
Conan of Cimmeria
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Well, if I remember right, the transparent color is choosen from the first pixel of the bitmap (top left corner)...
There is a function to point on other coordinates to change these...

Maybe there is an explenation in the 2D-demo ???


CU, Acki
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Ryoga2k
Posts: 21
Joined: Mon May 03, 2004 6:59 pm
Location: Asturias, Spain

Post by Ryoga2k »

So the makeColorKeyTexture method doesn´t work??

Is it not supposed that the SColor I wrote means all the pixels with this color will be transparent?? :?
"There's always a way, if desire meets courage"
Conan of Cimmeria
disanti
Posts: 367
Joined: Sat Jan 17, 2004 1:36 am
Location: California, US
Contact:

Post by disanti »

I'm having the same problem right now with the same function, I don't know if it is a bug or not but it never used to happen in the older versions of Irrlicht. Sorry you are having problems with it, it is usually working perfectly.
________
Mr175
Last edited by disanti on Thu Feb 24, 2011 10:27 am, edited 1 time in total.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

I thing you should try it with the position method I told you before !!!
Use this and set the position2d coordinates to a pixel that is your transparent color !!!

m_pDriver->makeColorKeyTexture(pTexture, position2d<s32>(0,0));
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Guest

Post by Guest »

Hi there!

this code won't work either as exspected:

gui::IGUIImage*
img = guienv->addImage(core::rect<int>(10,10,910,510),0,-1,L"Test");
video::ITexture*
txt = driver->getTexture("D:\\Test.bmp");
driver->makeColorKeyTexture(txt,core::position2d<s32>(0,0));
img->setImage(txt);

1) Have somebody checked driver DX8/9, OGL, SW ??
2) In drawing Loop guienv is rendered at last ??
3) what's the background the build in skyBox ??

UH
Ryoga2k
Posts: 21
Joined: Mon May 03, 2004 6:59 pm
Location: Asturias, Spain

Post by Ryoga2k »

I´ve tried both the two makeColorKeyTexture methods (by SColor and by position2d) and either of them doesn´t work :(

In fact, using makeColorKeyTexture(ITexture*,position2d<s32>), I obtained different results changing the drivers:

- With DX8 and DX9, the "transparent" area remains with the original color of the image.
- With OpenGL and Software, the "transparent" area turn into black!! :cry:
Guest wrote:
gui::IGUIImage* img = guienv->addImage(core::rect<int>(10,10,910,510),0,-1,L"Test");
. . .
driver->makeColorKeyTexture(txt,core::position2d<s32>(0,0));
I think your code doesn´t work anyway because your image begins at (10,0) and you pick the colorKey at (0,0) :P
"There's always a way, if desire meets courage"
Conan of Cimmeria
Guest

Post by Guest »

OH, :oops:
havent' noticed the clipping acts on makeColorKeyTexture as well! THX!
Anyway...
That rules out guienv->addImage as HUD for a while.

What about
driver->draw2DImage( video::ITexture* texture, const core::position2d< s32 >& destPos ) ?

Depends it on camera movement and FOV?
Ryoga2k
Posts: 21
Joined: Mon May 03, 2004 6:59 pm
Location: Asturias, Spain

Post by Ryoga2k »

Yes, it seems to be a bug. I hope it to be fixed soon. :?
Guest wrote:
What about driver->draw2DImage( video::ITexture* texture, const core::position2d< s32 >& destPos ) ?
The draw2DImage(video::ITexture*,const core::position2d< s32 >&) method sholdn´t work because it just draws the image without any special effect.

I wonder if the oveloaded method draw2DImage(video::ITexture *,const core::position2d< s32 >&,const core::rect< s32 >&,const core::rect< s32 >*,SColor,bool) would work.

Would anybody be so good as to explain to me each parameter of this function? (I´m sorry but the documentation didn´t clarify it :))
"There's always a way, if desire meets courage"
Conan of Cimmeria
Guest

Post by Guest »

from here

Code: Select all

virtual void irr::video::IVideoDriver::makeColorKeyTexture 	( 	video::ITexture * 	  texture, 	
video::SColor 	  color	
) 	[pure virtual]	
  	

Creates an 1bit alpha channel of the texture based of an color key. This makes the texture transparent at the regions where this color key can be found when using for example draw2DImage with useAlphachannel = true.
so
a) do you have to alter the alpha channel ?
b) is 255 255 255 really the colour in the picture ?
c) is _all_ of the area to blank out 255 255 255 ?

and below the qupte above is :

Code: Select all

Please note that the colors of a texture may get converted when loading it, so the color values may not be exactly the same in the engine and for example in picture edit programs. To avoid this problem, you could use the makeColorKeyTexture method, which takes the position of a pixel instead a color value.
Ryoga2k
Posts: 21
Joined: Mon May 03, 2004 6:59 pm
Location: Asturias, Spain

Post by Ryoga2k »

a) do you have to alter the alpha channel ?
b) is 255 255 255 really the colour in the picture ?
c) is _all_ of the area to blank out 255 255 255 ?
Yes to all :P

Anyway, I was asking for the draw2DImage method, not makeColorKeyTexture.
"There's always a way, if desire meets courage"
Conan of Cimmeria
Post Reply