3 cvar_t crosshair_brightness = {"crosshair_brightness", "1.0", true};
4 cvar_t crosshair_alpha = {"crosshair_alpha", "1.0", true};
5 cvar_t crosshair_flashspeed = {"crosshair_flashspeed", "2", true};
6 cvar_t crosshair_flashrange = {"crosshair_flashrange", "0.1", true};
8 #define NUMCROSSHAIRS 5
10 rtexture_t *crosshairtex[NUMCROSSHAIRS];
12 byte *crosshairtexdata[NUMCROSSHAIRS] =
100 void crosshairload(int num, byte *in)
104 for (i = 0;i < 16*16;i++)
106 data[i][0] = data[i][1] = data[i][2] = 255;
107 data[i][3] = (in[i] - '0') * 255 / 7;
109 crosshairtex[num] = R_LoadTexture(va("crosshair%02d", num), 16, 16, &data[0][0], TEXF_ALPHA | TEXF_RGBA | TEXF_PRECACHE);
112 void r_crosshairs_start()
115 for (i = 0;i < NUMCROSSHAIRS;i++)
116 crosshairload(i, crosshairtexdata[i]);
117 // crosshairtex[1] = crosshairload(crosshairtex2);
120 void r_crosshairs_shutdown()
124 void R_Crosshairs_Init()
126 Cvar_RegisterVariable(&crosshair_brightness);
127 Cvar_RegisterVariable(&crosshair_alpha);
128 Cvar_RegisterVariable(&crosshair_flashspeed);
129 Cvar_RegisterVariable(&crosshair_flashrange);
130 R_RegisterModule("R_Crosshairs", r_crosshairs_start, r_crosshairs_shutdown);
133 void DrawCrosshair(int num)
137 // Draw_Character (r_refdef.vrect.x + r_refdef.vrect.width/2, r_refdef.vrect.y + r_refdef.vrect.height/2, '+');
138 if (num < 0 || num >= NUMCROSSHAIRS)
142 int i = (cl.scores[cl.viewentity-1].colors & 0xF) << 4;
143 if (i >= 208 && i < 224) // blue
145 else if (i < 128 || i >= 224) // 128-224 are backwards ranges (bright to dark, rather than dark to bright)
147 color = (byte *) &d_8to24table[i];
150 color = (byte *) &d_8to24table[15];
151 if (crosshair_flashspeed.value >= 0.01f)
152 // scale = (sin(realtime * crosshair_flashspeed.value * (M_PI*2.0f)) * crosshair_flashrange.value + 1.0f) * (1.0f / 255.0f);
153 base = (sin(realtime * crosshair_flashspeed.value * (M_PI*2.0f)) * crosshair_flashrange.value);
156 scale = crosshair_brightness.value / 255.0f;
157 Draw_GenericPic(crosshairtex[num], color[0] * scale + base, color[1] * scale + base, color[2] * scale + base, crosshair_alpha.value, r_refdef.vrect.x + r_refdef.vrect.width * 0.5f - 8.0f, r_refdef.vrect.y + r_refdef.vrect.height * 0.5f - 8.0f, 16.0f, 16.0f);