Tutorial *116*
This tutorial will show you how to get that nifty crosshair from QuakeWorld when you type "Crosshair 2" in Normal Quake.

In draw.h under



void Draw_String (int x, int y, char *str);

Add


void Draw_Crosshair(void);

In view.c near top in below


cvar_t	crosshair = {"crosshair", "0", true};

add


cvar_t	crosshaircolor = {"crosshaircolor", "79", true};

at the bottom below


	Cvar_RegisterVariable (&crosshair);

add


	Cvar_RegisterVariable (&crosshaircolor);

For glquake:
In gl_draw.c

Among the variable declartions at the top (under int char_texture for example) add:



int			cs_texture;

static byte cs_data[64] = {

	0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff,

	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,

	0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff,

	0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff,

	0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff,

	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,

	0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff,

	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff

};



extern cvar_t crosshair, cl_crossx, cl_crossy, crosshaircolor;

Note:0xfe=a pixel, 0xff = no pixel, so u can edit the x-hair here. Find the Draw_Init function, and below the line:


char_texture = GL_LoadTexture ("charset", 128, 128, draw_chars, false, true);

add


cs_texture = GL_LoadTexture ("crosshair", 8, 8, cs_data, false, true);

Now add this function below the Draw_debugchar function:


void Draw_Crosshair(void)

{

	int x, y;

	extern vrect_t		scr_vrect;

	unsigned char *pColor;



	if (crosshair.value == 2) {

		x = scr_vrect.x + scr_vrect.width/2 + 1  + cl_crossx.value;

		y = scr_vrect.y + scr_vrect.height/2  + cl_crossy.value;



		glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

		pColor = (unsigned char *) &d_8to24table[(byte) crosshaircolor.value];

		glColor4ubv ( pColor );

		GL_Bind (cs_texture);



		glBegin (GL_QUADS);

		glTexCoord2f (0, 0);

		glVertex2f (x - 4, y - 4);

		glTexCoord2f (1, 0);

		glVertex2f (x+12, y-4);

		glTexCoord2f (1, 1);

		glVertex2f (x+12, y+12);

		glTexCoord2f (0, 1);

		glVertex2f (x - 4, y+12);

		glEnd ();



		glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );

	}

else if (crosshair.value)

Draw_Character (scr_vrect.x + scr_vrect.width/2 + cl_crossx.value, scr_vrect.y + scr_vrect.height/2 + cl_crossy.value, '+');

}

Now open gl_screen.c

Right at the bottom find



if (crosshair.value)

	Draw_Character (scr_vrect.x + scr_vrect.width/2, scr_vrect.y + scr_vrect.height/2, '+');

Comment out Draw_character call, and put Draw_Crosshair instead so it looks like this:


if (crosshair.value)

	Draw_Crosshair();

	//Draw_Character (scr_vrect.x + scr_vrect.width/2, scr_vrect.y + scr_vrect.height/2, '+');

That's it for GL.

For software rendering open draw.c. Under the Draw_String function add these functions



void Draw_Pixel(int x, int y, byte color)

{

	byte			*dest;

	unsigned short	*pusdest;



	if (r_pixbytes == 1)

	{

		dest = vid.conbuffer + y*vid.conrowbytes + x;

		*dest = color;

	}

	else

	{

	// FIXME: pre-expand to native format?

		pusdest = (unsigned short *)

		((byte *)vid.conbuffer + y*vid.conrowbytes + (x<<1));

		*pusdest = d_8to16table[color];

	}

}







void Draw_Crosshair(void)

{

	int x, y;

	extern cvar_t crosshair, cl_crossx, cl_crossy, crosshaircolor;

	extern vrect_t		scr_vrect;

	byte c = (byte)crosshaircolor.value;



	if (crosshair.value == 2) {

		x = scr_vrect.x + scr_vrect.width/2 + cl_crossx.value;

		y = scr_vrect.y + scr_vrect.height/2 + cl_crossy.value;

		Draw_Pixel(x - 1, y, c);

		Draw_Pixel(x - 3, y, c);

		Draw_Pixel(x + 1, y, c);

		Draw_Pixel(x + 3, y, c);

		Draw_Pixel(x, y - 1, c);

		Draw_Pixel(x, y - 3, c);

		Draw_Pixel(x, y + 1, c);

		Draw_Pixel(x, y + 3, c);

	} else if (crosshair.value)

		Draw_Character (

			scr_vrect.x + scr_vrect.width/2 + cl_crossx.value,

			scr_vrect.y + scr_vrect.height/2 + cl_crossy.value,

			'+');

}

Open view.c again, find this bit (near bottom)


#ifndef GLQUAKE

if (crosshair.value)

	Draw_Character (scr_vrect.x + scr_vrect.width/2 + cl_crossx.value, scr_vrect.y + scr_vrect.height/2 + cl_crossy.value, '+');

#endif

Comment out Draw_Character, and put Draw_Crosshair in instead so it looks like :


#ifndef GLQUAKE

if (crosshair.value)

	Draw_Crosshair();

	//Draw_Character (scr_vrect.x + scr_vrect.width/2 + cl_crossx.value, scr_vrect.y + scr_vrect.height/2 + cl_crossy.value, '+');

#endif

Well, there you have it!


 
Not logged in
Sign up
Login:
Passwd: