]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
added radius and radius2 (squared radius) fields to model structure
[xonotic/darkplaces.git] / gl_rmain.c
index 024c1172c55171bf12c22291d33bef543f988795..b989580bc93c1592e6a20976bf1ecdcd4660a152 100644 (file)
@@ -51,6 +51,7 @@ 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_speeds = {0, "r_speeds","0"};
 cvar_t r_fullbright = {0, "r_fullbright","0"};
 cvar_t r_wateralpha = {CVAR_SAVE, "r_wateralpha","1"};
@@ -218,6 +219,7 @@ void GL_Main_Init(void)
        Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);
        Cvar_RegisterVariable (&r_drawentities);
        Cvar_RegisterVariable (&r_drawviewmodel);
+       Cvar_RegisterVariable (&r_shadows);
        Cvar_RegisterVariable (&r_speeds);
        Cvar_RegisterVariable (&r_fullbrights);
        Cvar_RegisterVariable (&r_wateralpha);
@@ -289,10 +291,10 @@ extern void R_Particles_Init(void);
 extern void R_Explosion_Init(void);
 extern void ui_init(void);
 extern void gl_backend_init(void);
+extern void Sbar_Init(void);
 
 void Render_Init(void)
 {
-       R_Modules_Shutdown();
        R_Textures_Init();
        Mod_RenderInit();
        gl_backend_init();
@@ -307,7 +309,7 @@ void Render_Init(void)
        R_Particles_Init();
        R_Explosion_Init();
        ui_init();
-       R_Modules_Start();
+       Sbar_Init();
 }
 
 /*
@@ -459,9 +461,6 @@ static void R_MarkEntities (void)
                        VectorAdd(ent->angles, r_refdef.viewangles, ent->angles);
                }
 
-               if (R_CullBox(ent->mins, ent->maxs))
-                       continue;
-
                ent->visframe = r_framecount;
                VectorCopy(ent->angles, v);
                if (!ent->model || ent->model->type != mod_brush)
@@ -470,6 +469,8 @@ static void R_MarkEntities (void)
                Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
                R_LerpAnimation(ent);
                R_UpdateEntLights(ent);
+               if (R_CullBox(ent->mins, ent->maxs))
+                       continue;
                R_FarClip_Box(ent->mins, ent->maxs);
        }
 }
@@ -544,6 +545,22 @@ void R_DrawModels (void)
        }
 }
 
+void R_DrawModelFakeShadows (void)
+{
+       int i;
+       entity_render_t *ent;
+
+       if (!r_drawentities.integer)
+               return;
+
+       for (i = 0;i < r_refdef.numentities;i++)
+       {
+               ent = r_refdef.entities[i];
+               if (ent->model && ent->model->DrawFakeShadow)
+                       ent->model->DrawFakeShadow(ent);
+       }
+}
+
 static void R_SetFrustum (void)
 {
        int i;
@@ -606,7 +623,6 @@ static void R_BlendView(void)
        memset(&m, 0, sizeof(m));
        m.blendfunc1 = GL_SRC_ALPHA;
        m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
-       m.wantoverbright = false;
        m.depthdisable = true; // magic
        R_Mesh_Matrix(&r_identitymatrix);
        R_Mesh_State(&m);
@@ -661,7 +677,12 @@ void R_RenderView (void)
        r_farclip = R_FarClip_Finish() + 256.0f;
        R_TimeReport("markentity");
 
-       R_Mesh_Start(r_farclip);
+       GL_SetupView_ViewPort(r_refdef.x, r_refdef.y, r_refdef.width, r_refdef.height);
+       GL_SetupView_Mode_Perspective((double) r_refdef.height / r_refdef.width, r_refdef.fov_x, r_refdef.fov_y, 1.0f, r_farclip);
+       GL_SetupView_Orientation_FromEntity (r_refdef.vieworg, r_refdef.viewangles);
+       GL_DepthFunc(GL_LEQUAL);
+       
+       R_Mesh_Start();
        R_MeshQueue_BeginScene();
 
        if (R_DrawBrushModelsSky())
@@ -675,6 +696,12 @@ void R_RenderView (void)
        if (!intimerefresh && !r_speeds.integer)
                S_ExtraUpdate ();
 
+       if (r_shadows.integer)
+       {
+               R_DrawModelFakeShadows();
+               R_TimeReport("fakeshadows");
+       }
+
        R_DrawModels();
        R_TimeReport("models");
 
@@ -690,7 +717,7 @@ void R_RenderView (void)
        R_DrawCoronas();
        R_TimeReport("coronas");
 
-       R_DrawCrosshair();
+       R_DrawWorldCrosshair();
        R_TimeReport("crosshair");
 
        R_BlendView();
@@ -710,7 +737,6 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa
        rmeshstate_t m;
        m.blendfunc1 = GL_SRC_ALPHA;
        m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
-       m.wantoverbright = false;
        R_Mesh_Matrix(&r_identitymatrix);
        R_Mesh_State(&m);
 
@@ -722,9 +748,9 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa
        varray_vertex[20] = maxs[0];varray_vertex[21] = mins[1];varray_vertex[22] = maxs[2];
        varray_vertex[24] = mins[0];varray_vertex[25] = maxs[1];varray_vertex[26] = maxs[2];
        varray_vertex[28] = maxs[0];varray_vertex[29] = maxs[1];varray_vertex[30] = maxs[2];
-       varray_color[ 0] = varray_color[ 4] = varray_color[ 8] = varray_color[12] = varray_color[16] = varray_color[20] = varray_color[24] = varray_color[28] = cr * mesh_colorscale;
-       varray_color[ 1] = varray_color[ 5] = varray_color[ 9] = varray_color[13] = varray_color[17] = varray_color[21] = varray_color[25] = varray_color[29] = cg * mesh_colorscale;
-       varray_color[ 2] = varray_color[ 6] = varray_color[10] = varray_color[14] = varray_color[18] = varray_color[22] = varray_color[26] = varray_color[30] = cb * mesh_colorscale;
+       varray_color[ 0] = varray_color[ 4] = varray_color[ 8] = varray_color[12] = varray_color[16] = varray_color[20] = varray_color[24] = varray_color[28] = cr * r_colorscale;
+       varray_color[ 1] = varray_color[ 5] = varray_color[ 9] = varray_color[13] = varray_color[17] = varray_color[21] = varray_color[25] = varray_color[29] = cg * r_colorscale;
+       varray_color[ 2] = varray_color[ 6] = varray_color[10] = varray_color[14] = varray_color[18] = varray_color[22] = varray_color[26] = varray_color[30] = cb * r_colorscale;
        varray_color[ 3] = varray_color[ 7] = varray_color[11] = varray_color[15] = varray_color[19] = varray_color[23] = varray_color[27] = varray_color[31] = ca;
        if (fogenabled)
        {
@@ -733,7 +759,7 @@ void R_DrawBBoxMesh(vec3_t mins, vec3_t maxs, float cr, float cg, float cb, floa
                        VectorSubtract(v, r_origin, diff);
                        f2 = exp(fogdensity/DotProduct(diff, diff));
                        f1 = 1 - f2;
-                       f2 *= mesh_colorscale;
+                       f2 *= r_colorscale;
                        c[0] = c[0] * f1 + fogcolor[0] * f2;
                        c[1] = c[1] * f1 + fogcolor[1] * f2;
                        c[2] = c[2] * f1 + fogcolor[2] * f2;
@@ -765,7 +791,6 @@ void R_DrawNoModelCallback(const void *calldata1, int calldata2)
                m.blendfunc1 = GL_ONE;
                m.blendfunc2 = GL_ZERO;
        }
-       m.wantoverbright = false;
        R_Mesh_Matrix(&ent->matrix);
        R_Mesh_State(&m);
 
@@ -796,18 +821,18 @@ void R_DrawNoModelCallback(const void *calldata1, int calldata2)
                f1 = 1 - f2;
                for (i = 0, c = varray_color;i < 6;i++, c += 4)
                {
-                       c[0] = (c[0] * f1 + fogcolor[0] * f2) * mesh_colorscale;
-                       c[1] = (c[1] * f1 + fogcolor[1] * f2) * mesh_colorscale;
-                       c[2] = (c[2] * f1 + fogcolor[2] * f2) * mesh_colorscale;
+                       c[0] = (c[0] * f1 + fogcolor[0] * f2) * r_colorscale;
+                       c[1] = (c[1] * f1 + fogcolor[1] * f2) * r_colorscale;
+                       c[2] = (c[2] * f1 + fogcolor[2] * f2) * r_colorscale;
                }
        }
        else
        {
                for (i = 0, c = varray_color;i < 6;i++, c += 4)
                {
-                       c[0] *= mesh_colorscale;
-                       c[1] *= mesh_colorscale;
-                       c[2] *= mesh_colorscale;
+                       c[0] *= r_colorscale;
+                       c[1] *= r_colorscale;
+                       c[2] *= r_colorscale;
                }
        }
        R_Mesh_Draw(6, 8, element);
@@ -821,3 +846,33 @@ void R_DrawNoModel(entity_render_t *ent)
        //      R_DrawNoModelCallback(ent, 0);
 }
 
+void R_CalcBeamVerts (float *vert, vec3_t org1, vec3_t org2, float width)
+{
+       vec3_t right1, right2, diff, normal;
+
+       VectorSubtract (org2, org1, normal);
+       VectorNormalizeFast (normal);
+
+       // calculate 'right' vector for start
+       VectorSubtract (r_origin, org1, diff);
+       VectorNormalizeFast (diff);
+       CrossProduct (normal, diff, right1);
+
+       // calculate 'right' vector for end
+       VectorSubtract (r_origin, org2, diff);
+       VectorNormalizeFast (diff);
+       CrossProduct (normal, diff, right2);
+
+       vert[ 0] = org1[0] + width * right1[0];
+       vert[ 1] = org1[1] + width * right1[1];
+       vert[ 2] = org1[2] + width * right1[2];
+       vert[ 4] = org1[0] - width * right1[0];
+       vert[ 5] = org1[1] - width * right1[1];
+       vert[ 6] = org1[2] - width * right1[2];
+       vert[ 8] = org2[0] - width * right2[0];
+       vert[ 9] = org2[1] - width * right2[1];
+       vert[10] = org2[2] - width * right2[2];
+       vert[12] = org2[0] + width * right2[0];
+       vert[13] = org2[1] + width * right2[1];
+       vert[14] = org2[2] + width * right2[2];
+}