Page 1 of 1

More complex transparency

Posted: Sat Apr 30, 2011 8:45 am
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.

:?:

Posted: Sat Apr 30, 2011 1:01 pm
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).

Re: More complex transparency

Posted: Sun May 01, 2011 3:55 pm
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 */);

Posted: Mon May 02, 2011 6:35 am
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