updated to version 1.50, build 75.
[divverent/darkplaces.git] / r_crosshairs.c
1 #include "quakedef.h"
2
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};
7
8 #define NUMCROSSHAIRS 1
9
10 int crosshairtex[NUMCROSSHAIRS];
11
12 char crosshairtex1[16*16] =
13         "0000000000000000"
14         "0000000000000000"
15         "0000000000000000"
16         "0003000000003000"
17         "0000500000050000"
18         "0000070000700000"
19         "0000007007000000"
20         "0000000000000000"
21         "0000000000000000"
22         "0000007007000000"
23         "0000070000700000"
24         "0000500000050000"
25         "0003000000003000"
26         "0000000000000000"
27         "0000000000000000"
28         "0000000000000000"
29 ;
30
31 void r_crosshairs_start()
32 {
33         int i;
34         byte data[64*64][4];
35         for (i = 0;i < 16*16;i++)
36         {
37                 data[i][0] = data[i][1] = data[i][2] = 255;
38                 data[i][3] = (crosshairtex1[i] - '0') * 255 / 7;
39         }
40         crosshairtex[0] = GL_LoadTexture("crosshair0", 16, 16, &data[0][0], false, true, 4);
41 }
42
43 void r_crosshairs_shutdown()
44 {
45 }
46
47 void R_Crosshairs_Init()
48 {
49         Cvar_RegisterVariable(&crosshair_brightness);
50         Cvar_RegisterVariable(&crosshair_alpha);
51         Cvar_RegisterVariable(&crosshair_flashspeed);
52         Cvar_RegisterVariable(&crosshair_flashrange);
53         R_RegisterModule("R_Crosshairs", r_crosshairs_start, r_crosshairs_shutdown);
54 }
55
56 void DrawCrosshair(int num)
57 {
58         byte *color;
59         float scale, base;
60 //      Draw_Character (r_refdef.vrect.x + r_refdef.vrect.width/2, r_refdef.vrect.y + r_refdef.vrect.height/2, '+');
61         if (num < 0 || num >= NUMCROSSHAIRS)
62                 num = 0;
63         if (cl.viewentity)
64         {
65                 int i = (cl.scores[cl.viewentity-1].colors & 0xF) << 4;
66                 if (i >= 208 && i < 224) // blue
67                         i += 8;
68                 else if (i < 128 || i >= 224) // 128-224 are backwards ranges (bright to dark, rather than dark to bright)
69                         i += 15;
70                 color = (byte *) &d_8to24table[i];
71         }
72         else
73                 color = (byte *) &d_8to24table[15];
74         if (crosshair_flashspeed.value >= 0.01f)
75 //              scale = (sin(realtime * crosshair_flashspeed.value * (M_PI*2.0f)) * crosshair_flashrange.value + 1.0f) * (1.0f / 255.0f);
76                 base = (sin(realtime * crosshair_flashspeed.value * (M_PI*2.0f)) * crosshair_flashrange.value);
77         else
78                 base = 0.0f;
79         scale = crosshair_brightness.value / 255.0f;
80         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);
81 }
82