Forum

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.

Moderator: InsideQC Admins

More complex transparency

Postby behind_you » Sat Apr 30, 2011 8:45 am

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.

:?:
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya

Postby Spike » Sat Apr 30, 2011 1:01 pm

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).
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Re: More complex transparency

Postby Baker » Sun May 01, 2011 3:55 pm

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 ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby behind_you » Mon May 02, 2011 6:35 am

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
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya


Return to General Programming

Who is online

Users browsing this forum: No registered users and 1 guest