More complex transparency

Discuss programming topics for any language, any source base. If it is programming related but doesn't fit in one of the below categories, it goes here.
Post Reply
behind_you
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya

More complex transparency

Post by behind_you »

Everyone knows that alpha controls transparency. this is true both in qc and in source code. on my quest to creating a health bar instead of a damn number, i figured out that to do this, i need over 100 health lmps. so i thought, can i make a certain portion of the health bar transparent according to how much health i have? i think it's possible.

:?:
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

draw two subpics.
draw the left one X pixels wide, the right one WIDTH-X pixels wide, and offset by X pixels. make the x texture coords for both images be (WIDTH-X)/WIDTH.
X is of course health/maxhealth (clamped between 0 and 1 of the logical bar range - you may have extra padding on the edges of the image).
the the left one opaque, the right one more translucent.
Alternatively, you can just use different textures for each so the bar transitions between showing green and red (you can be more cunning and add in a yellow middle image too if you want).
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: More complex transparency

Post by Baker »

behind_you wrote: on my quest to creating a health bar instead of a damn number, i figured out that to do this, i need over 100 health lmps.
Setting the transparency desire aside, this isn't true.

Just use Draw_Fill

Code: Select all

void Draw_Fill (int x, int y, int w, int h, int c)
Without modification, the final parameter C is the color from the current palette. So with the standard Quake palette, 0 = black, 15 = white, 79 = dark red, etc.

Image

So in sbar.c you do something like ...
Draw_Fill (x, y, 80 * (float)cl.stats[STAT_HEALTH]/100 /*width varies on health*/, 8 /*height*/, 79 /* red */);
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
behind_you
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya

Post by behind_you »

hm. spike's idea is really interesting. i dont like draw_fill, baker. it's too monochromatic.

i guess it's spikes idea then. thanks u guys!

ps. is it really hard to do my transparency idea? counter strike does it, i think
Post Reply