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.
More complex transparency
-
- Posts: 237
- Joined: Sat Feb 05, 2011 6:57 am
- Location: Tripoli, Libya
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).
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
Setting the transparency desire aside, this isn't true.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.
Just use Draw_Fill
Code: Select all
void Draw_Fill (int x, int y, int w, int h, int c)
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? Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
-
- Posts: 237
- Joined: Sat Feb 05, 2011 6:57 am
- Location: Tripoli, Libya