Tutorial *131*
Q3 style - Scaled Status Bar

This is one of those tutorials, that people either love or hate.

A scaled status bar is not something that everyone wants, but I like it, so here it is.

I know the graphics suck when large, but they can be editted by someone with the necessary inclination. I just want to add code at the moment.

In GL_SCREEN.C, find the SCR_CalcRefdef function.

A few lines from the top you will find :-



	if (scr_viewsize.value > 120)

Cvar_Set ("viewsize","120");

change this to read :-


	// muff@yakko.globalnet.co.uk - this forces full screen mode in the renderer

	if (scr_viewsize.value != 120)

Cvar_Set ("viewsize","120");

This, as the comment says, sets the screen to full screen mode. This overrides the users actions and settings.

Just below this there is a set of lines saying :-


if (size >= 120)

	sb_lines = 0;		// no status bar at all

else if (size >= 110)

	sb_lines = 24;		// no inventory

else

	sb_lines = 24+16+8;

These tell the the renderer how big the status bar is. We want this to tell it we're in full screen mode, at this point.

So change the code to say :-


	//muff@yakko.globalnet.co.uk - tells renderer no status bar to worry about

sb_lines = 0;

Now at the bottom of the routine add the following line :-


	//muff@yakko.globalnet.co.uk

	// this enables status bar, except in intermissions

if (!(cl.intermission))

	sb_lines = 24;

This tells the status bar that it is 24 lines high. The reason we do this here and not above, is that we want the renderer to go full screen, not to the top of the status bar.


Further down in GL_SCREEN.C, find the SCR_UpdateScreen routine.

Find this code :-


if (scr_drawdialog)

{

  	Sbar_Draw ();

	Draw_FadeScreen ();

	SCR_DrawNotifyString ();

	scr_copyeverything = true;

}

else if (scr_drawloading)

{

	SCR_DrawLoading ();

	Sbar_Draw ();

}

Comment out both of the Sbar_Draw() calls so that the status bar is not drawn here.

A little further down in the same routine find the code :-


SCR_DrawPause ();

SCR_CheckDrawCenterString ();

Sbar_Draw ();

SCR_DrawConsole ();

M_Draw ();

After this, add :-


// muff@yakko.globalnet.co.uk - 12 Mar 2000

// force redraw for clear status bar stuff

if (!(cl.intermission == 2 && key_dest == key_game)

	&& !(cl.intermission == 1

	&& key_dest == key_game)

	&& !(scr_drawloading)          )

	Sbar_Changed ();

This will draw the status bar if it is suitable to do so.

Now open up SBAR.C

Find the Sbar_Draw routine near the bottom.

Near the top of the routine, find the code :-


if (sb_lines && vid.width > 320)

	Draw_TileClear (0, vid.height - sb_lines, vid.width, sb_lines);

Comment these lines out. This draws the background of the status bar that we want to be transparent.

A little lower down you will find :-


else if (sb_lines)

