Draw2DImage Elaboration

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
matticusrex
Posts: 6
Joined: Tue Apr 29, 2008 6:45 pm

Draw2DImage Elaboration

Post by matticusrex »

I've been using Irrlicht for a while now making 2D games, and I was wondering if anyone would help me out and elaborate on the different draw 2d image functions.

Code: Select all

draw2DImage (const video::ITexture *texture, const core::position2d< s32 > &destPos, const core::rect< s32 > &sourceRect, const core::rect< s32 > *clipRect=0, SColor color=SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture=false)=0
This is the function I use mostly. The values in question are the 4th and 5th args. (I think) I understand that the clip rect makes part of the image not draw, and assume that the color is supposed to change the color of the image in some way in terms of (R, G, B, A), but I can't make heads or tails of either of these (i've implemented them both a couple ways).

I'm making a top-down tank fighting game and I want to use one texture and draw it using different colors. Also, I want to draw a circular health bar on top of my tank and have it disappear as the player takes damage (change the size of the clip rect based on health pct).

Code: Select all

draw2DImage (const video::ITexture *texture, const core::position2d< s32 > &pos, const core::array< core::rect< s32 > > &sourceRects, const core::array< s32 > &indices, s32 kerningWidth=0, const core::rect< s32 > *clipRect=0, SColor color=SColor(255, 255, 255, 255), bool useAlphaChannelOfTexture=false)=0
This one has the same args as the last, with a few changes. I'm assuming it is used to do animation in some way. It takes an array of source rects. I've never used it, what are the indices and kerningWidth args used for?

Finally:

Code: Select all

draw2DImage (const video::ITexture *texture, const core::rect< s32 > &destRect, const core::rect< s32 > &sourceRect, const core::rect< s32 > *clipRect=0, video::SColor *colors=0, bool useAlphaChannelOfTexture=false)=0
This one takes an array of 4 colors. What's that all about?

It looks like the draw2DImage function has a lot of different uses, and I would like to tap into these, but I don't quite understand all of what is going on. Any clarification would be greatly helpful, in exchange I'll add anything I find useful to the wiki.

Thanks!
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I would suggest reading the documentation whenever you want to learn more about a function...
Image Image Image
matticusrex
Posts: 6
Joined: Tue Apr 29, 2008 6:45 pm

Post by matticusrex »

Thank you for your informative response, maybe it could be accompanied by an actual link to this magical documentation. Obviously I know where to find the function in the API since I quoted it, and if there is more documentation than that then I'm not aware of it.

I try to phrase my post in an intelligent manner, asking specifically for the things I don't know, providing background information, etc. I even offered to immortalize your knowledge in the wiki. The least you could do is a) provide thoughtful answers, or b) don't respond if you don't have anything constructive to give me.

Is this an unreasonable request?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The API docs are linked from the Irrlicht homepage, and also are available in the SDK (as .chm file) and as a printable manual from SourceForge downloads. The parameters are explained there, but also in the Irrlicht engine code (in the interface headers).
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

http://irrlicht.sourceforge.net/docu/index.html

That documentation is created automagically from the comments in the source, and patches to improve the commenting would be great.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
matticusrex
Posts: 6
Joined: Tue Apr 29, 2008 6:45 pm

Post by matticusrex »

I appreciate your replies, and apologize for being snappy earlier, but you still aren't addressing my questions. More specifically:

I'm making a top-down 2D game, I want to add a health bar that is a circle around my player object. As the player loses health, the circle disappears from top to bottom, which I believe can be done with a clipping rectangle with a variable Y dimension based on the health:

Code: Select all

	screenPos.UpperLeftCorner=core::position2d<s32>(posX-16, posY-16);
	screenPos.LowerRightCorner=core::position2d<s32>(posX+16, posY+16);

	healthBarClip.UpperLeftCorner=screenPos.UpperLeftCorner;
	healthBarClip.LowerRightCorner.X = screenPos.UpperLeftCorner.X+32;
	healthBarClip.LowerRightCorner.Y = screenPos.UpperLeftCorner.Y+(32-(int)(32*healthPct));

	driver->draw2DImage(source, screenPos, sourceRect, 0, 0, true);
	driver->draw2DImage(health, screenPos, healthBarSource, &healthBarClip, 0, true);
The health bar draws fine, but when the clip rect size is increased, none of the health bar disappears.

I think I can figure out the color stuff on my own with some more playing around, and reading the source helped answer my questions about the overload with an array of sourceRects.
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

I understand what you are trying to accomplish, but why are you using the draw 2d image clip rect functionality when (based on my own experience) i have just drawn this following :

[______________________]

^^ width = 100 right ? Now if i draw an image at width 60 :

[_____________

It clips it anyway (there may be a flag to set about scaling).

This is how i normally do it, although i dont normally use an image, i would prefer to draw an image with alpha OVER a drawn rectangle.

So drawing a rectangle (at a color of choice) UNDER an image with some parts "showing through" will save on texture memory, and most likely drawing a rectangle 'costs" less then an image.

If you need an example, i can probably show you in one of my older games. For now, try the above?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

matticusrex wrote:I appreciate your replies, and apologize for being snappy earlier, but you still aren't addressing my questions.
To be honest, the reason for that is that (without looking at the code, which you also have available) I simply don't know for sure.

Since Irrlicht relies on contributions from parties who are interested in specific areas, it would be great if you could help us to understand what all the 2D methods do. ;)
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

If you're using DirectX as your driver then the clip rectangle gets ignored. So try using OpenGL and it should work. It's annoying but should be fixed in irrlicht 1.5!
Image Image Image
Post Reply