]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_screen.c
bmodel rotation physics now work
[xonotic/darkplaces.git] / gl_screen.c
index 2a0bfa531316d6aae5022557505ba967586e8472..624a9db635f77317e2b60489417202e3c7b990bc 100644 (file)
@@ -88,8 +88,8 @@ cvar_t                scr_showram = {"showram","1"};
 cvar_t         scr_showturtle = {"showturtle","0"};
 cvar_t         scr_showpause = {"showpause","1"};
 cvar_t         scr_printspeed = {"scr_printspeed","8"};
-cvar_t         gl_triplebuffer = {"gl_triplebuffer", "1", true };
 cvar_t         showfps = {"showfps", "0", true};
+cvar_t         r_render = {"r_render", "1"};
 
 extern cvar_t  crosshair;
 
@@ -108,8 +108,6 @@ extern int                     sb_lines;
 
 extern viddef_t        vid;                            // global video state
 
-vrect_t                scr_vrect;
-
 qboolean       scr_disabled_for_loading;
 qboolean       scr_drawloading;
 float          scr_disabled_time;
@@ -272,9 +270,6 @@ static void SCR_CalcRefdef (void)
        scr_fullupdate = 0;             // force a background redraw
        vid.recalc_refdef = 0;
 
-// force the status bar to redraw
-//     Sbar_Changed ();
-
 //========================================
        
 // bound viewsize
@@ -340,8 +335,6 @@ static void SCR_CalcRefdef (void)
 
        r_refdef.fov_x = scr_fov.value;
        r_refdef.fov_y = CalcFov (r_refdef.fov_x, r_refdef.vrect.width, r_refdef.vrect.height);
-
-       scr_vrect = r_refdef.vrect;
 }
 
 
@@ -374,12 +367,23 @@ void SCR_SizeDown_f (void)
 
 //============================================================================
 
+void gl_screen_start()
+{
+       scr_ram = Draw_PicFromWad ("ram");
+       scr_net = Draw_PicFromWad ("net");
+       scr_turtle = Draw_PicFromWad ("turtle");
+}
+
+void gl_screen_shutdown()
+{
+}
+
 /*
 ==================
 SCR_Init
 ==================
 */
-void SCR_Init (void)
+void GL_Screen_Init (void)
 {
 
        Cvar_RegisterVariable (&scr_fov);
@@ -390,8 +394,11 @@ void SCR_Init (void)
        Cvar_RegisterVariable (&scr_showpause);
        Cvar_RegisterVariable (&scr_centertime);
        Cvar_RegisterVariable (&scr_printspeed);
-       Cvar_RegisterVariable (&gl_triplebuffer);
        Cvar_RegisterVariable (&showfps);
+       Cvar_RegisterVariable (&r_render);
+#ifdef NORENDER
+       r_render.value = 0;
+#endif
 
 //
 // register our commands
@@ -400,11 +407,9 @@ void SCR_Init (void)
        Cmd_AddCommand ("sizeup",SCR_SizeUp_f);
        Cmd_AddCommand ("sizedown",SCR_SizeDown_f);
 
-       scr_ram = Draw_PicFromWad ("ram");
-       scr_net = Draw_PicFromWad ("net");
-       scr_turtle = Draw_PicFromWad ("turtle");
-
        scr_initialized = true;
+
+       R_RegisterModule("GL_Screen", gl_screen_start, gl_screen_shutdown);
 }
 
 
@@ -422,7 +427,7 @@ void SCR_DrawRam (void)
        if (!r_cache_thrash)
                return;
 
-       Draw_Pic (scr_vrect.x+32, scr_vrect.y, scr_ram);
+       Draw_Pic (32, 0, scr_ram);
 }
 
 /*
@@ -447,7 +452,7 @@ void SCR_DrawTurtle (void)
        if (count < 3)
                return;
 
-       Draw_Pic (scr_vrect.x, scr_vrect.y, scr_turtle);
+       Draw_Pic (0, 0, scr_turtle);
 }
 
 /*
@@ -462,7 +467,7 @@ void SCR_DrawNet (void)
        if (cls.demoplayback)
                return;
 
-       Draw_Pic (scr_vrect.x+64, scr_vrect.y, scr_net);
+       Draw_Pic (64, 0, scr_net);
 }
 
 /*
@@ -547,18 +552,6 @@ void SCR_SetUpToDrawConsole (void)
                if (scr_conlines < scr_con_current)
                        scr_con_current = scr_conlines;
        }
-
-       /*
-       if (clearconsole++ < vid.numpages)
-       {
-               Sbar_Changed ();
-       }
-       else if (clearnotify++ < vid.numpages)
-       {
-       }
-       else
-               con_notifylines = 0;
-       */
 }
        
 /*
@@ -590,15 +583,6 @@ void SCR_DrawConsole (void)
 ============================================================================== 
 */ 
 
-typedef struct _TargaHeader {
-       unsigned char   id_length, colormap_type, image_type;
-       unsigned short  colormap_index, colormap_length;
-       unsigned char   colormap_size;
-       unsigned short  x_origin, y_origin, width, height;
-       unsigned char   pixel_size, attributes;
-} TargaHeader;
-
-
 /* 
 ================== 
 SCR_ScreenShot_f
@@ -607,21 +591,21 @@ SCR_ScreenShot_f
 void SCR_ScreenShot_f (void) 
 {
        byte            *buffer;
-       char            pcxname[80]; 
+       char            filename[80]; 
        char            checkname[MAX_OSPATH];
-       int                     i, c, temp;
+       int                     i;
 // 
 // find a file name to save it to 
 // 
-       strcpy(pcxname,"dp0000.tga");
+       strcpy(filename,"dp0000.tga");
                
        for (i=0 ; i<=9999 ; i++) 
        { 
-               pcxname[2] = (i/1000)%10 + '0'; 
-               pcxname[3] = (i/ 100)%10 + '0'; 
-               pcxname[4] = (i/  10)%10 + '0'; 
-               pcxname[5] = (i/   1)%10 + '0'; 
-               sprintf (checkname, "%s/%s", com_gamedir, pcxname);
+               filename[2] = (i/1000)%10 + '0'; 
+               filename[3] = (i/ 100)%10 + '0'; 
+               filename[4] = (i/  10)%10 + '0'; 
+               filename[5] = (i/   1)%10 + '0'; 
+               sprintf (checkname, "%s/%s", com_gamedir, filename);
                if (Sys_FileTime(checkname) == -1)
                        break;  // file doesn't exist
        } 
@@ -631,30 +615,12 @@ void SCR_ScreenShot_f (void)
                return;
        }
 
-
-       buffer = malloc(glwidth*glheight*3 + 18);
-       memset (buffer, 0, 18);
-       buffer[2] = 2;          // uncompressed type
-       buffer[12] = glwidth&255;
-       buffer[13] = glwidth>>8;
-       buffer[14] = glheight&255;
-       buffer[15] = glheight>>8;
-       buffer[16] = 24;        // pixel size
-
-       glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer+18 ); 
-
-       // swap rgb to bgr
-       c = 18+glwidth*glheight*3;
-       for (i=18 ; i<c ; i+=3)
-       {
-               temp = buffer[i];
-               buffer[i] = buffer[i+2];
-               buffer[i+2] = temp;
-       }
-       COM_WriteFile (pcxname, buffer, glwidth*glheight*3 + 18 );
+       buffer = malloc(glwidth*glheight*3);
+       glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer); 
+       Image_WriteTGARGB(filename, glwidth, glheight, buffer);
 
        free (buffer);
-       Con_Printf ("Wrote %s\n", pcxname);
+       Con_Printf ("Wrote %s\n", filename);
 } 
 
 
@@ -683,7 +649,6 @@ void SCR_BeginLoadingPlaque (void)
 
        scr_drawloading = true;
        scr_fullupdate = 0;
-//     Sbar_Changed ();
        SCR_UpdateScreen ();
        scr_drawloading = false;
 
@@ -785,7 +750,7 @@ int SCR_ModalMessage (char *text)
 ===============
 SCR_BringDownConsole
 
-Brings the console down and fades the palettes back to normal
+Brings the console down and fades the blends back to normal
 ================
 */
 void SCR_BringDownConsole (void)
@@ -797,10 +762,10 @@ void SCR_BringDownConsole (void)
        for (i=0 ; i<20 && scr_conlines != scr_con_current ; i++)
                SCR_UpdateScreen ();
 
-       cl.cshifts[0].percent = 0;              // no area contents palette on next frame
-       VID_SetPalette (host_basepal);
+       cl.cshifts[0].percent = 0;              // no area contents blend on next frame
 }
 
+void DrawCrosshair(int num);
 void GL_Set2D (void);
 
 extern void SHOWLMP_drawall();
@@ -811,14 +776,16 @@ extern cvar_t gl_lightmode;
 void GL_BrightenScreen()
 {
        float f;
+       if (!r_render.value)
+               return;
        glDisable(GL_TEXTURE_2D);
        glEnable(GL_BLEND);
        f = brightness.value = bound(1.0f, brightness.value, 5.0f);
-       if (f > 1)
+       if (f >= 1.01f)
        {
                glBlendFunc (GL_DST_COLOR, GL_ONE);
                glBegin (GL_TRIANGLES);
-               while (f > 1)
+               while (f >= 1.01f)
                {
                        if (f >= 2)
                                glColor3f (1, 1, 1);
@@ -833,7 +800,7 @@ void GL_BrightenScreen()
        }
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        contrast.value = bound(0.2, contrast.value, 1.0);
-       if (contrast.value < 1.0f)
+       if (contrast.value < 0.99f)
        {
                glBegin (GL_TRIANGLES);
                glColor4f (1, 1, 1, 1-contrast.value);
@@ -856,31 +823,22 @@ SCR_UpdateScreen
 This is called every frame, and can also be called explicitly to flush
 text to the screen.
 
-WARNING: be very careful calling this from elsewhere, because the refresh
-needs almost the entire 256k of stack space!
+LordHavoc: due to my rewrite of R_WorldNode, it no longer takes 256k of stack space :)
 ==================
 */
 extern cvar_t gl_vertexarrays;
 extern qboolean gl_arrays;
 void GL_Finish();
-int c_nodes;
 void SCR_UpdateScreen (void)
 {
        double  time1 = 0, time2;
 
        if (r_speeds.value)
-       {
                time1 = Sys_FloatTime ();
-               c_brush_polys = 0;
-               c_alias_polys = 0;
-               c_nodes = 0;
-       }
 
        if (!gl_arrays)
                gl_vertexarrays.value = 0;
 
-       vid.numpages = 2 + gl_triplebuffer.value;
-
        scr_copytop = 0;
        scr_copyeverything = 0;
 
@@ -919,8 +877,11 @@ void SCR_UpdateScreen (void)
        if (vid.recalc_refdef)
                SCR_CalcRefdef ();
 
-       glClearColor(0,0,0,0);
-       glClear (GL_COLOR_BUFFER_BIT); // LordHavoc: clear the screen (around the view as well)
+       if (r_render.value)
+       {
+               glClearColor(0,0,0,0);
+               glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // LordHavoc: clear the screen (around the view as well)
+       }
 
 //
 // do 3D refresh drawing, and then update the screen
@@ -955,7 +916,7 @@ void SCR_UpdateScreen (void)
        else
        {
                if (crosshair.value)
-                       Draw_Character (scr_vrect.x + scr_vrect.width/2, scr_vrect.y + scr_vrect.height/2, '+');
+                       DrawCrosshair(crosshair.value - 1);
                
                SCR_DrawRam ();
                SCR_DrawNet ();
@@ -981,7 +942,7 @@ void SCR_UpdateScreen (void)
                Draw_String(vid.width - (12*8), 0, temp, 9999);
        }
 
-       V_UpdatePalette ();
+       V_UpdateBlends ();
 
        GL_BrightenScreen();
 
@@ -990,7 +951,7 @@ void SCR_UpdateScreen (void)
        if (r_speeds.value)
        {
                time2 = Sys_FloatTime ();
-               Con_Printf ("%3i ms  %4i wpoly %4i epoly %4i transpoly %4i BSPnodes\n", (int)((time2-time1)*1000), c_brush_polys, c_alias_polys, currenttranspoly, c_nodes); 
+               Con_Printf ("%3i ms  %4i wpoly %4i epoly %4i transpoly %4i lightpoly %4i BSPnodes %4i BSPleafs\n", (int)((time2-time1)*1000), c_brush_polys, c_alias_polys, currenttranspoly, c_light_polys, c_nodes, c_leafs);
        }
        GL_EndRendering ();
 }
@@ -998,6 +959,8 @@ void SCR_UpdateScreen (void)
 // for profiling, this is seperated
 void GL_Finish()
 {
+       if (!r_render.value)
+               return;
        glFinish ();
 }