diff --git a/nq/include/client.h b/nq/include/client.h
index 1a03cd901..7827a0879 100644
--- a/nq/include/client.h
+++ b/nq/include/client.h
@@ -272,6 +272,7 @@ extern cvar_t	*m_yaw;
 extern cvar_t	*m_forward;
 extern cvar_t	*m_side;
 
+extern struct cvar_s *name;
 
 #define	MAX_TEMP_ENTITIES	64			// lightning bolts, etc
 #define	MAX_STATIC_ENTITIES	128			// torches, etc
diff --git a/nq/source/Makefile.am b/nq/source/Makefile.am
index a8a9290f6..760df7aa5 100644
--- a/nq/source/Makefile.am
+++ b/nq/source/Makefile.am
@@ -123,7 +123,7 @@ nq_x11_DEPENDENCIES=$(client_LIB_DEPS)
 ogl_SOURCES=	noisetextures.c gl_textures.c gl_draw.c gl_dyn_fires.c	\
 		gl_dyn_part.c gl_dyn_textures.c \
 		gl_rlight.c gl_rmain.c gl_rmisc.c gl_rsurf.c \
-		gl_screen.c gl_sky.c gl_sky_clip gl_view.c gl_warp.c
+		gl_screen.c gl_sky.c gl_sky_clip.c gl_view.c gl_warp.c
 
 # ... 3Dfx Voodoo 1 and 2 SVGAlib-based console GL
 nq_3dfx_SOURCES=	$(combined_SOURCES) $(ogl_SOURCES)
diff --git a/nq/source/gl_rlight.c b/nq/source/gl_rlight.c
index 5540325d4..07eefd2e5 100644
--- a/nq/source/gl_rlight.c
+++ b/nq/source/gl_rlight.c
@@ -43,8 +43,6 @@
 #include "glquake.h"
 #include "r_shared.h"
 
-int         r_dlightframecount;
-
 /*
 	R_AnimateLight
 */
@@ -121,7 +119,6 @@ R_RenderDlight (dlight_t *light)
 
 	VectorSubtract (light->origin, r_origin, v);
 	if (Length (v) < rad) {				// view is inside the dlight
-		AddLightBlend (1, 0.5, 0, light->radius * 0.0003);
 		return;
 	}
 
@@ -163,14 +160,11 @@ R_RenderDlights (void)
 	int         i;
 	dlight_t   *l;
 
-	if (!gl_flashblend->int_val)
+	if (!gl_dlight_polyblend->int_val)
 		return;
 
-	r_dlightframecount = r_framecount + 1;	// because the count hasn't
-	// advanced yet for this frame
 	glDepthMask (GL_FALSE);
 	glDisable (GL_TEXTURE_2D);
-	glEnable (GL_BLEND);
 	glBlendFunc (GL_ONE, GL_ONE);
 	glShadeModel (GL_SMOOTH);
 
@@ -181,8 +175,9 @@ R_RenderDlights (void)
 		R_RenderDlight (l);
 	}
 
-	glColor3f (1, 1, 1);
-	glDisable (GL_BLEND);
+	if (!gl_dlight_smooth->int_val)
+		glShadeModel (GL_FLAT);
+	glColor3ubv (lighthalf_v);
 	glEnable (GL_TEXTURE_2D);
 	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 	glDepthMask (GL_TRUE);
@@ -298,11 +293,9 @@ R_PushDlights (vec3_t entorigin)
 	dlight_t   *l;
 	vec3_t      lightorigin;
 
-	if (gl_flashblend->int_val)
+	if (!gl_dlight_lightmap->int_val)
 		return;
 
-	r_dlightframecount = r_framecount + 1;	// because the count hasn't
-	// advanced yet for this frame
 	l = cl_dlights;
 
 	for (i = 0; i < MAX_DLIGHTS; i++, l++) {
diff --git a/nq/source/gl_rmain.c b/nq/source/gl_rmain.c
index 4901c4b88..2c664562f 100644
--- a/nq/source/gl_rmain.c
+++ b/nq/source/gl_rmain.c
@@ -50,8 +50,10 @@
 #include "chase.h"
 #include "game.h"
 #include "glquake.h"
-#include "render.h"
+#include "r_cvar.h"
 #include "r_local.h"
+#include "r_dynamic.h"
+//#include "render.h"
 #include "view.h"
 
 entity_t    r_worldentity;
@@ -73,16 +75,13 @@ int         c_brush_polys, c_alias_polys;
 qboolean    envmap;						// true during envmap command capture
 
 
-int         particletexture;			// little dot for particles
 int         playertextures;				// up to 16 color translated skins
 
 int         mirrortexturenum;			// quake texturenum, not gltexturenum
 qboolean    mirror;
 mplane_t   *mirror_plane;
 
-//
 // view origin
-//
 vec3_t      vup;
 vec3_t      vpn;
 vec3_t      vright;
@@ -91,15 +90,15 @@ vec3_t      r_origin;
 float       r_world_matrix[16];
 float       r_base_world_matrix[16];
 
-//
 // screen size info
-//
 refdef_t    r_refdef;
 
 mleaf_t    *r_viewleaf, *r_oldviewleaf;
 
 int         d_lightstylevalue[256];		// 8.8 fraction of base light value
 
+vec3_t		shadecolor;					// Ender (EXtend) Colormod
+float		modelalpha;					// Ender (EXtend) Alpha
 
 void        R_MarkLeaves (void);
 
@@ -109,12 +108,14 @@ extern byte gammatable[256];
 extern qboolean lighthalf;
 static float vid_gamma = 1.0;
 
+
 // LordHavoc: place for gl_rmain setup code
 void
 glrmain_init ()
 {
 };
 
+
 /*
 	GL_CheckGamma
 
@@ -166,14 +167,6 @@ R_RotateForEntity (entity_t *e)
 	glRotatef (e->angles[2], 1, 0, 0);
 }
 
-/*
-=============================================================
-
-  SPRITE MODELS
-
-=============================================================
-*/
-
 
 static mspriteframe_t *
 R_GetSpriteFrame (entity_t *currententity)
@@ -242,11 +235,6 @@ R_DrawSpriteModel (entity_t *e)
 		right = vright;
 	}
 
-	if (lighthalf)
-		glColor4f (0.5, 0.5, 0.5, 1);
-	else
-		glColor4f (1, 1, 1, 1);
-
 	glBindTexture (GL_TEXTURE_2D, frame->gl_texturenum);
 
 	glEnable (GL_ALPHA_TEST);
@@ -279,11 +267,7 @@ R_DrawSpriteModel (entity_t *e)
 
 
 /*
-=============================================================
-
   ALIAS MODELS
-
-=============================================================
 */
 
 #define NUMVERTEXNORMALS	162
@@ -297,9 +281,9 @@ float       shadelight;
 
 // precalculated dot products for quantized angles
 #define SHADEDOT_QUANT 16
-float       r_avertexnormal_dots[SHADEDOT_QUANT][256] =
-#include "anorm_dots.h"
-           ;
+float   r_avertexnormal_dots[SHADEDOT_QUANT][256] =
+	#include "anorm_dots.h"
+		;
 
 float      *shadedots = r_avertexnormal_dots[0];
 
@@ -320,20 +304,24 @@ GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum, qboolean fb)
 	verts += posenum * paliashdr->poseverts;
 	order = (int *) ((byte *) paliashdr + paliashdr->commands);
 
-	if (fb)
-		glColor3f (1, 1, 1);
-	else if (lighthalf)
-		shadelight *= 2;
-	while (1) {
+	if (modelalpha != 1.0)
+		glDepthMask (GL_FALSE);
+
+	if (fb) {
+		if (lighthalf)
+			glColor4f (0.5, 0.5, 0.5, modelalpha);
+		else
+			glColor4f (1, 1, 1, modelalpha);
+	}
+
+	while ((count = *order++)) {
 		// get the vertex count and primitive type
-		count = *order++;
-		if (!count)
-			break;						// done
 		if (count < 0) {
 			count = -count;
 			glBegin (GL_TRIANGLE_FAN);
-		} else
+		} else {
 			glBegin (GL_TRIANGLE_STRIP);
+		}
 
 		do {
 			// texture coordinates come from the draw list
@@ -343,7 +331,10 @@ GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum, qboolean fb)
 			if (!fb) {
 				// normals and vertexes come from the frame list
 				l = shadedots[verts->lightnormalindex] * shadelight;
-				glColor3f (l, l, l);
+
+				// LordHavoc: cleanup after Endy
+				glColor4f (shadecolor[0] * l, shadecolor[1] * l,
+						   shadecolor[2] * l, modelalpha);
 			}
 
 			glVertex3f (verts->v[0], verts->v[1], verts->v[2]);
@@ -352,8 +343,12 @@ GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum, qboolean fb)
 
 		glEnd ();
 	}
-}
 
+	if (modelalpha != 1.0)
+		glDepthMask (GL_TRUE);
+
+	glColor3ubv (lighthalf_v);
+}
 
 
 extern vec3_t lightspot;
@@ -376,11 +371,9 @@ GL_DrawAliasShadow (aliashdr_t *paliashdr, int posenum)
 
 	height = -lheight + 1.0;
 
-	while (1) {
+	while ((count = *order++)) {
 		// get the vertex count and primitive type
-		count = *order++;
-		if (!count)
-			break;						// done
+
 		if (count < 0) {
 			count = -count;
 			glBegin (GL_TRIANGLE_FAN);
@@ -464,10 +457,7 @@ R_DrawAliasModel (entity_t *e)
 	VectorCopy (currententity->origin, r_entorigin);
 	VectorSubtract (r_origin, r_entorigin, modelorg);
 
-	// 
 	// get lighting information
-	// 
-
 	shadelight = R_LightPoint (currententity->origin);
 
 	// always give the gun some light
@@ -514,23 +504,15 @@ R_DrawAliasModel (entity_t *e)
 	shadevector[2] = 1;
 	VectorNormalize (shadevector);
 
-	// 
 	// locate the proper data
-	// 
 	paliashdr = (aliashdr_t *) Mod_Extradata (currententity->model);
-
 	c_alias_polys += paliashdr->mdl.numtris;
 
-	// 
 	// draw all the triangles
-	// 
-
 	glPushMatrix ();
 	R_RotateForEntity (e);
 
 	// LordHavoc: must be in modulate mode for reasons of lighting as well as 
-	// 
-	// 
 	// fullbright support
 	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
@@ -605,8 +587,6 @@ R_DrawAliasModel (entity_t *e)
 
 }
 
-//==================================================================================
-
 
 static void
 R_DrawEntitiesOnList (void)
@@ -769,9 +749,7 @@ R_SetupGL (void)
 	extern int  glwidth, glheight;
 	int         x, x2, y2, y, w, h;
 
-	// 
 	// set up viewpoint
-	// 
 	glMatrixMode (GL_PROJECTION);
 	glLoadIdentity ();
 	x = r_refdef.vrect.x * glwidth / vid.width;
@@ -829,9 +807,7 @@ R_SetupGL (void)
 
 	glGetFloatv (GL_MODELVIEW_MATRIX, r_world_matrix);
 
-	// 
 	// set drawing parms
-	// 
 	if (gl_cull->int_val)
 		glEnable (GL_CULL_FACE);
 	else
@@ -845,38 +821,6 @@ R_SetupGL (void)
 }
 
 
-/*
-================
-R_RenderScene
-
-r_refdef must be set before the first call
-================
-*/
-static void
-R_RenderScene (void)
-{
-	R_SetupFrame ();
-
-	R_SetFrustum ();
-
-	R_SetupGL ();
-
-	R_MarkLeaves ();					// done here so we know if we're in
-	// water
-
-	R_DrawWorld ();						// adds static entities to the list
-
-	S_ExtraUpdate ();					// don't let sound get messed up if
-	// going slow
-
-	R_DrawEntitiesOnList ();
-
-	R_RenderDlights ();
-	R_UpdateFires ();
-	R_DrawParticles ();
-}
-
-
 static void
 R_Clear (void)
 {
@@ -891,6 +835,7 @@ R_Clear (void)
 	glDepthRange (gldepthmin, gldepthmax);
 }
 
+
 #if 0 // !!! FIXME, Zoid, mirror is disabled for now
 void
 R_Mirror (void)
@@ -958,11 +903,9 @@ R_Mirror (void)
 
 
 /*
-================
-R_RenderView
+	R_RenderView
 
-r_refdef must be set before the first call
-================
+	r_refdef must be set before the first call
 */
 void
 R_RenderView (void)
@@ -980,10 +923,30 @@ R_RenderView (void)
 	R_Clear ();
 
 	// render normal view
-	R_RenderScene ();
-	R_DrawViewModel ();
+	R_SetupFrame ();
+
+	R_SetFrustum ();
+
+	R_SetupGL ();
+
+	R_MarkLeaves ();			// done here so we know if we're in water
+
+	R_DrawWorld ();				// adds static entities to the list
+
+	S_ExtraUpdate ();			// don't let sound get messed up if going slow
+
+	R_DrawEntitiesOnList ();
+
+	R_RenderDlights ();
+
 	R_DrawWaterSurfaces ();
 
+	R_UpdateFires ();
+
+	R_DrawParticles ();
+
+	R_DrawViewModel ();
+
 	// render mirror view
-//  R_Mirror ();
+//	R_Mirror ();
 }
