Forum

csqc hud positioning

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

csqc hud positioning

Postby ceriux » Sat Mar 14, 2009 9:20 pm

nvm im wrong i guess - the parts in orange edit with a number below 1 "0.6" ect.


sorry got it ill post an explaination at the bottom for others to use



hey, im fairly new to qc, but im able to do that to and extent but iv tried picking up csqc and still learning on it. anyways im having issues positioning my hud that daemon has helped me with.

here's what i got so far.


void DrawHealth()

{
local string text;


vid_size_x = cvar("vid_conwidth");
vid_size_y = cvar("vid_conheight");
vid_res_x = cvar("vid_width");
vid_res_y = cvar("vid_height");

currenthealth = getstati(STAT_HEALTH);

//maxhealth = getstati(STAT_CELLS);

//drawstring(position, "string", fontsize, color, alpha, drawflags);
//drawline(float width, vector pos1, vector pos2, vector rgb, float alpha, float flags) = #315;

pos_x = vid_size_x*0.5 - hud_width*0.5;

text = strcat(ftos(currenthealth), ": HEALTH");

//text = strcat(text, ftos(maxhealth));

//drawline(1 1 1, 0, 1,'1 1 1', 0, 0);


drawstring(pos, text, '8 8 0', '0 2 2', 3, 0);








};



void DrawArmor()

{
local string text;


vid_size_x = cvar("vid_conwidth");
vid_size_y = cvar("vid_conheight");
vid_res_x = cvar("vid_width");
vid_res_y = cvar("vid_height");

currenthealth = getstati(STAT_ARMOR);

//maxhealth = getstati(STAT_CELLS);

//drawstring(position, "string", fontsize, color, alpha, drawflags);
//drawline(float width, vector pos1, vector pos2, vector rgb, float alpha, float flags) = #315;

pos_x = vid_size_x*0.5 - hud_width*0.5;

text = strcat(ftos(currenthealth), ": Armor");

//text = strcat(text, ftos(maxhealth));

//drawline(1 1 1, 0, 1,'1 1 1', 0, 0);


drawstring(pos, text, '8 8 0', '0 2 2', 3, 0);








};



its basic, but its good enough for what i want to start.




this is the code that u alter 0 equals top left of the screen


vid_size_x = cvar("vid_conwidth");
vid_size_y = cvar("vid_conheight");
vid_res_x = cvar("vid_width");
vid_res_y = cvar("vid_height");



Pic of my hud :D

Image
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby ceriux » Sun Mar 15, 2009 5:25 am

(sorry for double post getting no help on irc)

anyways.

this is the hud pic iv made so far. i want to draw pic it behind my text.
im having issues figuring it out anyone mind helping?

(i can move my text display to fit the hud)

Image
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby xaGe » Tue Mar 17, 2009 4:04 am

..Hey good start with your csqc hud.. I wish I had the time and grey matter to mess with csqc to get even the results you have so far. :)
User avatar
xaGe
 
Posts: 461
Joined: Wed Mar 01, 2006 8:29 am
Location: Upstate, New York

Postby ceriux » Tue Mar 17, 2009 4:13 am

its not really that hard as what i thought it would be (mind its basic) but in this case, basic is all i need. i can post up the whole code with some explainations. kinda like a mini tutorial hey! ill write submit a tutorial on how to make a basic csqc HUD! right now before i go to bed :D

"forgot to mention i wouldnt have gotten this far if it was for those on irc, (im stoned a lot sorry i dont remember your name 'minus daemon'.) so please if you helped me and want the credit please post your name here when u see this :D!
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby xaGe » Tue Mar 17, 2009 5:02 am

..Yes daemon seems pretty good with csqc code in the projects of his I've seen/played in... A mini tut on what you did would be super for others looking to see the basics you got working ceriux.
User avatar
xaGe
 
Posts: 461
Joined: Wed Mar 01, 2006 8:29 am
Location: Upstate, New York

Postby ceriux » Tue Mar 17, 2009 5:07 am

what im working on now.

edit: i submitted my tutorial, it shows how to make a better looking version of the hud i drew up recently. though some of the effects are from the alpha channel included with the hud tga in the tutorial.
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby ceriux » Fri Apr 03, 2009 6:27 pm