{

	Sbar_DrawPic (0, 0, sb_sbar);

Comment out the Sbar_DrawPic line.

If you compile now, the status bar has no background, and is starting to look like what we're after.

Open up GL_DRAW.C

Find the routine Draw_Pic in the middle. After it, add the following code.


/*

=============

Draw_Pic2 - muff for scaling status bar

added 20 april 2000

=============

*/

void Draw_Pic2 (int x, int y, qpic_t *pic)

{

byte		*dest, *source;

unsigned short	*pusdest;

int		v, u;

glpic_t		*gl;

int 		pw,ph;





if (x < 0 || (unsigned)(x + pic->width) > vid.width || y < 0 ||

	 (unsigned)(y + pic->height) > vid.height)

{

	Sys_Error ("Draw_TransPic: bad coordinates");

}



if (scrap_dirty)

Scrap_Upload ();

gl = (glpic_t *)pic->data;





// first we calculate the scaling factor of the picture

pw = (pic->width)  * (vid.width /320);

ph = (pic->height) * (vid.height/200);



//now we calculate the scaled x position

x = x*(vid.width/320);

y = y*(vid.height/200);



glColor4f (1,1,1,1);

GL_Bind (gl->texnum);

glBegin (GL_QUADS);

glTexCoord2f (gl->sl, gl->tl);

glVertex2f (x, y);

glTexCoord2f (gl->sh, gl->tl);

glVertex2f (x+pw, y);

glTexCoord2f (gl->sh, gl->th);

glVertex2f (x+pw, y+ph );

glTexCoord2f (gl->sl, gl->th);

glVertex2f (x, y+ph);

glEnd ();

}

What this does is re-scale any pics relative to the current screen resolution.

Now re-open SBAR.C

Near the top you will find the routine Sbar_DrawPic. Just after it add the following new code.


/*

=============

Sbar_DrawPic2 - muff - april 20 2000 - scalable scoreboard

=============

*/

void Sbar_DrawPic2 (int x, int y, qpic_t *pic)

{

	Draw_Pic2 (x , y + (240-SBAR_HEIGHT), pic);

}

This acts as a call to the code we just added in GL_DRAW.C

In Sbar_DrawNum routine, find the line


Sbar_DrawTransPic (x,y,sb_nums[color][frame]);

and change it to :-


Sbar_DrawPic2 (x,y,sb_nums[color][frame]);

This will call our new scaling routine for all the numbers on the status bar.

Now lets do the other items on the bar.

Find the Sbar_DrawFace routine, and find the code that look like this :-


if ( (cl.items & (IT_INVISIBILITY | IT_INVULNERABILITY) )

== (IT_INVISIBILITY | IT_INVULNERABILITY) )

{

	Sbar_DrawPic2 (112, 0, sb_face_invis_invuln);

	return;

}

if (cl.items & IT_QUAD)

{

	Sbar_DrawPic2 (112, 0, sb_face_quad );

	return;

}

if (cl.items & IT_INVISIBILITY)

{

	Sbar_DrawPic2 (112, 0, sb_face_invis );

	return;

}

if (cl.items & IT_INVULNERABILITY)

{

	Sbar_DrawPic2 (112, 0, sb_face_invuln);

	return;

}

Change all the references to Sbar_DrawPic to Sbar_DrawPic2. This will scale the face during powerups as well.

At the very end of the routine change the line :-


Sbar_DrawPic (112, 0, sb_faces[f][anim]);

to :-


Sbar_DrawPic2 (112, 0, sb_faces[f][anim]);

This handles the scaling of the face animations.

In Sbar_Draw find this code :-

if (cl.items & IT_ARMOR3)

	Sbar_DrawPic (0, 0, sb_armor[2]);

else if (cl.items & IT_ARMOR2)

	Sbar_DrawPic (0, 0, sb_armor[1]);

else if (cl.items & IT_ARMOR1)

	Sbar_DrawPic (0, 0, sb_armor[0]);

Again, change all the references to Sbar_DrawPic to Sbar_DrawPic2.

Just below this you will find this code :-


if (cl.items & IT_SHELLS)

	Sbar_DrawPic (224, 0, sb_ammo[0]);

else if (cl.items & IT_NAILS)

	Sbar_DrawPic (224, 0, sb_ammo[1]);

else if (cl.items & IT_ROCKETS)

	Sbar_DrawPic (224, 0, sb_ammo[2]);

else if (cl.items & IT_CELLS)

	Sbar_DrawPic (224, 0, sb_ammo[3]);

Yet again, change all the references to Sbar_DrawPic to Sbar_DrawPic2.

Now compile this.

You should now have a scaled status bar.

The graphics leave something to be desired at this resolution, but I'm sure someone will change the graphics at some point to smooth this out (Big Hint graphics people)

Hope you enjoy the new status bar

Muff


 
Not logged in
Sign up
Login:
Passwd: