-refdef_t r_refdef;
-
-mleaf_t *r_viewleaf, *r_oldviewleaf;
-
-texture_t *r_notexture_mip;
-
-int d_lightstylevalue[256]; // 8.8 fraction of base light value
-
-
-void R_MarkLeaves (void);
-
-//cvar_t r_norefresh = {"r_norefresh","0"};
-cvar_t r_drawentities = {"r_drawentities","1"};
-cvar_t r_drawviewmodel = {"r_drawviewmodel","1"};
-cvar_t r_speeds = {"r_speeds","0"};
-cvar_t r_speeds2 = {"r_speeds2","0"};
-cvar_t r_fullbright = {"r_fullbright","0"};
-//cvar_t r_lightmap = {"r_lightmap","0"};
-//cvar_t r_shadows = {"r_shadows","0"};
-cvar_t r_wateralpha = {"r_wateralpha","1"};
-//cvar_t r_dynamic = {"r_dynamic","1"};
-cvar_t r_novis = {"r_novis","0"};
-cvar_t r_waterripple = {"r_waterripple","0"};
-cvar_t r_fullbrights = {"r_fullbrights", "1"};
-
-//cvar_t gl_cull = {"gl_cull","1"};
-//cvar_t gl_affinemodels = {"gl_affinemodels","0"};
-//cvar_t gl_polyblend = {"gl_polyblend","1"};
-//cvar_t gl_flashblend = {"gl_flashblend","0"};
-cvar_t gl_playermip = {"gl_playermip","0"};
-//cvar_t gl_nocolors = {"gl_nocolors","0"};
-//cvar_t gl_keeptjunctions = {"gl_keeptjunctions","1"};
-//cvar_t gl_reporttjunctions = {"gl_reporttjunctions","0"};
-cvar_t contrast = {"contrast", "1.0", TRUE}; // LordHavoc: a method of operating system independent color correction
-cvar_t brightness = {"brightness", "1.0", TRUE}; // LordHavoc: a method of operating system independent color correction
-cvar_t gl_lightmode = {"gl_lightmode", "1", TRUE}; // LordHavoc: overbright lighting
-//cvar_t r_particles = {"r_particles", "1"};
-//cvar_t r_dynamicwater = {"r_dynamicwater", "1"};
-//cvar_t r_smokealpha = {"r_smokealpha", "0.25"};
-//cvar_t r_dynamicbothsides = {"r_dynamicbothsides", "1"}; // LordHavoc: can disable dynamic lighting of backfaces, but quake maps are weird so it doesn't always work right...
-
-cvar_t r_fogdensity = {"r_fogdensity", "0"};
-cvar_t r_fogred = {"r_fogred","0.3"};
-cvar_t r_foggreen = {"r_foggreen","0.3"};
-cvar_t r_fogblue = {"r_fogblue","0.3"};
-
-cvar_t gl_fogenable = {"gl_fogenable", "0"};
-cvar_t gl_fogdensity = {"gl_fogdensity", "0.25"};
-cvar_t gl_fogred = {"gl_fogred","0.3"};
-cvar_t gl_foggreen = {"gl_foggreen","0.3"};
-cvar_t gl_fogblue = {"gl_fogblue","0.3"};
-cvar_t gl_fogstart = {"gl_fogstart", "0"};
-cvar_t gl_fogend = {"gl_fogend","0"};
-
-int chrometexture;
-
-void makechrometextures()
+refdef_t r_refdef;
+
+// 8.8 fraction of base light value
+unsigned short d_lightstylevalue[256];
+
+cvar_t r_drawentities = {0, "r_drawentities","1"};
+cvar_t r_drawviewmodel = {0, "r_drawviewmodel","1"};
+cvar_t r_shadows = {CVAR_SAVE, "r_shadows", "1"};
+cvar_t r_shadow_staticworldlights = {0, "r_shadow_staticworldlights", "1"};
+cvar_t r_speeds = {0, "r_speeds","0"};
+cvar_t r_fullbright = {0, "r_fullbright","0"};
+cvar_t r_wateralpha = {CVAR_SAVE, "r_wateralpha","1"};
+cvar_t r_dynamic = {CVAR_SAVE, "r_dynamic","1"};
+cvar_t r_fullbrights = {CVAR_SAVE, "r_fullbrights", "1"};
+
+cvar_t gl_fogenable = {0, "gl_fogenable", "0"};
+cvar_t gl_fogdensity = {0, "gl_fogdensity", "0.25"};
+cvar_t gl_fogred = {0, "gl_fogred","0.3"};
+cvar_t gl_foggreen = {0, "gl_foggreen","0.3"};
+cvar_t gl_fogblue = {0, "gl_fogblue","0.3"};
+cvar_t gl_fogstart = {0, "gl_fogstart", "0"};
+cvar_t gl_fogend = {0, "gl_fogend","0"};
+
+cvar_t r_textureunits = {0, "r_textureunits", "32"};
+
+void R_ModulateColors(float *in, float *out, int verts, float r, float g, float b)