diff --git a/nq/source/gl_rmisc.c b/nq/source/gl_rmisc.c
index 85da0846a..eb8675e4b 100644
--- a/nq/source/gl_rmisc.c
+++ b/nq/source/gl_rmisc.c
@@ -58,15 +58,17 @@
 #include "r_local.h"
 #include "render.h"
 
-extern entity_t r_worldentity;
-extern void GDT_Init ();
-
 varray_t2f_c4f_v3f_t varray[MAX_VARRAY_VERTS];
 
 qboolean    VID_Is8bit (void);
-void        R_InitBubble ();
-
 qboolean    allowskybox;				// allow skyboxes?  --KB
+void        R_InitBubble (void);
+
+extern cvar_t  *r_netgraph;
+
+extern void GDT_Init ();
+
+extern entity_t r_worldentity;
 
 
 void
@@ -75,7 +77,7 @@ R_InitTextures (void)
 	int         x, y, m;
 	byte       *dest;
 
-// create a simple checkerboard texture for the default
+	// create a simple checkerboard texture for the default
 	r_notexture_mip =
 		Hunk_AllocName (sizeof (texture_t) + 16 * 16 + 8 * 8 + 4 * 4 + 2 * 2,
 						"notexture");
@@ -89,13 +91,14 @@ R_InitTextures (void)
 
 	for (m = 0; m < 4; m++) {
 		dest = (byte *) r_notexture_mip + r_notexture_mip->offsets[m];
-		for (y = 0; y < (16 >> m); y++)
+		for (y = 0; y < (16 >> m); y++) {
 			for (x = 0; x < (16 >> m); x++) {
 				if ((y < (8 >> m)) ^ (x < (8 >> m)))
 					*dest++ = 0;
 				else
 					*dest++ = 0xff;
 			}
+		}
 	}
 }
 
@@ -182,12 +185,14 @@ void
 R_Init (void)
 {
 	allowskybox = false;				// server will decide if this is
-	// allowed  --KB
+										// allowed  --KB
 
-	Cmd_AddCommand ("timerefresh", R_TimeRefresh_f, "No Description");
+	Cmd_AddCommand ("timerefresh", R_TimeRefresh_f,
+					"Tests the current refresh rate for the current location");
 	Cmd_AddCommand ("envmap", R_Envmap_f, "No Description");
-	Cmd_AddCommand ("pointfile", R_ReadPointFile_f, "No Description");
-	Cmd_AddCommand ("loadsky", R_LoadSky_f, "No Description");
+	Cmd_AddCommand ("pointfile", R_ReadPointFile_f,
+					"Load a pointfile to determine map leaks");
+	Cmd_AddCommand ("loadsky", R_LoadSky_f, "Load a skybox");
 
 	R_InitBubble ();
 
@@ -199,11 +204,9 @@ R_Init (void)
 
 
 /*
-===============
-R_TranslatePlayerSkin
+	R_TranslatePlayerSkin
 
-Translates a skin texture by the per-player color lookup
-===============
+	Translates a skin texture by the per-player color lookup
 */
 void
 R_TranslatePlayerSkin (int playernum)
@@ -351,7 +354,8 @@ R_TranslatePlayerSkin (int playernum)
 void
 R_NewMap (void)
 {
-	int         i;
+	int			 i;
+	cvar_t		*r_skyname;
 
 	for (i = 0; i < 256; i++)
 		d_lightstylevalue[i] = 264;		// normal light value
@@ -359,8 +363,7 @@ R_NewMap (void)
 	memset (&r_worldentity, 0, sizeof (r_worldentity));
 	r_worldentity.model = cl.worldmodel;
 
-// clear out efrags in case the level hasn't been reloaded
-// FIXME: is this one short?
+	// clear out efrags in case the level hasn't been reloaded
 	for (i = 0; i < cl.worldmodel->numleafs; i++)
 		cl.worldmodel->leafs[i].efrags = NULL;
 
@@ -390,11 +393,9 @@ R_NewMap (void)
 
 
 /*
-====================
-R_TimeRefresh_f
+	R_TimeRefresh_f
 
-For program optimization
-====================
+	For program optimization
 */
 // LordHavoc: improved appearance and accuracy of timerefresh
 void
@@ -403,7 +404,6 @@ R_TimeRefresh_f (void)
 	int         i;
 	double      start, stop, time;
 
-//  glDrawBuffer  (GL_FRONT);
 	glFinish ();
 	GL_EndRendering ();
 
@@ -416,13 +416,10 @@ R_TimeRefresh_f (void)
 		GL_EndRendering ();
 	}
 
-//  glFinish ();
 	stop = Sys_DoubleTime ();
 	time = stop - start;
 	Con_Printf ("%f seconds (%f fps)\n", time, 128 / time);
 
-//  glDrawBuffer  (GL_BACK);
-//  GL_EndRendering ();
 	GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
 }
 
diff --git a/nq/source/gl_rsurf.c b/nq/source/gl_rsurf.c
index 2bc2b5697..a0ed9c1d5 100644
--- a/nq/source/gl_rsurf.c
+++ b/nq/source/gl_rsurf.c
@@ -40,35 +40,26 @@
 #include <math.h>
 #include <stdio.h>
 
-#include "QF/cmd.h"
 #include "QF/compat.h"
-#include "QF/console.h"
-#include "QF/cvar.h"
-#include "QF/draw.h"
-#include "QF/mathlib.h"
-#include "QF/model.h"
-#include "QF/qargs.h"
 #include "QF/sys.h"
-#include "QF/vid.h"
-#include "QF/wad.h"
 
-#include "protocol.h"
 #include "client.h"
 #include "glquake.h"
 #include "r_cvar.h"
 #include "r_local.h"
-#include "render.h"
-#include "sbar.h"
+#include "r_shared.h"
+
+qboolean	r_cache_thrash;
 
 extern double realtime;
-int         skytexturenum;
+int			skytexturenum;
 
 extern vec3_t shadecolor;				// Ender (Extend) Colormod
-int         lightmap_bytes;				// 1 or 3
 
+int         lightmap_bytes;				// 1, 3, or 4
 int         lightmap_textures;
 
-unsigned    blocklights[18 * 18 * 3];
+unsigned int blocklights[18 * 18 * 3];
 
 #define	BLOCK_WIDTH		128
 #define	BLOCK_HEIGHT	128
@@ -94,28 +85,29 @@ int         allocated[MAX_LIGHTMAPS][BLOCK_WIDTH];
 byte       *lightmaps[MAX_LIGHTMAPS];
 
 msurface_t *waterchain = NULL;
+msurface_t *sky_chain;
 
 extern qboolean lighthalf;
 
 
 // LordHavoc: place for gl_rsurf setup code
 void
-glrsurf_init ()
+glrsurf_init (void)
 {
 	memset (&lightmaps, 0, sizeof (lightmaps));
 }
 
 
