- if (!r_render.value)
- return;
- //
- // set up viewpoint
- //
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity ();
- x = r_refdef.vrect.x * glwidth/vid.width;
- x2 = (r_refdef.vrect.x + r_refdef.vrect.width) * glwidth/vid.width;
- y = (vid.height-r_refdef.vrect.y) * glheight/vid.height;
- y2 = (vid.height - (r_refdef.vrect.y + r_refdef.vrect.height)) * glheight/vid.height;
-
- // fudge around because of frac screen scale
- if (x > 0)
- x--;
- if (x2 < glwidth)
- x2++;
- if (y2 < 0)
- y2--;
- if (y < glheight)
- y++;
-
- w = x2 - x;
- h = y - y2;
-
- if (envmap)
- {
- x = y2 = 0;
- w = h = 256;
- }
-
- glViewport (glx + x, gly + y2, w, h);
- screenaspect = (float)r_refdef.vrect.width/r_refdef.vrect.height;
-// yfov = 2*atan((float)r_refdef.vrect.height/r_refdef.vrect.width)*180/M_PI;
-// if (skyname[0]) // skybox enabled?
-// MYgluPerspective (r_refdef.fov_y, screenaspect, 4, r_skyboxsize.value*1.732050807569 + 256); // this is size*sqrt(3) + 256
-// else
- MYgluPerspective (r_refdef.fov_y, screenaspect, 4, r_farclip.value);
-
- glCullFace(GL_FRONT);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity ();
-
- glRotatef (-90, 1, 0, 0); // put Z going up
- glRotatef (90, 0, 0, 1); // put Z going up
- glRotatef (-r_refdef.viewangles[2], 1, 0, 0);
- glRotatef (-r_refdef.viewangles[0], 0, 1, 0);
- glRotatef (-r_refdef.viewangles[1], 0, 0, 1);
- glTranslatef (-r_refdef.vieworg[0], -r_refdef.vieworg[1], -r_refdef.vieworg[2]);
-
- glGetFloatv (GL_MODELVIEW_MATRIX, r_world_matrix);
-
- //
- // set drawing parms
- //
-// if (gl_cull.value)
- glEnable(GL_CULL_FACE);
-// else
-// glDisable(GL_CULL_FACE);
-
- glEnable(GL_BLEND); // was Disable
- glDisable(GL_ALPHA_TEST);
- glAlphaFunc(GL_GREATER, 0.5);
- glEnable(GL_DEPTH_TEST);
- glDepthMask(1);
- glShadeModel(GL_SMOOTH);
+ if (!visiblevolumes)
+ R_Shadow_Stage_ShadowVolumes();
+ ent = &cl_entities[0].render;
+ R_TestAndDrawShadowVolume(ent, rd->origin, cullradius, lightradius, clipmins, clipmaxs, clipmins, clipmaxs);
+ if (r_drawentities.integer)
+ {
+ for (i = 0;i < r_refdef.numentities;i++)
+ {
+ ent = r_refdef.entities[i];
+ if (ent != rd->ent)
+ R_TestAndDrawShadowVolume(ent, rd->origin, cullradius, lightradius, clipmins, clipmaxs, clipmins, clipmaxs);
+ }
+ }
+
+ if (!visiblevolumes)
+ {
+ R_Shadow_Stage_LightWithShadows();
+ ent = &cl_entities[0].render;
+ if (ent->model && ent->model->DrawLight)
+ {
+ Matrix4x4_Transform(&ent->inversematrix, rd->origin, relativelightorigin);
+ Matrix4x4_Transform(&ent->inversematrix, r_origin, relativeeyeorigin);
+ ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor);
+ }
+ if (r_drawentities.integer)
+ {
+ for (i = 0;i < r_refdef.numentities;i++)
+ {
+ ent = r_refdef.entities[i];
+ if (ent->visframe == r_framecount && ent->model && ent->model->DrawLight
+ && !(ent->effects & EF_ADDITIVE) && ent->alpha == 1)
+ {
+ Matrix4x4_Transform(&ent->inversematrix, rd->origin, relativelightorigin);
+ Matrix4x4_Transform(&ent->inversematrix, r_origin, relativeeyeorigin);
+ ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor);
+ }
+ }
+ }
+ }
+ }
+
+ if (!visiblevolumes)
+ R_Shadow_Stage_End();
+ qglEnable(GL_CULL_FACE);
+ qglDisable(GL_SCISSOR_TEST);
+}
+
+static void R_SetFrustum (void)
+{
+ // LordHavoc: note to all quake engine coders, the special case for 90
+ // degrees assumed a square view (wrong), so I removed it, Quake2 has it
+ // disabled as well.
+
+ // rotate VPN right by FOV_X/2 degrees
+ RotatePointAroundVector( frustum[0].normal, vup, vpn, -(90-r_refdef.fov_x / 2 ) );
+ frustum[0].dist = DotProduct (r_origin, frustum[0].normal);
+ PlaneClassify(&frustum[0]);
+
+ // rotate VPN left by FOV_X/2 degrees
+ RotatePointAroundVector( frustum[1].normal, vup, vpn, 90-r_refdef.fov_x / 2 );
+ frustum[1].dist = DotProduct (r_origin, frustum[1].normal);
+ PlaneClassify(&frustum[1]);
+
+ // rotate VPN up by FOV_X/2 degrees
+ RotatePointAroundVector( frustum[2].normal, vright, vpn, 90-r_refdef.fov_y / 2 );
+ frustum[2].dist = DotProduct (r_origin, frustum[2].normal);
+ PlaneClassify(&frustum[2]);
+
+ // rotate VPN down by FOV_X/2 degrees
+ RotatePointAroundVector( frustum[3].normal, vright, vpn, -( 90 - r_refdef.fov_y / 2 ) );
+ frustum[3].dist = DotProduct (r_origin, frustum[3].normal);
+ PlaneClassify(&frustum[3]);