in my tutorial if you cant find the hud files they've been relocated here. http://www.quaketastic.com/upload/files/misc/hud4.zip
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby worldspawn » Sun Sep 27, 2009 10:27 pm

http://inside3d.com/showtutorial.php?id=245


There's a few backslashes kicking around in your functions rendering code that prevents a clean compile.

Not sure if that was intentional but whatever, it should look as follows:


Code: Select all
void DrawHealth()
{
   local string text;
   
   vid_size_x = cvar("vid_conwidth");
   vid_size_y = cvar("vid_conheight");
   vid_res_x = cvar("vid_width");
   vid_res_y = cvar("vid_height");
   
   currenthealth = getstati(STAT_HEALTH);
   
   pos_x = vid_size_x*0.050 - hud_width*0.050;
   pos_y= vid_size_y*0.83 - hud_height*0.83;
   
   text = strcat(ftos(currenthealth), ": HEALTH");
   drawstring(pos, text, '10 10 0', '1 1 1', 3, 1);
};

void DrawArmor()
{
   local string text;
   
   vid_size_x = cvar("vid_conwidth");
   vid_size_y = cvar("vid_conheight");
   vid_res_x = cvar("vid_width");
   vid_res_y = cvar("vid_height");
   
   currentarmor = getstati(STAT_ARMOR);

   pos_x = vid_size_x*0.05 - hud_width*0.05;
   pos_y= vid_size_y*0.85 - hud_height*0.85;

   text = strcat(ftos(currentarmor), ": ARMOR");
   drawstring(pos, text, '10 10 0', '1 1 1', 3, 1);
};


void DrawHud()
{
   vid_size_x = cvar("vid_conwidth");
   vid_size_y = cvar("vid_conheight");
   vid_res_x = cvar("vid_width");
   vid_res_y = cvar("vid_height");'

   pos2_y= vid_size_y*0.77 - hud_height*0.77;
   pos2_x = vid_size_x*0.0 - hud_width*0.0;

   drawpic(pos2, "progs/hud4.tga", '128 110 0', '1 1 1', 1, 0);
};
worldspawn
 
Posts: 27
Joined: Tue Dec 02, 2008 11:44 pm

Postby Spike » Sun Sep 27, 2009 11:57 pm

querying vid_conwidth and vid_conheight every frame multiple times a frame is horrible.
instead, you ought to utilize the arguments to your CSQC_UpdateView for those two vars, and basically pass them through to child functions.

you also don't even use vid_width, and nor should you really. they can very very easily be stale, invalid, etc.

quake doesn't normally scale its hud, depending upon the -conwidth argument in glquake to rescale.
that is the following two lines is generally enough to draw items to match quake. Insert the proper variables and you have an item drawn in a virtual hud.
vector sbarpos = (vid_width-sbar_width)*'0.5 0 0' + (vid_height-sbar_height)*'0 1 0';
drawpic(mypic, sbarpos + item_offset, item_size, '1 1 1', 1, 0);
sbarpos is of course the top left of your hud area, which can be passed around to the various functions that form your hud.

You can scale your hud, but beware widescreens! It can pay to use a hybrid aproach to scaling your hud if you choose to do that. Scale based on the smaller axis (relative to 4:3 anyway), and center on the other. This gives a single float scaler which can be used to multiply item_size without dotproduct semantics (basically multiply sbar_width, sbar_height, item_offset, and item_size by that scaler. Thus:
float hudscale = (vid_width*3 > vid_height*4)?((vid_width*3)/(vid_height*4)):((vid_height*4)/(vid_width*3));
vector sbarpos = (vid_width-sbar_width*hudscale)*'0.5 0 0' + (vid_height-sbar_height*hudscale)*'0 1 0';
drawpic(mypic, sbarpos + item_offset*hudscale, item_size*hudscale, '1 1 1', 1, 0);
or so.
Actually, I'm not certain about that hudscale line. But you get the idea. Of course, you might need art to cover the fact that there might be gaps each side of the hud when it is wide.
Side note: halflife has separate artwork for 320+ and 640+ :)

also, be cautious about strings that are not scaled 8*8, they can scale badly, depending on the user's raster font. The same applies to images, but its less noticable thus less important.

It annoys me that there is no componant-based vector multiply in QC.


Your mileage may vary.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest