HUD need to be transparent

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
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

HUD need to be transparent

Post by dawasw »

Hi again, ugly Dawasw here. I have this code for mine crosshair:

Code: Select all

	gui::IGUIImage *crosshair;

    rect<s32> crosshairDimensions(position2d<s32>(640/2,480/2),dimension2d<s32>(640 * 6,480 * 6));
    
	crosshair=guienv->addImage(crosshairDimensions);
    
	ITexture *tex=driver->getTexture("gui/crosshair.bmp");
    
	crosshair->setImage(tex);
Is there any way to make it a transparent image??
If not, i would like to make for example a grey rectangle and then make it transparent, maybe that will be possible ??
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Place the following line of code between your "ITexture *tex=driver->getTexture("gui/crosshair.bmp");" and "crosshair->setImage(tex);" line:

Code: Select all

driver->makeColorKeyTexture(text, position2d<s32>(0,0))
The position indicates the color that needs to be used as the transparant color. All other pixels with the same color will become transparant. Instead of using this pixel-way you could also specify the color (SColor(a,r,g,b)).
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

Hmm a bit strange, when i put this everything compiles runs its ok, but it didn't made it, i mean mine grey health indicator turned not transparent but black T_T
Brad8711

Post by Brad8711 »

thnx for the code, i will try it out. lets just hope it works. i was using the method that was used in the 2d tutorial. thnx again


Peace out :o
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

dawasw wrote:Hmm a bit strange, when i put this everything compiles runs its ok, but it didn't made it, i mean mine grey health indicator turned not transparent but black T_T
Maybe the pixel at 0,0 is black in your image. Then it would be safer to specify the transparant colour with an SColor.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

Yes , great. :D SColor . BUT HOOOWWW???!!!! give some code pleeeaassee. I dont know how to integrate it with mine crosshair code.... :cry:
brad8711

Post by brad8711 »

thnx, i tried the SColor thing but it didn't work, neither did the other one. i will play with it some more and see what i can do. aight, thnx for the help guys.

:D
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Make sure the colour is right. Check for the right values with Paint or another paint program.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
brad8711

Post by brad8711 »

:(: as soon as i insert the code i get a whole buch of undeclared identifiers.
what i'm doing is using the collision example that comes with Irrlicht. i'm sure that there is some other stuff that i'm supposed to put in to declare the things. here is the error report

Code: Select all

-------------------Configuration: collision - Win32 Debug--------------------
Compiling...
collision.cpp
C:\irrlicht-0.7\Projects\Collision\collision.cpp(245) : error C2065: 'rect' : undeclared identifier
C:\irrlicht-0.7\Projects\Collision\collision.cpp(245) : error C2275: 's32' : illegal use of this type as an expression
        c:\irrlicht-0.7\include\irrtypes.h(41) : see declaration of 's32'
C:\irrlicht-0.7\Projects\Collision\collision.cpp(245) : error C2065: 'crosshairDimensions' : undeclared identifier
C:\irrlicht-0.7\Projects\Collision\collision.cpp(245) : error C2065: 'position2d' : undeclared identifier
C:\irrlicht-0.7\Projects\Collision\collision.cpp(245) : error C2275: 's32' : illegal use of this type as an expression
        c:\irrlicht-0.7\include\irrtypes.h(41) : see declaration of 's32'
C:\irrlicht-0.7\Projects\Collision\collision.cpp(245) : error C2065: 'dimension2d' : undeclared identifier
C:\irrlicht-0.7\Projects\Collision\collision.cpp(245) : error C2275: 's32' : illegal use of this type as an expression
        c:\irrlicht-0.7\include\irrtypes.h(41) : see declaration of 's32'
C:\irrlicht-0.7\Projects\Collision\collision.cpp(246) : error C2065: 'guienv' : undeclared identifier
C:\irrlicht-0.7\Projects\Collision\collision.cpp(246) : error C2227: left of '->addImage' must point to class/struct/union
C:\irrlicht-0.7\Projects\Collision\collision.cpp(247) : error C2065: 'ITexture' : undeclared identifier
C:\irrlicht-0.7\Projects\Collision\collision.cpp(247) : error C2065: 'tex' : undeclared identifier
C:\irrlicht-0.7\Projects\Collision\collision.cpp(247) : error C2440: '=' : cannot convert from 'class irr::video::ITexture *' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\irrlicht-0.7\Projects\Collision\collision.cpp(248) : error C2065: 'image' : undeclared identifier
C:\irrlicht-0.7\Projects\Collision\collision.cpp(248) : error C2275: 's32' : illegal use of this type as an expression
        c:\irrlicht-0.7\include\irrtypes.h(41) : see declaration of 's32'
Error executing cl.exe.

collision.exe - 14 error(s), 0 warning(s)
if u can help it would be very helpful, <- LOL
Json
Posts: 5
Joined: Thu Nov 18, 2004 12:16 pm

Post by Json »

Hi!

As far as I know the keycolor method is used to specify what color in the texture that should not be drawn. If you want textures to be transparent you need to use the alphalayer of the image.

Never tried this myself but many people seem to look for how to draw HUDs and making them transparent, maybe a tutorial would be in order, anyways look at draw2DImage function.
brad8711

Post by brad8711 »

ok cool, i'm using this code now

Code: Select all

//crosshair
		gui::IGUIImage* crosshair; 
        rect<s32> crosshairDimensions(position2d<s32>(640/2,480/2),dimension2d<s32>(640 * 6,480 * 6)); 
		ITexture *images=driver->getTexture("../../media/crosshair.bmp"); 
		driver->makeColorKeyTexture(images, core::position2d<s32>(1,2));

        //drawing crosshair
        crosshair=env->addImage(crosshairDimensions);
        crosshair->setImage(images);
that is inserted into the while(device->run())
but the black part of the crosshair is black, and not transparent? why?
SARIN
Posts: 139
Joined: Fri Oct 29, 2004 3:53 am

Post by SARIN »

tada! SARIN to the RESCUE!!!!
it took me less than 5 min, so it should be simple for u guys to implement. im a newb myself.
i simply took the sample tutorial #7, but it should work with all 3d ones.
place this right before the main loop.

ITexture* images = driver->getTexture("crosshair.bmp");
driver->makeColorKeyTexture(images,position2d<s32>(0,0));

and place this after the main loop, but before endscene();

position2d<s32> m = device->getCursorControl()->getPosition();
driver->draw2DImage(images,m,
rect<s32>(0,0,16,16), 0,
SColor(100,255,255,255), true);

now, the image i had was a simple 16 by 16 .bmp image with white all around and black as a crossin the center, but u can use anything, provided that the first pixel on the top-left corner is the color u want transparent (i think, but u might wanna use white, as it wont show up anyways)
Post Reply