-void
-recursivelightupdate (mnode_t *node)
+static void
+R_RecursiveLightUpdate (mnode_t *node)
 {
 	int         c;
 	msurface_t *surf;
 
 	if (node->children[0]->contents >= 0)
-		recursivelightupdate (node->children[0]);
+		R_RecursiveLightUpdate (node->children[0]);
 	if (node->children[1]->contents >= 0)
-		recursivelightupdate (node->children[1]);
+		R_RecursiveLightUpdate (node->children[1]);
 	if ((c = node->numsurfaces))
 		for (surf = cl.worldmodel->surfaces + node->firstsurface; c;
 			 c--, surf++) surf->cached_dlight = true;
@@ -124,30 +116,29 @@ recursivelightupdate (mnode_t *node)
 
 // LordHavoc: function to force all lightmaps to be updated
 void
-R_ForceLightUpdate ()
+R_ForceLightUpdate (void)
 {
 	if (cl.worldmodel && cl.worldmodel->nodes
 		&& cl.worldmodel->nodes->contents >= 0)
-		recursivelightupdate (cl.worldmodel->nodes);
+		R_RecursiveLightUpdate (cl.worldmodel->nodes);
 }
 
 
+int         dlightdivtable[8192];
+int         dlightdivtableinitialized = 0;
+
+
 /*
 	R_AddDynamicLights
 
 	LordHavoc: completely rewrote this, relies on 64bit integer math...
 */
-
-int         dlightdivtable[8192];
-int         dlightdivtableinitialized = 0;
-
-
 void
 R_AddDynamicLights (msurface_t *surf)
 {
 	int         sdtable[18], lnum, td, maxdist, maxdist2, maxdist3, i, s, t,
 		smax, tmax, red, green, blue, j;
-	unsigned   *bl;
+	unsigned int *bl;
 	float       dist, f;
 	vec3_t      impact, local;
 
@@ -178,58 +169,40 @@ R_AddDynamicLights (msurface_t *surf)
 			impact[i] =
 				cl_dlights[lnum].origin[i] - surf->plane->normal[i] * dist;
 
-		f =
-			DotProduct (impact,
-						surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] -
-			surf->texturemins[0];
-		i = f;
+		i = f =	DotProduct (impact,	surf->texinfo->vecs[0]) +
+			surf->texinfo->vecs[0][3] - surf->texturemins[0];
 
 		// reduce calculations
 		t = dist * dist;
 		for (s = 0; s < smax; s++, i -= 16)
 			sdtable[s] = i * i + t;
 
-		f =
-			DotProduct (impact,
-						surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] -
-			surf->texturemins[1];
-		i = f;
+		i = f =	DotProduct (impact,	surf->texinfo->vecs[1]) +
+			surf->texinfo->vecs[1][3] - surf->texturemins[1];
 
-		maxdist = (int) (cl_dlights[lnum].radius * cl_dlights[lnum].radius);
 		// for comparisons to minimum acceptable light
+		maxdist = (int) ((cl_dlights[lnum].radius * cl_dlights[lnum].radius) * 0.75);
+
 		// clamp radius to avoid exceeding 8192 entry division table
 		if (maxdist > 1048576)
 			maxdist = 1048576;
 		maxdist3 = maxdist - (int) (dist * dist);
+
 		// convert to 8.8 blocklights format
-//		if (!cl_dlights[lnum].dark)
-//		{
-		f = cl_dlights[lnum].color[0] * maxdist;
-		red = f;
-		f = cl_dlights[lnum].color[1] * maxdist;
-		green = f;
-		f = cl_dlights[lnum].color[2] * maxdist;
-		blue = f;
-		/* 
-		   } else // negate for darklight { f = cl_dlights[lnum].color[0] *
-		   -maxdist;red = f; f = cl_dlights[lnum].color[1] * -maxdist;green = 
-		   f; f = cl_dlights[lnum].color[2] * -maxdist;blue = f; } */
+		red = f = cl_dlights[lnum].color[0] * maxdist;
+		green = f = cl_dlights[lnum].color[1] * maxdist;
+		blue = f = cl_dlights[lnum].color[2] * maxdist;
 		bl = blocklights;
 		for (t = 0; t < tmax; t++, i -= 16) {
 			td = i * i;
-			if (td < maxdist3)			// make sure some part of it is
-				// visible on this line
-			{
+			if (td < maxdist3) {	// make sure some part of it is visible on this line
 				maxdist2 = maxdist - td;
 				for (s = 0; s < smax; s++) {
 					if (sdtable[s] < maxdist2) {
 						j = dlightdivtable[(sdtable[s] + td) >> 7];
-						k = (red * j) >> 7;
-						bl[0] += k;
-						k = (green * j) >> 7;
-						bl[1] += k;
-						k = (blue * j) >> 7;
-						bl[2] += k;
+						bl[0] += (k = (red * j) >> 7);
+						bl[1] += (k = (green * j) >> 7);
+						bl[2] += (k = (blue * j) >> 7);
 					}
 					bl += 3;
 				}
@@ -252,13 +225,12 @@ void
 R_BuildLightMap (msurface_t *surf, byte * dest, int stride)
 {
 	int         smax, tmax;
-	int         t;
-	int         i, j, size;
+	int         i, j, size, shift;
 	byte       *lightmap;
-	unsigned    scale;
+	unsigned int scale;
 	int         maps;
 	float       t2;
-	unsigned   *bl;
+	unsigned int *bl;
 
 	surf->cached_dlight = (surf->dlightframe == r_framecount);
 
@@ -268,26 +240,16 @@ R_BuildLightMap (msurface_t *surf, byte * dest, int stride)
 	lightmap = surf->samples;
 
 	// set to full bright if no light data
-	if ( /* r_fullbright->int_val || */ !cl.worldmodel->lightdata) {
-		bl = blocklights;
-		for (i = 0; i < size; i++) {
-			*bl++ = 255 * 256;
-			*bl++ = 255 * 256;
-			*bl++ = 255 * 256;
-		}
+	if (!cl.worldmodel->lightdata) {
+		memset (&blocklights[0], 65280, 3 * size * sizeof(int));
 		goto store;
 	}
+
 	// clear to no light
-	bl = blocklights;
-	for (i = 0; i < size; i++) {
-		*bl++ = 0;
-		*bl++ = 0;
-		*bl++ = 0;
-	}
-	bl = blocklights;
+	memset (&blocklights[0], 0, 3 * size * sizeof(int));
 
 	// add all the lightmaps
-	if (lightmap)
+	if (lightmap) {
 		for (maps = 0; maps < MAXLIGHTMAPS && surf->styles[maps] != 255; maps++) {
 			scale = d_lightstylevalue[surf->styles[maps]];
 			surf->cached_light[maps] = scale;	// 8.8 fraction
@@ -298,64 +260,58 @@ R_BuildLightMap (msurface_t *surf, byte * dest, int stride)
 				*bl++ += *lightmap++ * scale;
 			}
 		}
+	}
 	// add all the dynamic lights
 	if (surf->dlightframe == r_framecount)
 		R_AddDynamicLights (surf);
 
   store:
 	// bound and shift
-	if (gl_colorlights->int_val) {
-		stride -= smax * 3;
-		bl = blocklights;
-		if (lighthalf) {
-			for (i = 0; i < tmax; i++, dest += stride)
-				for (j = 0; j < smax; j++) {
-					t = (int) *bl++ >> 8;
-					*dest++ = bound (0, t, 255);
-					t = (int) *bl++ >> 8;
-					*dest++ = bound (0, t, 255);
-					t = (int) *bl++ >> 8;
-					*dest++ = bound (0, t, 255);
-				}
-		} else {
-			for (i = 0; i < tmax; i++, dest += stride)
-				for (j = 0; j < smax; j++) {
-					t = (int) *bl++ >> 7;
-					*dest++ = bound (0, t, 255);
-					t = (int) *bl++ >> 7;
-					*dest++ = bound (0, t, 255);
-					t = (int) *bl++ >> 7;
-					*dest++ = bound (0, t, 255);
-				}
-		}
+	stride -= smax * lightmap_bytes;
+	bl = blocklights;
+
+	if (gl_mtex_active && !lighthalf) {
+		shift = 7;      // 0-1 lightmap range.
 	} else {
-		stride -= smax;
-		bl = blocklights;
-		if (lighthalf) {
-			for (i = 0; i < tmax; i++, dest += stride)
-				for (j = 0; j < smax; j++) {
-					t = (int) *bl++ >> 8;
-					t2 = bound (0, t, 255);
-					t = (int) *bl++ >> 8;
-					t2 += bound (0, t, 255);
-					t = (int) *bl++ >> 8;
-					t2 += bound (0, t, 255);
-					t2 *= (1.0 / 3.0);
-					*dest++ = t2;
-				}
-		} else {
-			for (i = 0; i < tmax; i++, dest += stride)
-				for (j = 0; j < smax; j++) {
-					t = (int) *bl++ >> 7;
-					t2 = bound (0, t, 255);
-					t = (int) *bl++ >> 7;
-					t2 += bound (0, t, 255);
-					t = (int) *bl++ >> 7;
-					t2 += bound (0, t, 255);
-					t2 *= (1.0 / 3.0);
-					*dest++ = t2;
-				}
+		shift = 8;      // 0-2 lightmap range.
+	}
+
+	switch (lightmap_bytes) {
+	case 4:
+		for (i = 0; i < tmax; i++, dest += stride) {
+			for (j = 0; j < smax; j++) {
+				dest[0] = bound(0, bl[0] >> shift, 255);
+				dest[1] = bound(0, bl[1] >> shift, 255);
+				dest[2] = bound(0, bl[2] >> shift, 255);
+				dest[3] = 255;
+				dest += 4;
+				bl += 3;
+			}
 		}
+		break;
+	case 3:
+		for (i = 0; i < tmax; i++, dest += stride) {
+			for (j = 0; j < smax; j++) {
+				dest[0] = bound(0, bl[0] >> shift, 255);
+				dest[1] = bound(0, bl[1] >> shift, 255);
+				dest[2] = bound(0, bl[2] >> shift, 255);
+				dest += 3;
+				bl += 3;
+			}
+		}
+		break;
+	case 1:
+		for (i = 0; i < tmax; i++, dest += stride) {
+			for (j = 0; j < smax; j++) {
+				t2 = bound (0, bl[0] >> shift, 255);
+				t2 += bound (0, bl[1] >> shift, 255);
+				t2 += bound (0, bl[2] >> shift, 255);
+				t2 *= (1.0 / 3.0);
+				*dest++ = t2;
+				bl += 3;
+			}
+		}
+		break;
 	}
 }
 
@@ -403,16 +359,17 @@ extern int  solidskytexture;
 extern int  alphaskytexture;
 extern float speedscale;				// for top sky and bottom sky
 
-lpMTexFUNC  qglMTexCoord2f = NULL;
-lpSelTexFUNC qglSelectTexture = NULL;
-
 
 void
 GL_UploadLightmap (int i, int x, int y, int w, int h)
 {
-	glTexSubImage2D (GL_TEXTURE_2D, 0, 0, y, BLOCK_WIDTH, h, gl_lightmap_format,
+/*	glTexSubImage2D (GL_TEXTURE_2D, 0, 0, y, BLOCK_WIDTH, h, gl_lightmap_format,
 					 GL_UNSIGNED_BYTE,
 					 lightmaps[i] + (y * BLOCK_WIDTH) * lightmap_bytes);
+*/
+	glTexImage2D (GL_TEXTURE_2D, 0, lightmap_bytes, BLOCK_WIDTH,
+				  BLOCK_HEIGHT, 0, gl_lightmap_format,
+				  GL_UNSIGNED_BYTE, lightmaps[i]);
 }
 
 
@@ -436,12 +393,12 @@ R_DrawMultitexturePoly (msurface_t *s)
 
 	glColor3f (1, 1, 1);
 	// Binds world to texture env 0
-	qglSelectTexture (gl_mtex_enum + 0);
+	qglActiveTexture (gl_mtex_enum + 0);
 	glBindTexture (GL_TEXTURE_2D, texture->gl_texturenum);
 	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 	glEnable (GL_TEXTURE_2D);
 	// Binds lightmap to texenv 1
-	qglSelectTexture (gl_mtex_enum + 1);
+	qglActiveTexture (gl_mtex_enum + 1);
 	glBindTexture (GL_TEXTURE_2D, lightmap_textures + i);
 	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 	glEnable (GL_TEXTURE_2D);
@@ -452,9 +409,7 @@ R_DrawMultitexturePoly (msurface_t *s)
 			if (d_lightstylevalue[s->styles[maps]] != s->cached_light[maps])
 				goto dynamic;
 
-		if (s->dlightframe == r_framecount	// dynamic this frame
-			|| s->cached_dlight)		// dynamic previously
-		{
+		if ((s->dlightframe == r_framecount) || s->cached_dlight)	{
 		  dynamic:
 			R_BuildLightMap (s,
 							 lightmaps[s->lightmaptexturenum] +
@@ -470,19 +425,21 @@ R_DrawMultitexturePoly (msurface_t *s)
 	glBegin (GL_POLYGON);
 	v = s->polys->verts[0];
 	for (i = 0; i < s->polys->numverts; i++, v += VERTEXSIZE) {
-		qglMTexCoord2f (gl_mtex_enum + 0, v[3], v[4]);
-		qglMTexCoord2f (gl_mtex_enum + 1, v[5], v[6]);
+		qglMultiTexCoord2f (gl_mtex_enum + 0, v[3], v[4]);
+		qglMultiTexCoord2f (gl_mtex_enum + 1, v[5], v[6]);
 		glVertex3fv (v);
 	}
 	glEnd ();
 	glDisable (GL_TEXTURE_2D);
-	qglSelectTexture (gl_mtex_enum + 0);
+	qglActiveTexture (gl_mtex_enum + 0);
 	glEnable (GL_TEXTURE_2D);
 
 	if (texture->gl_fb_texturenum > 0) {
 		s->polys->fb_chain = fullbright_polys[texture->gl_fb_texturenum];
 		fullbright_polys[texture->gl_fb_texturenum] = s->polys;
 	}
+	glColor3ubv (lighthalf_v);
+	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 }
 
 
@@ -493,11 +450,14 @@ R_BlendLightmaps (void)
 	glpoly_t   *p;
 	float      *v;
 
-	glDepthMask (0);					// don't bother writing Z
+	glDepthMask (GL_FALSE);					// don't bother writing Z
 
-	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-	glBlendFunc (GL_ZERO, GL_SRC_COLOR);
-	glEnable (GL_BLEND);
+	if (lighthalf)
+		glBlendFunc (GL_ZERO, GL_SRC_COLOR);
+	else
+		glBlendFunc (GL_DST_COLOR, GL_SRC_COLOR);
+
+	glColor3f (1, 1, 1);
 
 	for (i = 0; i < MAX_LIGHTMAPS; i++) {
 		p = lightmap_polys[i];
@@ -523,9 +483,10 @@ R_BlendLightmaps (void)
 	}
 
 	// Return to normal blending  --KB
+	glColor3ubv (lighthalf_v);
 	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
-	glDepthMask (1);					// back to normal Z buffering
+	glDepthMask (GL_TRUE);					// back to normal Z buffering
 }
 
 
@@ -536,10 +497,7 @@ R_RenderFullbrights (void)
 	glpoly_t   *p;
 	float      *v;
 
-	// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 	glBlendFunc (GL_ONE, GL_ONE);
-	glEnable (GL_BLEND);
-	glColor3f (1, 1, 1);
 
 	for (i = 1; i < MAX_GLTEXTURES; i++) {
 		if (!fullbright_polys[i])
@@ -554,8 +512,6 @@ R_RenderFullbrights (void)
 			glEnd ();
 		}
 	}
-
-	glDisable (GL_BLEND);
 	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 }
 
@@ -573,6 +529,7 @@ R_RenderBrushPoly (msurface_t *fa)
 
 	c_brush_polys++;
 
+	glColor3f (1, 1, 1);
 	glBindTexture (GL_TEXTURE_2D, texture->gl_texturenum);
 
 	glBegin (GL_POLYGON);
@@ -597,9 +554,7 @@ R_RenderBrushPoly (msurface_t *fa)
 		if (d_lightstylevalue[fa->styles[maps]] != fa->cached_light[maps])
 			goto dynamic;
 
-	if (fa->dlightframe == r_framecount	// dynamic this frame
-		|| fa->cached_dlight)			// dynamic previously
-	{
+	if ((fa->dlightframe == r_framecount) || fa->cached_dlight) {
 	  dynamic:
 		if (r_dynamic->int_val) {
 			lightmap_modified[fa->lightmaptexturenum] = true;
@@ -621,12 +576,12 @@ R_RenderBrushPoly (msurface_t *fa)
 			if ((theRect->h + theRect->t) < (fa->light_t + tmax))
 				theRect->h = (fa->light_t - theRect->t) + tmax;
 			base =
-				lightmaps[fa->lightmaptexturenum] + (fa->light_t * BLOCK_WIDTH +
-													 fa->light_s) *
-				lightmap_bytes;
+				lightmaps[fa->lightmaptexturenum] +
+				(fa->light_t * BLOCK_WIDTH + fa->light_s) * lightmap_bytes;
 			R_BuildLightMap (fa, base, BLOCK_WIDTH * lightmap_bytes);
 		}
 	}
+	glColor3ubv (lighthalf_v);
 }
 
 
@@ -635,20 +590,20 @@ GL_WaterSurface (msurface_t *s)
 {
 	int         i;
 
-	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-	if (lighthalf)
-		glColor4f (0.5, 0.5, 0.5, r_wateralpha->value);
-	else
-		glColor4f (1, 1, 1, r_wateralpha->value);
 	i = s->texinfo->texture->gl_texturenum;
 	glBindTexture (GL_TEXTURE_2D, i);
 	if (r_wateralpha->value < 1.0) {
-		glDepthMask (0);
+		glDepthMask (GL_FALSE);
+		if (lighthalf) {
+			glColor4f (0.5, 0.5, 0.5, r_wateralpha->value);
+		} else {
+			glColor4f (1, 1, 1, r_wateralpha->value);
+		}
 		EmitWaterPolys (s);
-		glDepthMask (1);
+		glColor3ubv (lighthalf_v);
+		glDepthMask (GL_TRUE);
 	} else
 		EmitWaterPolys (s);
-	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 }
 
 
@@ -662,16 +617,16 @@ R_DrawWaterSurfaces (void)
 		return;
 
 	// go back to the world matrix
-
 	glLoadMatrixf (r_world_matrix);
 
-	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-	if (lighthalf)
-		glColor4f (0.5, 0.5, 0.5, r_wateralpha->value);
-	else
-		glColor4f (1, 1, 1, r_wateralpha->value);
-	if (r_wateralpha->value < 1.0)
-		glDepthMask (0);
+	if (r_wateralpha->value < 1.0) {
+		glDepthMask (GL_FALSE);
+		if (lighthalf) {
+			glColor4f (0.5, 0.5, 0.5, r_wateralpha->value);
+		} else {
+			glColor4f (1, 1, 1, r_wateralpha->value);
+		}
+	}
 
 	i = -1;
 	for (s = waterchain; s; s = s->texturechain) {
@@ -684,9 +639,10 @@ R_DrawWaterSurfaces (void)
 
 	waterchain = NULL;
 
-	glColor3f (1, 1, 1);
-	if (r_wateralpha->value < 1.0)
-		glDepthMask (1);
+	if (r_wateralpha->value < 1.0) {
+		glDepthMask (GL_TRUE);
+		glColor3ubv (lighthalf_v);
+	}
 }
 
 
@@ -696,6 +652,8 @@ DrawTextureChains (void)
 	int         i;
 	msurface_t *s;
 
+	glDisable (GL_BLEND);
+
 	for (i = 0; i < cl.worldmodel->numtextures; i++) {
 		if (!cl.worldmodel->textures[i])
 			continue;
@@ -704,6 +662,8 @@ DrawTextureChains (void)
 
 		cl.worldmodel->textures[i]->texturechain = NULL;
 	}
+
+	glEnable (GL_BLEND);
 }
 
 
@@ -738,10 +698,11 @@ R_DrawBrushModel (entity_t *e)
 	if (R_CullBox (mins, maxs))
 		return;
 
-	glColor3f (1, 1, 1);
-
 	memset (lightmap_polys, 0, sizeof (lightmap_polys));
 	memset (fullbright_polys, 0, sizeof (fullbright_polys));
+	if (gl_sky_clip->int_val) {
+		sky_chain = 0;
+	}
 
 	VectorSubtract (r_refdef.vieworg, e->origin, modelorg);
 	if (rotated) {
@@ -757,9 +718,8 @@ R_DrawBrushModel (entity_t *e)
 
 	psurf = &clmodel->surfaces[clmodel->firstmodelsurface];
 
-	// calculate dynamic lighting for bmodel if it's not an
-	// instanced model
-	if (clmodel->firstmodelsurface != 0 && !gl_flashblend->int_val) {
+	// calculate dynamic lighting for bmodel if it's not an instanced model
+	if (clmodel->firstmodelsurface != 0 && gl_dlight_lightmap->int_val) {
 		vec3_t      lightorigin;
 
 		for (k = 0; k < MAX_DLIGHTS; k++) {
@@ -777,14 +737,12 @@ R_DrawBrushModel (entity_t *e)
 	R_RotateForEntity (e);
 	e->angles[0] = -e->angles[0];		// stupid quake bug
 
-	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-
-	// 
 	// draw texture
-	// 
 	for (i = 0; i < clmodel->nummodelsurfaces; i++, psurf++) {
+/* FIXME: Not in qw?
 		if (psurf->flags & SURF_DRAWSKY)
 			return;
+*/
 
 		// find which side of the node we are on
 		pplane = psurf->plane;
@@ -794,24 +752,28 @@ R_DrawBrushModel (entity_t *e)
 		// draw the polygon
 		if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
 			(!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) {
-			if (psurf->flags & SURF_DRAWTURB)
+			if (psurf->flags & SURF_DRAWTURB) {
 				GL_WaterSurface (psurf);
-			else if (gl_texsort->int_val)
-				R_RenderBrushPoly (psurf);
-			else
+			} else if (psurf->flags & SURF_DRAWSKY) {
+				psurf->texturechain = sky_chain;
+				sky_chain = psurf;
+				return;
+			} else if (gl_mtex_active) {
 				R_DrawMultitexturePoly (psurf);
+			} else {
+				R_RenderBrushPoly (psurf);
+			}
 		}
 	}
 
-	if (gl_texsort->int_val)
+	if (!gl_mtex_active)
 		R_BlendLightmaps ();
 
 	if (gl_fb_bmodels->int_val)
 		R_RenderFullbrights ();
 
-	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-	glEnable (GL_BLEND);
+	if (gl_sky_clip->int_val)
+		R_DrawSkyChain (sky_chain);
 
 	glPopMatrix ();
 }
@@ -832,14 +794,13 @@ R_RecursiveWorldNode (mnode_t *node)
 	double      dot;
 
 	if (node->contents == CONTENTS_SOLID)
-		return;							// solid
-
+		return;
 	if (node->visframe != r_visframecount)
 		return;
 	if (R_CullBox (node->minmaxs, node->minmaxs + 3))
 		return;
 
-// if a leaf node, draw stuff
+	// if a leaf node, draw stuff
 	if (node->contents < 0) {
 		pleaf = (mleaf_t *) node;
 
@@ -856,9 +817,9 @@ R_RecursiveWorldNode (mnode_t *node)
 
 		return;
 	}
-// node is just a decision point, so go down the apropriate sides
+	// node is just a decision point, so go down the apropriate sides
 
-// find which side of the node we are on
+	// find which side of the node we are on
 	plane = node->plane;
 
 	switch (plane->type) {
@@ -878,7 +839,7 @@ R_RecursiveWorldNode (mnode_t *node)
 
 	side = dot < 0;
 
-// recurse down the children, front side first
+	// recurse down the children, front side first
 	// LordHavoc: save a stack frame by avoiding a call
 	if (node->children[side]->contents != CONTENTS_SOLID
 		&& node->children[side]->visframe == r_visframecount
@@ -886,7 +847,7 @@ R_RecursiveWorldNode (mnode_t *node)
 					   node->children[side]->minmaxs + 3))
 		R_RecursiveWorldNode (node->children[side]);
 
-// draw stuff
+	// draw stuff
 	if ((c = node->numsurfaces)) {
 		surf = cl.worldmodel->surfaces + node->firstsurface;
 
@@ -902,20 +863,22 @@ R_RecursiveWorldNode (mnode_t *node)
 			if ((dot < 0) ^ !!(surf->flags & SURF_PLANEBACK))
 				continue;				// wrong side
 
-			if (surf->flags & SURF_DRAWSKY)
-				continue;
-
 			if (surf->flags & SURF_DRAWTURB) {
 				surf->texturechain = waterchain;
 				waterchain = surf;
-			} else if (gl_texsort->int_val) {
+			} else if (surf->flags & SURF_DRAWSKY) {
+				surf->texturechain = sky_chain;
+				sky_chain = surf;
+				continue;
+			} else if (gl_mtex_active) {
+				R_DrawMultitexturePoly (surf);
+			} else {
 				surf->texturechain = surf->texinfo->texture->texturechain;
 				surf->texinfo->texture->texturechain = surf;
-			} else
-				R_DrawMultitexturePoly (surf);
+			}
 		}
 	}
-// recurse down the back side
+	// recurse down the back side
 	// LordHavoc: save a stack frame by avoiding a call
 	side = !side;
 	if (node->children[side]->contents != CONTENTS_SOLID
@@ -938,28 +901,27 @@ R_DrawWorld (void)
 
 	currententity = &ent;
 
-	glColor3f (1.0, 1.0, 1.0);
 	memset (lightmap_polys, 0, sizeof (lightmap_polys));
 	memset (fullbright_polys, 0, sizeof (fullbright_polys));
-	// Be sure to clear the skybox --KB
-	R_DrawSky ();
-
-	glDisable (GL_BLEND);
-	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+	if (gl_sky_clip->int_val) {
+		sky_chain = 0;
+	} else {
+		// Be sure to clear the skybox --KB
+		R_DrawSky ();
+	}
 
 	R_RecursiveWorldNode (cl.worldmodel->nodes);
 
 	DrawTextureChains ();
 
-	if (gl_texsort->int_val)
+	if (!gl_mtex_active)
 		R_BlendLightmaps ();
 
 	if (gl_fb_bmodels->int_val)
 		R_RenderFullbrights ();
 
-	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-	glEnable (GL_BLEND);
+	if (gl_sky_clip->int_val)
+		R_DrawSkyChain (sky_chain);
 }
 
 
@@ -974,9 +936,6 @@ R_MarkLeaves (void)
 	if (r_oldviewleaf == r_viewleaf && !r_novis->int_val)
 		return;
 
-	if (mirror)
-		return;
-
 	r_visframecount++;
 	r_oldviewleaf = r_viewleaf;
 
@@ -1037,7 +996,7 @@ AllocBlock (int w, int h, int *x, int *y)
 
 		// LordHavoc: allocate lightmaps only as needed
 		if (!lightmaps[texnum])
-			lightmaps[texnum] = calloc (BLOCK_WIDTH * BLOCK_HEIGHT, 3);
+			lightmaps[texnum] = calloc (BLOCK_WIDTH * BLOCK_HEIGHT, lightmap_bytes); // DESPAIR: was 3, not lightmap_bytes
 
 		for (i = 0; i < w; i++)
 			allocated[texnum][*x + i] = best + h;
@@ -1065,18 +1024,14 @@ BuildSurfaceDisplayList (msurface_t *fa)
 	float       s, t;
 	glpoly_t   *poly;
 
-// reconstruct the polygon
+	// reconstruct the polygon
 	pedges = currentmodel->edges;
 	lnumverts = fa->numedges;
 	vertpage = 0;
 
-	// 
 	// draw texture
-	// 
-	poly =
-
-		Hunk_Alloc (sizeof (glpoly_t) +
-					(lnumverts - 4) * VERTEXSIZE * sizeof (float));
+	poly = Hunk_Alloc (sizeof (glpoly_t) + (lnumverts - 4) *
+					   VERTEXSIZE * sizeof (float));
 	poly->next = fa->polys;
 	poly->flags = fa->flags;
 	fa->polys = poly;
@@ -1102,9 +1057,7 @@ BuildSurfaceDisplayList (msurface_t *fa)
 		poly->verts[i][3] = s;
 		poly->verts[i][4] = t;
 
-		// 
 		// lightmap texture coordinates
-		// 
 		s = DotProduct (vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3];
 		s -= fa->texturemins[0];
 		s += fa->light_s * 16;
@@ -1121,9 +1074,7 @@ BuildSurfaceDisplayList (msurface_t *fa)
 		poly->verts[i][6] = t;
 	}
 
-	// 
 	// remove co-linear points - Ed
-	// 
 	if (!gl_keeptjunctions->int_val && !(fa->flags & SURF_UNDERWATER)) {
 		for (i = 0; i < lnumverts; ++i) {
 			vec3_t      v1, v2;
@@ -1176,9 +1127,8 @@ GL_CreateSurfaceLightmap (msurface_t *surf)
 
 	surf->lightmaptexturenum =
 		AllocBlock (smax, tmax, &surf->light_s, &surf->light_t);
-	base =
-		lightmaps[surf->lightmaptexturenum] + (surf->light_t * BLOCK_WIDTH +
-											   surf->light_s) * lightmap_bytes;
+	base = lightmaps[surf->lightmaptexturenum] +
+		(surf->light_t * BLOCK_WIDTH + surf->light_s) * lightmap_bytes;
 	R_BuildLightMap (surf, base, BLOCK_WIDTH * lightmap_bytes);
 }
 
@@ -1186,8 +1136,7 @@ GL_CreateSurfaceLightmap (msurface_t *surf)
 /*
 	GL_BuildLightmaps
 
-	Builds the lightmap texture
-	with all the surfaces from all brush models
+	Builds the lightmap texture with all the surfaces from all brush models
 */
 void
 GL_BuildLightmaps (void)
@@ -1204,12 +1153,20 @@ GL_BuildLightmaps (void)
 		texture_extension_number += MAX_LIGHTMAPS;
 	}
 
-	if (gl_colorlights->int_val) {
-		gl_lightmap_format = GL_RGB;
-		lightmap_bytes = 3;
-	} else {
+	switch (gl_lightmap_components->int_val) {
+	case 1:
 		gl_lightmap_format = GL_LUMINANCE;
 		lightmap_bytes = 1;
+		break;
+	case 3:
+		gl_lightmap_format = GL_RGB;
+		lightmap_bytes = 3;
+		break;
+	case 4:
+	default:
+		gl_lightmap_format = GL_RGBA;
+		lightmap_bytes = 4;
+		break;
 	}
 
 	for (j = 1; j < MAX_MODELS; j++) {
@@ -1223,19 +1180,17 @@ GL_BuildLightmaps (void)
 		for (i = 0; i < m->numsurfaces; i++) {
 			if (m->surfaces[i].flags & SURF_DRAWTURB)
 				continue;
-			if (m->surfaces[i].flags & SURF_DRAWSKY)
+			if (gl_sky_divide->int_val && (m->surfaces[i].flags & SURF_DRAWSKY))
 				continue;
 			GL_CreateSurfaceLightmap (m->surfaces + i);
 			BuildSurfaceDisplayList (m->surfaces + i);
 		}
 	}
 
-	if (!gl_texsort->int_val)
-		qglSelectTexture (gl_mtex_enum + 1);
+	if (gl_mtex_active)
+		qglActiveTexture (gl_mtex_enum + 1);
 
-	// 
 	// upload all lightmaps that were filled
-	// 
 	for (i = 0; i < MAX_LIGHTMAPS; i++) {
 		if (!allocated[i][0])
 			break;						// no more used
@@ -1252,6 +1207,6 @@ GL_BuildLightmaps (void)
 					  GL_UNSIGNED_BYTE, lightmaps[i]);
 	}
 
-	if (!gl_texsort->int_val)
-		qglSelectTexture (gl_mtex_enum + 0);
+	if (gl_mtex_active)
+		qglActiveTexture (gl_mtex_enum + 0);
 }
diff --git a/nq/source/r_cvar.c b/nq/source/r_cvar.c
index 300cd7344..7de883b36 100644
--- a/nq/source/r_cvar.c
+++ b/nq/source/r_cvar.c
@@ -15,15 +15,16 @@ cvar_t     *d_subdiv16;
 
 cvar_t     *gl_affinemodels;
 cvar_t     *gl_clear;
-cvar_t     *gl_colorlights;
 cvar_t     *gl_conalpha;
 cvar_t     *gl_conspin;
 cvar_t     *gl_constretch;
-cvar_t     *gl_cull;
+cvar_t     *gl_cull; // FIXME
+cvar_t     *gl_dlight_lightmap; 
+cvar_t     *gl_dlight_polyblend; 
+cvar_t     *gl_dlight_smooth; 
 cvar_t     *gl_fb_bmodels;
 cvar_t     *gl_fb_models;
 cvar_t     *gl_fires;
-cvar_t     *gl_flashblend;
 cvar_t     *gl_keeptjunctions;
 cvar_t     *gl_lightmap_components;
 cvar_t     *gl_lightmode;
@@ -31,10 +32,11 @@ cvar_t     *gl_max_size;
 cvar_t     *gl_nocolors;
 cvar_t     *gl_picmip;
 cvar_t     *gl_playermip;
-cvar_t     *gl_polyblend;
+cvar_t     *gl_polyblend; // FIXME
 cvar_t     *gl_reporttjunctions;
+cvar_t     *gl_sky_clip;
 cvar_t     *gl_skymultipass;
-cvar_t     *gl_smoothmodels;
+cvar_t     *gl_smoothmodels; // FIXME
 cvar_t     *gl_texsort;
 cvar_t     *gl_triplebuffer;
 
@@ -102,41 +104,77 @@ void
 R_Init_Cvars (void)
 {
 
-	cl_crossx = Cvar_Get ("cl_crossx", "0", CVAR_ARCHIVE, NULL, "Sets the position of the crosshair on the X-axis");
-	cl_crossx = Cvar_Get ("cl_crossx", "0", CVAR_ARCHIVE, NULL, "Sets the position of the crosshair on the X-axis.");
-	cl_crossy = Cvar_Get ("cl_crossy", "0", CVAR_ARCHIVE, NULL, "Sets the position of the crosshair on the Y-axis");
-	cl_crossy = Cvar_Get ("cl_crossy", "0", CVAR_ARCHIVE, NULL, "Sets the position of the crosshair on the Y-axis.");
-	cl_verstring = Cvar_Get ("cl_verstring", PROGRAM " " VERSION, CVAR_NONE, NULL, "Client version string");
-	crosshair = Cvar_Get ("crosshair", "0", CVAR_ARCHIVE, NULL, "Crosshair type. 0 off, 1 old without color, 2 new with colors");
-	crosshair = Cvar_Get ("crosshair", "0", CVAR_ARCHIVE, NULL, "Crosshair type. 0 off, 1 old, 2 new with color");
-	crosshaircolor = Cvar_Get ("crosshaircolor", "79", CVAR_ARCHIVE, NULL, "Color of the new crosshair");
-	crosshaircolor = Cvar_Get ("crosshaircolor", "79", CVAR_ARCHIVE, NULL, "Crosshair 2's color");
-
-	d_mipcap = Cvar_Get ("d_mipcap", "0", CVAR_NONE, NULL, "None");
-	d_mipscale = Cvar_Get ("d_mipscale", "1", CVAR_NONE, NULL, "None");
-	d_subdiv16 = Cvar_Get ("d_subdiv16", "1", CVAR_NONE, NULL, "None");
-
-	gl_affinemodels = Cvar_Get ("gl_affinemodels", "0", CVAR_NONE, NULL, "None");
-	gl_clear = Cvar_Get ("gl_clear", "0", CVAR_NONE, NULL, "None");
-	gl_colorlights = Cvar_Get ("gl_colorlights", "1", CVAR_ROM, NULL, "Whether to use RGB lightmaps or not");
-	gl_conalpha = Cvar_Get ("gl_conalpha", "0.6", CVAR_ARCHIVE, NULL, "alpha value for the console background");
-	gl_conspin = Cvar_Get ("gl_conspin", "0", CVAR_ARCHIVE, NULL, "speed at which the console spins");
-	gl_constretch = Cvar_Get ("gl_constretch", "0", CVAR_ARCHIVE, NULL, "whether slide the console or stretch it");
+	cl_crossx =	Cvar_Get ("cl_crossx", "0", CVAR_ARCHIVE, NULL,
+						  "Sets the position of the crosshair on the X-axis");
+	cl_crossx = Cvar_Get ("cl_crossx", "0", CVAR_ARCHIVE, NULL,
+						  "Sets the position of the crosshair on the X-axis.");
+	cl_crossy = Cvar_Get ("cl_crossy", "0", CVAR_ARCHIVE, NULL,
+						  "Sets the position of the crosshair on the Y-axis");
+	cl_crossy = Cvar_Get ("cl_crossy", "0", CVAR_ARCHIVE, NULL,
+						  "Sets the position of the crosshair on the Y-axis.");
+	cl_verstring = Cvar_Get ("cl_verstring", PROGRAM " " VERSION, CVAR_NONE,
+							 NULL, "Client version string");
+	crosshair =
+		Cvar_Get ("crosshair", "0", CVAR_ARCHIVE, NULL,
+				  "Crosshair type. 0 off, 1 old without color, 2 new with colors");
+	crosshaircolor = Cvar_Get ("crosshaircolor", "79", CVAR_ARCHIVE, NULL,
+							   "Color of the new crosshair");
+	d_mipcap = Cvar_Get ("d_mipcap", "0", CVAR_NONE, NULL,
+						 "Detail level. 0 is highest, 3 is lowest.");
+	d_mipscale =
+		Cvar_Get ("d_mipscale", "1", CVAR_NONE, NULL,
+				  "Detail level of objects. 0 is highest, 3 is lowest");
+	d_subdiv16 = Cvar_Get ("d_subdiv16", "1", CVAR_NONE, NULL,
+						   "Set to enable extreme perspective correction");
+	gl_affinemodels =
+		Cvar_Get ("gl_affinemodels", "0", CVAR_NONE, NULL,
+				  "Makes texture rendering quality better if set to 1");
+	gl_clear = Cvar_Get ("gl_clear", "0", CVAR_NONE, NULL,
+						 "Set to 1 to make background black. Useful for removing HOM effect"); 
+	gl_conalpha = Cvar_Get ("gl_conalpha", "0.6", CVAR_ARCHIVE, NULL,
+							"alpha value for the console background");
+	gl_conspin = Cvar_Get ("gl_conspin", "0", CVAR_ARCHIVE, NULL,
+						   "speed at which the console spins");
+	gl_constretch = Cvar_Get ("gl_constretch", "0", CVAR_ARCHIVE, NULL,
+							  "whether slide the console or stretch it");
 	gl_cull = Cvar_Get ("gl_cull", "1", CVAR_NONE, NULL, "None");
-	gl_fb_bmodels = Cvar_Get ("gl_fb_bmodels", "1", CVAR_ARCHIVE, NULL, "Toggles fullbright color support for bmodels");
-	gl_fb_models = Cvar_Get ("gl_fb_models", "1", CVAR_ARCHIVE, NULL, "Toggles fullbright color support for models..  " "This is very handy, but costs me 2 FPS.. (=:]");
-	gl_fires = Cvar_Get ("gl_fires", "0", CVAR_ARCHIVE, NULL, "Toggles lavaball and rocket fireballs");
-	gl_flashblend = Cvar_Get ("gl_flashblend", "0", CVAR_NONE, NULL, "None");
+    gl_dlight_lightmap = 
+        Cvar_Get ("gl_dlight_lightmap", "1", CVAR_ARCHIVE, NULL, 
+                  "Set to 1 for high quality dynamic lighting."); 
+    gl_dlight_polyblend = 
+        Cvar_Get ("gl_dlight_polyblend", "0", CVAR_ARCHIVE, NULL, 
+                  "Set to 1 to use a dynamic light effect faster on GL"); 
+    gl_dlight_smooth = 
+        Cvar_Get ("gl_dlight_smooth", "1", CVAR_ARCHIVE, NULL, 
+                  "Smooth dynamic vertex lighting"); 
+	gl_fb_bmodels = Cvar_Get ("gl_fb_bmodels", "1", CVAR_ARCHIVE, NULL,
+							  "Toggles fullbright color support for bmodels");
+	gl_fb_models = Cvar_Get ("gl_fb_models", "1", CVAR_ARCHIVE, NULL,
+							 "Toggles fullbright color support for models..  "
+							 "This is very handy, but costs me 2 FPS.. (=:]");
+	gl_fires = Cvar_Get ("gl_fires", "0", CVAR_ARCHIVE, NULL,
+						 "Toggles lavaball and rocket fireballs");
 	gl_keeptjunctions = Cvar_Get ("gl_keeptjunctions", "1", CVAR_NONE, NULL, "None");
-	gl_lightmap_components = Cvar_Get ("gl_lightmap_components", "4", CVAR_ROM, NULL, "Lightmap texture components. 1 is greyscale, 3 is RGB, 4 is RGBA.");
-	gl_lightmode = Cvar_Get ("gl_lightmode", "1", CVAR_ARCHIVE, gl_lightmode_callback, "Lighting mode (0 = GLQuake style, 1 = new style)");
-	gl_max_size = Cvar_Get ("gl_max_size", "1024", CVAR_NONE, NULL, "Texture dimension"); 
-	gl_nocolors = Cvar_Get ("gl_nocolors", "0", CVAR_NONE, NULL, "None");
-	gl_picmip = Cvar_Get ("gl_picmip", "0", CVAR_NONE, NULL, "Dimensions of displayed textures. 0 is normal, 1 is half, 2 is 1/4"); 
-	gl_playermip = Cvar_Get ("gl_playermip", "0", CVAR_NONE, NULL, "None");
-	gl_polyblend = Cvar_Get ("gl_polyblend", "1", CVAR_NONE, NULL, "None");
+	gl_lightmap_components =
+		Cvar_Get ("gl_lightmap_components", "4", CVAR_ROM, NULL,
+				  "Lightmap texture components. 1 is greyscale, 3 is RGB, 4 is RGBA.");
+	gl_lightmode =
+		Cvar_Get ("gl_lightmode", "1", CVAR_ARCHIVE, gl_lightmode_callback,
+				  "Lighting mode (0 = GLQuake style, 1 = new style)");
+	gl_max_size = Cvar_Get ("gl_max_size", "1024", CVAR_NONE, NULL,
+							"Texture dimension"); 
+	gl_nocolors = Cvar_Get ("gl_nocolors", "0", CVAR_NONE, NULL,
+							"Set to 1, turns off all player colors");
+	gl_picmip = Cvar_Get ("gl_picmip", "0", CVAR_NONE, NULL,
+						  "Dimensions of displayed textures. 0 is normal, 1 is half, 2 is 1/4"); 
+	gl_playermip = Cvar_Get ("gl_playermip", "0", CVAR_NONE, NULL,
+							 "Detail of player skins. 0 best, 4 worst.");
 	gl_reporttjunctions = Cvar_Get ("gl_reporttjunctions", "0", CVAR_NONE, NULL, "None");
-	gl_skymultipass = Cvar_Get ("gl_skymultipass", "1", CVAR_NONE, NULL, "controls wether the skydome is single or double pass");
+	gl_sky_clip = 
+        Cvar_Get ("gl_sky_clip", "0", CVAR_ARCHIVE, NULL, 
+                  "controls whether sky is drawn first (0) or later (1)"); 
+	gl_skymultipass = Cvar_Get ("gl_skymultipass", "1", CVAR_NONE, NULL,
+								"controls wether the skydome is single or double pass");
 	gl_smoothmodels = Cvar_Get ("gl_smoothmodels", "1", CVAR_NONE, NULL, "None");
 	gl_texsort = Cvar_Get ("gl_texsort", "1", CVAR_NONE, NULL, "None");
 	gl_triplebuffer = Cvar_Get ("gl_triplebuffer", "1", CVAR_ARCHIVE, NULL, "Set to 1 by default. Fixes status bar flicker on some hardware");
diff --git a/qw/source/gl_rmain.c b/qw/source/gl_rmain.c
index 9cbad6144..0d5fe1c57 100644
--- a/qw/source/gl_rmain.c
+++ b/qw/source/gl_rmain.c
@@ -76,9 +76,7 @@ qboolean	envmap;						// true during envmap command capture
 int 	playertextures;				// up to 16 color translated skins
 int 	player_fb_textures;			// up to 128 skin fullbright maps
 
-//
 // view origin
-//
 vec3_t	vup;
 vec3_t	vpn;
 vec3_t	vright;
@@ -87,16 +85,13 @@ vec3_t	r_origin;
 float	r_world_matrix[16];
 float	r_base_world_matrix[16];
 
-//
 // screen size info
-//
 refdef_t	r_refdef;
 
 mleaf_t *r_viewleaf, *r_oldviewleaf;
 
 int 	d_lightstylevalue[256];		// 8.8 fraction of base light value
 
-
 vec3_t	shadecolor;					// Ender (Extend) Colormod
 float	modelalpha;					// Ender (EXtend) Alpha
 
@@ -107,29 +102,13 @@ extern cvar_t *scr_fov;
 extern byte gammatable[256];
 extern qboolean lighthalf;
 
+
 // LordHavoc: place for gl_rmain setup code
 void
 glrmain_init (void)
 {
 }
 
-/*
-	R_CullBox
-
-	Returns true if the box is completely outside the frustum
-*/
-/*
-qboolean R_CullBox (vec3_t mins, vec3_t maxs)
-{
-	int		i;
-
-	for (i=0 ; i<4 ; i++)
-		if (BoxOnPlaneSide (mins, maxs, &frustum[i]) == 2)
-			return true;
-	return false;
-}
-*/
-
 
 void
 R_RotateForEntity (entity_t *e)
@@ -257,18 +236,14 @@ float	shadelight;
 // precalculated dot products for quantized angles
 #define SHADEDOT_QUANT 16
 float	r_avertexnormal_dots[SHADEDOT_QUANT][256] =
-#include "anorm_dots.h"
-           ;
+	#include "anorm_dots.h"
+		;
 
-float	*shadedots = r_avertexnormal_dots[0];
+float  *shadedots = r_avertexnormal_dots[0];
 
 int 	lastposenum, lastposenum0;
 
-/*
-	GL_DrawAliasFrame
 
-	Standard model drawing
-*/
 static void
 GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum, qboolean fb)
 {
@@ -286,7 +261,7 @@ GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum, qboolean fb)
 	if (modelalpha != 1.0)
 		glDepthMask (GL_FALSE);
 
-	if (fb) {	// don't do this in the loop, it doesn't change
+	if (fb) {
 		if (lighthalf)
 			glColor4f (0.5, 0.5, 0.5, modelalpha);
 		else
@@ -406,13 +381,14 @@ GL_DrawAliasBlendedFrame (aliashdr_t *paliashdr, int pose1, int pose2, float ble
 
 }
 
+
+extern vec3_t lightspot;
+
 /*
 	GL_DrawAliasShadow
 
 	Standard shadow drawing
 */
-extern vec3_t lightspot;
-
 static void
 GL_DrawAliasShadow (aliashdr_t *paliashdr, int posenum)
 {
@@ -446,9 +422,15 @@ GL_DrawAliasShadow (aliashdr_t *paliashdr, int posenum)
 			order += 2;
 
 			// normals and vertexes come from the frame list
-			point[0] = verts->v[0] * paliashdr->mdl.scale[0] + paliashdr->mdl.scale_origin[0];
-			point[1] = verts->v[1] * paliashdr->mdl.scale[1] + paliashdr->mdl.scale_origin[1];
-			point[2] = verts->v[2] * paliashdr->mdl.scale[2] + paliashdr->mdl.scale_origin[2];
+			point[0] =
+				verts->v[0] * paliashdr->mdl.scale[0] +
+				paliashdr->mdl.scale_origin[0];
+			point[1] =
+				verts->v[1] * paliashdr->mdl.scale[1] +
+				paliashdr->mdl.scale_origin[1];
+			point[2] =
+				verts->v[2] * paliashdr->mdl.scale[2] +
+				paliashdr->mdl.scale_origin[2];
 
 			point[0] -= shadevector[0] * (point[2] + lheight);
 			point[1] -= shadevector[1] * (point[2] + lheight);
@@ -463,6 +445,7 @@ GL_DrawAliasShadow (aliashdr_t *paliashdr, int posenum)
 	}
 }
 
+
 /*
 	GL_DrawAliasBlendedShadow
          
@@ -572,7 +555,7 @@ R_SetupAliasBlendedFrame (int frame, aliashdr_t *paliashdr, entity_t *e, qboolea
 		pose += (int) (cl.time / e->frame_interval) % numposes;
 	} else {
 		/*
-			One tenth of a second is a good for most Quake animations. If the
+			One tenth of a second is good for most Quake animations. If the
 			nextthink is longer then the animation is usually meant to pause
 			(e.g. check out the shambler magic animation in shambler.qc).  If
 			its shorter then things will still be smoothed partly, and the
@@ -594,7 +577,6 @@ R_SetupAliasBlendedFrame (int frame, aliashdr_t *paliashdr, entity_t *e, qboolea
 	} else {
 		blend = (realtime - e->frame_start_time) / e->frame_interval;
 	}
-	// Con_DPrintf ("numposes: %d, poses: %d %d\n", numposes, e->pose1, e->pose2);
 
 	// wierd things start happening if blend passes 1
 	if (cl.paused || blend > 1)
@@ -799,7 +781,6 @@ R_DrawAliasModel (entity_t *e)
 	}
 }
 
-//==================================================================================
 
 /*
 	R_ShowNearestLoc
@@ -1046,9 +1027,7 @@ R_SetupGL (void)
 
 	glGetFloatv (GL_MODELVIEW_MATRIX, r_world_matrix);
 
-	// 
 	// set drawing parms
-	// 
 	glEnable (GL_CULL_FACE);
 	glDisable (GL_ALPHA_TEST);
 	glAlphaFunc (GL_GREATER, 0.5);
diff --git a/qw/source/gl_rmisc.c b/qw/source/gl_rmisc.c
index 98852ae59..3d4afb367 100644
--- a/qw/source/gl_rmisc.c
+++ b/qw/source/gl_rmisc.c
@@ -54,19 +54,16 @@
 
 varray_t2f_c4f_v3f_t varray[MAX_VARRAY_VERTS];
 
-qboolean VID_Is8bit (void);
-void R_InitBubble (void);
+qboolean    VID_Is8bit (void);
+qboolean	allowskybox;				// allow skyboxes?  --KB
+void        R_InitBubble (void);
 
 extern cvar_t	*gl_lerp_anim;
-
 extern cvar_t	*r_netgraph;
 
 extern void GDT_Init ();
-qboolean	allowskybox;				// allow skyboxes?  --KB
 
-/*
-	R_Textures_Init
-*/
+
 void
 R_Textures_Init (void)
 {
@@ -98,6 +95,7 @@ R_Textures_Init (void)
 	}
 }
 
+
 /*
 	R_Envmap_f
 
@@ -163,9 +161,7 @@ R_Envmap_f (void)
 	GL_EndRendering ();
 }
 
-/*
-   R_LoadSky_f
-*/
+
 void
 R_LoadSky_f (void)
 {
@@ -178,18 +174,17 @@ R_LoadSky_f (void)
 }
 
 
-/*
-	R_Init
-*/
 void
 R_Init (void)
 {
 	allowskybox = false;				// server will decide if this is
 										// allowed  --KB
 
-	Cmd_AddCommand ("timerefresh", R_TimeRefresh_f, "Tests the current refresh rate for the current location");
-	Cmd_AddCommand ("envmap", R_Envmap_f, "FIXME: What on earth does this do? No Description");
-	Cmd_AddCommand ("pointfile", R_ReadPointFile_f, "Load a pointfile to determine map leaks");
+	Cmd_AddCommand ("timerefresh", R_TimeRefresh_f,
+					"Tests the current refresh rate for the current location");
+	Cmd_AddCommand ("envmap", R_Envmap_f, "No Description");
+	Cmd_AddCommand ("pointfile", R_ReadPointFile_f,
+					"Load a pointfile to determine map leaks");
 	Cmd_AddCommand ("loadsky", R_LoadSky_f, "Load a skybox");
 
 	R_InitBubble ();
@@ -214,9 +209,7 @@ R_Init (void)
 	glVertexPointer (3, GL_FLOAT, sizeof(varray[0]), varray[0].vertex);
 }
 
-/*
-	R_NewMap
-*/
+
 void
 R_NewMap (void)
 {
@@ -229,7 +222,7 @@ R_NewMap (void)
 	memset (&r_worldentity, 0, sizeof (r_worldentity));
 	r_worldentity.model = cl.worldmodel;
 
-// clear out efrags in case the level hasn't been reloaded
+	// clear out efrags in case the level hasn't been reloaded
 	for (i = 0; i < cl.worldmodel->numleafs; i++)
 		cl.worldmodel->leafs[i].efrags = NULL;
 
@@ -267,7 +260,6 @@ R_TimeRefresh_f (void)
 	int         i;
 	double      start, stop, time;
 
-//  glDrawBuffer  (GL_FRONT);
 	glFinish ();
 	GL_EndRendering ();
 
@@ -280,13 +272,10 @@ R_TimeRefresh_f (void)
 		GL_EndRendering ();
 	}
 
-//  glFinish ();
 	stop = Sys_DoubleTime ();
 	time = stop - start;
 	Con_Printf ("%f seconds (%f fps)\n", time, 128 / time);
 
-//  glDrawBuffer  (GL_BACK);
-//  GL_EndRendering ();
 	GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
 }
 
diff --git a/qw/source/gl_rsurf.c b/qw/source/gl_rsurf.c
index 2f15029af..a0ed9c1d5 100644
--- a/qw/source/gl_rsurf.c
+++ b/qw/source/gl_rsurf.c
@@ -49,12 +49,13 @@
 #include "r_local.h"
 #include "r_shared.h"
 
-qboolean    r_cache_thrash;
+qboolean	r_cache_thrash;
 
 extern double realtime;
-int         skytexturenum;
+int			skytexturenum;
 
 extern vec3_t shadecolor;				// Ender (Extend) Colormod
+
 int         lightmap_bytes;				// 1, 3, or 4
 int         lightmap_textures;
 
@@ -168,14 +169,16 @@ R_AddDynamicLights (msurface_t *surf)
 			impact[i] =
 				cl_dlights[lnum].origin[i] - surf->plane->normal[i] * dist;
 
-		i = f =	DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
+		i = f =	DotProduct (impact,	surf->texinfo->vecs[0]) +
+			surf->texinfo->vecs[0][3] - surf->texturemins[0];
 
 		// reduce calculations
 		t = dist * dist;
 		for (s = 0; s < smax; s++, i -= 16)
 			sdtable[s] = i * i + t;
 
-		i = f = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
+		i = f =	DotProduct (impact,	surf->texinfo->vecs[1]) +
+			surf->texinfo->vecs[1][3] - surf->texturemins[1];
 
 		// for comparisons to minimum acceptable light
 		maxdist = (int) ((cl_dlights[lnum].radius * cl_dlights[lnum].radius) * 0.75);
@@ -268,9 +271,9 @@ R_BuildLightMap (msurface_t *surf, byte * dest, int stride)
 	bl = blocklights;
 
 	if (gl_mtex_active && !lighthalf) {
-		shift = 7;	// 0-1 lightmap range.
+		shift = 7;      // 0-1 lightmap range.
 	} else {
-		shift = 8;	// 0-2 lightmap range.
+		shift = 8;      // 0-2 lightmap range.
 	}
 
 	switch (lightmap_bytes) {
@@ -360,11 +363,10 @@ extern float speedscale;				// for top sky and bottom sky
 void
 GL_UploadLightmap (int i, int x, int y, int w, int h)
 {
-	/*
-	glTexSubImage2D (GL_TEXTURE_2D, 0, 0, y, BLOCK_WIDTH, h, gl_lightmap_format,
+/*	glTexSubImage2D (GL_TEXTURE_2D, 0, 0, y, BLOCK_WIDTH, h, gl_lightmap_format,
 					 GL_UNSIGNED_BYTE,
 					 lightmaps[i] + (y * BLOCK_WIDTH) * lightmap_bytes);
-					 */
+*/
 	glTexImage2D (GL_TEXTURE_2D, 0, lightmap_bytes, BLOCK_WIDTH,
 				  BLOCK_HEIGHT, 0, gl_lightmap_format,
 				  GL_UNSIGNED_BYTE, lightmaps[i]);
@@ -407,7 +409,7 @@ R_DrawMultitexturePoly (msurface_t *s)
 			if (d_lightstylevalue[s->styles[maps]] != s->cached_light[maps])
 				goto dynamic;
 
-		if ((s->dlightframe = r_framecount) || s->cached_dlight) {
+		if ((s->dlightframe == r_framecount) || s->cached_dlight)	{
 		  dynamic:
 			R_BuildLightMap (s,
 							 lightmaps[s->lightmaptexturenum] +
@@ -448,7 +450,7 @@ R_BlendLightmaps (void)
 	glpoly_t   *p;
 	float      *v;
 
-	glDepthMask (GL_FALSE);				// don't bother writing Z
+	glDepthMask (GL_FALSE);					// don't bother writing Z
 
 	if (lighthalf)
 		glBlendFunc (GL_ZERO, GL_SRC_COLOR);
@@ -484,7 +486,7 @@ R_BlendLightmaps (void)
 	glColor3ubv (lighthalf_v);
 	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
-	glDepthMask (GL_TRUE);				// back to normal Z buffering
+	glDepthMask (GL_TRUE);					// back to normal Z buffering
 }
 
 
@@ -574,9 +576,8 @@ R_RenderBrushPoly (msurface_t *fa)
 			if ((theRect->h + theRect->t) < (fa->light_t + tmax))
 				theRect->h = (fa->light_t - theRect->t) + tmax;
 			base =
-				lightmaps[fa->lightmaptexturenum] + (fa->light_t * BLOCK_WIDTH +
-													 fa->light_s) *
-				lightmap_bytes;
+				lightmaps[fa->lightmaptexturenum] +
+				(fa->light_t * BLOCK_WIDTH + fa->light_s) * lightmap_bytes;
 			R_BuildLightMap (fa, base, BLOCK_WIDTH * lightmap_bytes);
 		}
 	}
@@ -616,7 +617,6 @@ R_DrawWaterSurfaces (void)
 		return;
 
 	// go back to the world matrix
-
 	glLoadMatrixf (r_world_matrix);
 
 	if (r_wateralpha->value < 1.0) {
@@ -739,6 +739,11 @@ R_DrawBrushModel (entity_t *e)
 
 	// draw texture
 	for (i = 0; i < clmodel->nummodelsurfaces; i++, psurf++) {
+/* FIXME: Not in qw?
+		if (psurf->flags & SURF_DRAWSKY)
+			return;
+*/
+
 		// find which side of the node we are on
 		pplane = psurf->plane;
 
@@ -747,7 +752,6 @@ R_DrawBrushModel (entity_t *e)
 		// draw the polygon
 		if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
 			(!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) {
-
 			if (psurf->flags & SURF_DRAWTURB) {
 				GL_WaterSurface (psurf);
 			} else if (psurf->flags & SURF_DRAWSKY) {
@@ -789,9 +793,8 @@ R_RecursiveWorldNode (mnode_t *node)
 	mleaf_t    *pleaf;
 	double      dot;
 
-	if (node->contents == CONTENTS_SOLID)	// solid
+	if (node->contents == CONTENTS_SOLID)
 		return;
-
 	if (node->visframe != r_visframecount)
 		return;
 	if (R_CullBox (node->minmaxs, node->minmaxs + 3))
@@ -860,7 +863,6 @@ R_RecursiveWorldNode (mnode_t *node)
 			if ((dot < 0) ^ !!(surf->flags & SURF_PLANEBACK))
 				continue;				// wrong side
 
-
 			if (surf->flags & SURF_DRAWTURB) {
 				surf->texturechain = waterchain;
 				waterchain = surf;
@@ -958,7 +960,7 @@ R_MarkLeaves (void)
 
 
 /*
-	LIGHTMAP ALLOCATION
+  LIGHTMAP ALLOCATION
 */
 
 
@@ -1009,7 +1011,6 @@ AllocBlock (int w, int h, int *x, int *y)
 
 mvertex_t  *r_pcurrentvertbase;
 model_t    *currentmodel;
-
 int         nColinElim;
 
 
@@ -1029,7 +1030,8 @@ BuildSurfaceDisplayList (msurface_t *fa)
 	vertpage = 0;
 
 	// draw texture
-	poly = Hunk_Alloc (sizeof (glpoly_t) + (lnumverts - 4) * VERTEXSIZE * sizeof (float));
+	poly = Hunk_Alloc (sizeof (glpoly_t) + (lnumverts - 4) *
+					   VERTEXSIZE * sizeof (float));
 	poly->next = fa->polys;
 	poly->flags = fa->flags;
 	fa->polys = poly;
@@ -1108,7 +1110,6 @@ BuildSurfaceDisplayList (msurface_t *fa)
 		}
 	}
 	poly->numverts = lnumverts;
-
 }
 
 
@@ -1124,8 +1125,10 @@ GL_CreateSurfaceLightmap (msurface_t *surf)
 	smax = (surf->extents[0] >> 4) + 1;
 	tmax = (surf->extents[1] >> 4) + 1;
 
-	surf->lightmaptexturenum = AllocBlock (smax, tmax, &surf->light_s, &surf->light_t);
-	base = lightmaps[surf->lightmaptexturenum] + (surf->light_t * BLOCK_WIDTH + surf->light_s) * lightmap_bytes;
+	surf->lightmaptexturenum =
+		AllocBlock (smax, tmax, &surf->light_s, &surf->light_t);
+	base = lightmaps[surf->lightmaptexturenum] +
+		(surf->light_t * BLOCK_WIDTH + surf->light_s) * lightmap_bytes;
 	R_BuildLightMap (surf, base, BLOCK_WIDTH * lightmap_bytes);
 }
 
diff --git a/qw/source/r_cvar.c b/qw/source/r_cvar.c
index 9388b965c..d313264a4 100644
--- a/qw/source/r_cvar.c
+++ b/qw/source/r_cvar.c
@@ -19,8 +19,6 @@ cvar_t     *gl_conalpha;
 cvar_t     *gl_conspin;
 cvar_t     *gl_constretch;
 cvar_t     *gl_dlight_lightmap;
-cvar_t     *gl_dlight_lightmap;
-cvar_t     *gl_dlight_polyblend;
 cvar_t     *gl_dlight_polyblend;
 cvar_t     *gl_dlight_smooth;
 cvar_t     *gl_fb_bmodels;
@@ -44,18 +42,15 @@ cvar_t     *r_aliastransbase;
 cvar_t     *r_ambient;
 cvar_t     *r_clearcolor;
 cvar_t     *r_drawentities;
-cvar_t     *r_drawentities;
 cvar_t     *r_drawflat;
 cvar_t     *r_draworder;
 cvar_t     *r_drawviewmodel;
-cvar_t     *r_drawviewmodel;
 cvar_t     *r_dspeeds;
 cvar_t     *r_dynamic;
 cvar_t     *r_graphheight;
 cvar_t     *r_maxedges;
 cvar_t     *r_maxsurfs;
 cvar_t     *r_netgraph;
-cvar_t     *r_netgraph;
 cvar_t     *r_netgraph_alpha;
 cvar_t     *r_netgraph_box;
 cvar_t     *r_norefresh;
@@ -63,13 +58,11 @@ cvar_t     *r_novis;
 cvar_t     *r_numedges;
 cvar_t     *r_numsurfs;
 cvar_t     *r_particles;
-cvar_t     *r_particles;
 cvar_t     *r_reportedgeout;
 cvar_t     *r_reportsurfout;
 cvar_t     *r_shadows;
 cvar_t     *r_skyname;
 cvar_t     *r_speeds;
-cvar_t     *r_speeds;
 cvar_t     *r_timegraph;
 cvar_t     *r_wateralpha;
 cvar_t     *r_waterripple;
@@ -118,35 +111,27 @@ R_Init_Cvars (void)
 	crosshair =
 		Cvar_Get ("crosshair", "0", CVAR_ARCHIVE, NULL,
 				  "Crosshair type. 0 off, 1 old without color, 2 new with colors");
-	crosshaircolor =
-		Cvar_Get ("crosshaircolor", "79", CVAR_ARCHIVE, NULL,
-				  "Color of the new crosshair");
-
-	d_mipcap =
-		Cvar_Get ("d_mipcap", "0", CVAR_NONE, NULL,
-				  "Detail level. 0 is highest, 3 is lowest.");
+	crosshaircolor = Cvar_Get ("crosshaircolor", "79", CVAR_ARCHIVE, NULL,
+							   "Color of the new crosshair");
+	d_mipcap = Cvar_Get ("d_mipcap", "0", CVAR_NONE, NULL,
+						 "Detail level. 0 is highest, 3 is lowest.");
 	d_mipscale =
 		Cvar_Get ("d_mipscale", "1", CVAR_NONE, NULL,
 				  "Detail level of objects. 0 is highest, 3 is lowest.");
 	d_subdiv16 =
 		Cvar_Get ("d_subdiv16", "1", CVAR_NONE, NULL,
 				  "Set to enable extreme perspective correction");
-
 	gl_affinemodels =
 		Cvar_Get ("gl_affinemodels", "0", CVAR_ARCHIVE, NULL,
 				  "Makes texture rendering quality better if set to 1");
-	gl_clear =
-		Cvar_Get ("gl_clear", "0", CVAR_NONE, NULL,
-				  "Set to 1 to make background black. Useful for removing HOM effect");
-	gl_conalpha =
-		Cvar_Get ("gl_conalpha", "0.6", CVAR_ARCHIVE, NULL,
-				  "alpha value for the console background");
-	gl_conspin =
-		Cvar_Get ("gl_conspin", "0", CVAR_ARCHIVE, NULL,
-				  "speed at which the console spins");
-	gl_constretch =
-		Cvar_Get ("gl_constretch", "0", CVAR_ARCHIVE, NULL,
-				  "whether slide the console or stretch it");
+	gl_clear = Cvar_Get ("gl_clear", "0", CVAR_NONE, NULL,
+						 "Set to 1 to make background black. Useful for removing HOM effect");
+	gl_conalpha = Cvar_Get ("gl_conalpha", "0.6", CVAR_ARCHIVE, NULL,
+							"alpha value for the console background");
+	gl_conspin = Cvar_Get ("gl_conspin", "0", CVAR_ARCHIVE, NULL,
+						   "speed at which the console spins");
+	gl_constretch = Cvar_Get ("gl_constretch", "0", CVAR_ARCHIVE, NULL,
+							  "whether slide the console or stretch it");
 	gl_dlight_lightmap =
 		Cvar_Get ("gl_dlight_lightmap", "1", CVAR_ARCHIVE, NULL,
 				  "Set to 1 for high quality dynamic lighting.");
@@ -177,11 +162,10 @@ R_Init_Cvars (void)
 	gl_lightmode =
 		Cvar_Get ("gl_lightmode", "1", CVAR_ARCHIVE, gl_lightmode_callback,
 				  "Lighting mode (0 = GLQuake style, 1 = new style)");
-	gl_max_size =
-		Cvar_Get ("gl_max_size", "1024", CVAR_NONE, NULL, "Texture dimension");
-	gl_nocolors =
-		Cvar_Get ("gl_nocolors", "0", CVAR_NONE, NULL,
-				  "Set to 1, turns off all player colors");
+	gl_max_size = Cvar_Get ("gl_max_size", "1024", CVAR_NONE, NULL,
+							"Texture dimension");
+	gl_nocolors = Cvar_Get ("gl_nocolors", "0", CVAR_NONE, NULL,
+							"Set to 1, turns off all player colors");
 	gl_picmip =
 		Cvar_Get ("gl_picmip", "0", CVAR_NONE, NULL,
 				  "Dimensions of displayed textures. 0 is normal, 1 is half, 2 is 1/4");
@@ -194,9 +178,6 @@ R_Init_Cvars (void)
 	gl_sky_divide =
 		Cvar_Get ("gl_sky_divide", "1", CVAR_ARCHIVE, NULL,
 				  "subdivide sky polys");
-	gl_sky_divide =
-		Cvar_Get ("gl_sky_divide", "1", CVAR_ARCHIVE, NULL,
-				  "subdivide sky polys");
 	gl_skymultipass =
 		Cvar_Get ("gl_skymultipass", "1", CVAR_ARCHIVE, NULL,
 				  "controls whether the skydome is single or double pass");