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); void Draw_Crosshair(void); cvar_t crosshair = {"crosshair", "0", true}; cvar_t crosshaircolor = {"crosshaircolor", "79", true}; Cvar_RegisterVariable (&crosshair); Cvar_RegisterVariable (&crosshaircolor); 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; char_texture = GL_LoadTexture ("charset", 128, 128, draw_chars, false, true); cs_texture = GL_LoadTexture ("crosshair", 8, 8, cs_data, false, true); 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, '+'); } Right at the bottom find if (crosshair.value) Draw_Character (scr_vrect.x + scr_vrect.width/2, scr_vrect.y + scr_vrect.height/2, '+'); if (crosshair.value) Draw_Crosshair(); //Draw_Character (scr_vrect.x + scr_vrect.width/2, scr_vrect.y + scr_vrect.height/2, '+'); 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, '+'); } #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 #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 |