drawing 2d rectangles

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
me_go_fast
Posts: 8
Joined: Fri Jul 23, 2004 2:45 am
Location: Untied States

drawing 2d rectangles

Post by me_go_fast »

I want to use a 2d rectangle as a health bar in game. But when i try to draw a 2d rectangle it doesn't sahow up in game. Here is the code i use:

while(SPDevice->run() && Sdriver)
{
Sdriver->beginScene(true, true, video::SColor(0,100,100,100));
smgr->drawAll();
env->drawAll();
core::position2d<s32> m = SPDevice->getCursorControl()->getPosition();
Sdriver->draw2DRectangle(SColor(0,100,100,100),rect<s32>(50,50,25,25), 0);
Sdriver->draw2DImage(texture, core::position2d<s32>(m.X - 12,m.Y - 12), rect<s32>(0,0,25,25), 0, video::SColor(255,255,255,255), true);
Sdriver->endScene();
}
SPDevice->drop();


If you can help me it would be appreciated. This is probably small mistake that i made but i can't find it! :(
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

SColor(0,100,100,100) is wrong. You set the alpha-value (first value) to 0 which means no visibility. Set it to 255 for full opacity.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
StargateSG1
Posts: 15
Joined: Sun Aug 22, 2004 2:06 pm
Location: Estonia

Post by StargateSG1 »

However the documentation says for SColor() alpha value that:

The alpha component defines how transparent a color should be. 0 means not transparent(so it's opque and is fully seen on screen), 255 means fully transparent(unseen).

Are the docs lieing :roll:
melon

Re: drawing 2d rectangles

Post by melon »

me_go_fast wrote:
Sdriver->draw2DRectangle(SColor(0,100,100,100),rect<s32>(50,50,25,25), 0);
Sdriver->draw2DImage(texture, core::position2d<s32>(m.X - 12,m.Y - 12), rect<s32>(0,0,25,25), 0, video::SColor(255,255,255,255), true);
Sdriver->endScene();
}


it seems that you replaced values inf rect<s32>. if you'll put (25,25,50,50) instead it will probably be OK.
also, as far as I remeber SColor(255, 255, 255, 255) if fully white and opaque, so that's probably good choice for testing.

greetz
natol
Posts: 25
Joined: Fri Aug 13, 2004 5:12 pm
Location: USA, KS

Post by natol »

I tried using just the 2D rectangle and it seems that the rectangle is showing up behind the 3d Scene....

So if I have a simple plane with some stuff on it , the rectangle shows up behind the 3D objects....
driver->draw2DRectangle(SColor(100,255,255,255),rect<s32>(10,10,240,60),0);
Here's my code if I change the size of the object to be towards the middle of the screen it shows me that the rectangle is behind the 3d Objects...

Weird????
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

this looks like a bug to me...

smgr->drawAll();
env->drawAll();
Sdriver->draw2DRectangle(SColor(0,100,100,100),rect<s32>(50,50,25,25), 0);


take me lightly... in my program I have that minus the smgr which is what 3d?

ok so the solution seems to put the rectangle before you draw the smgr.. but doesn't env-> have to be before rectangle and after smgr?

you have all officially confused me.
Post Reply