]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_draw.c
rewrote RecursiveHullCheck, no longer gets stuck on angle changes, and is generally...
[xonotic/darkplaces.git] / gl_draw.c
index f2c94651bde91ce59c5841748f6d4f0a8b53d23b..bf3de8f98252d974c1098baaca33aa57e3aa9236 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 //#define GL_COLOR_INDEX8_EXT     0x80E5
 
-cvar_t         scr_conalpha = {"scr_conalpha", "1"};
+cvar_t         scr_conalpha = {CVAR_SAVE, "scr_conalpha", "1"};
 
 byte           *draw_chars;                            // 8*8 graphic characters
 qpic_t         *draw_disc;
@@ -119,16 +119,12 @@ qpic_t    *Draw_CachePic (char *path)
        return &pic->pic;
 }
 
-extern void LoadSky_f(void);
-
 /*
 ===============
 Draw_Init
 ===============
 */
-void rmain_registercvars();
-
-void gl_draw_start()
+void gl_draw_start(void)
 {
        int             i;
 
@@ -150,11 +146,15 @@ void gl_draw_start()
        draw_disc = Draw_PicFromWad ("disc");
 }
 
-void gl_draw_shutdown()
+void gl_draw_shutdown(void)
 {
 }
 
-char engineversion[40];
+void gl_draw_newmap(void)
+{
+}
+
+extern char engineversion[40];
 int engineversionx, engineversiony;
 
 extern void R_Textures_Init();
@@ -163,22 +163,13 @@ void GL_Draw_Init (void)
        int i;
        Cvar_RegisterVariable (&scr_conalpha);
 
-       Cmd_AddCommand ("loadsky", &LoadSky_f);
-
-#if defined(__linux__)
-       sprintf (engineversion, "DarkPlaces Linux   GL %.2f build %3i", (float) VERSION, buildnumber);
-#elif defined(WIN32)
-       sprintf (engineversion, "DarkPlaces Windows GL %.2f build %3i", (float) VERSION, buildnumber);
-#else
-       sprintf (engineversion, "DarkPlaces Unknown GL %.2f build %3i", (float) VERSION, buildnumber);
-#endif
        for (i = 0;i < 40 && engineversion[i];i++)
                engineversion[i] += 0x80; // shift to orange
-       engineversionx = vid.width - strlen(engineversion) * 8 - 8;
-       engineversiony = vid.height - 8;
+       engineversionx = vid.conwidth - strlen(engineversion) * 8 - 8;
+       engineversiony = vid.conheight - 8;
 
        R_Textures_Init();
-       R_RegisterModule("GL_Draw", gl_draw_start, gl_draw_shutdown);
+       R_RegisterModule("GL_Draw", gl_draw_start, gl_draw_shutdown, gl_draw_newmap);
 }
 
 /*
@@ -214,7 +205,7 @@ void Draw_Character (int x, int y, int num)
                return;
        glBindTexture(GL_TEXTURE_2D, R_GetTexture(char_texture));
        // LordHavoc: NEAREST mode on text if not scaling up
-       if (glwidth <= (int) vid.width)
+       if (vid.realwidth <= (int) vid.conwidth)
        {
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -225,7 +216,10 @@ void Draw_Character (int x, int y, int num)
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        }
 
-       glColor3f(1,1,1);
+       if (lighthalf)
+               glColor3f(0.5f,0.5f,0.5f);
+       else
+               glColor3f(1.0f,1.0f,1.0f);
        glBegin (GL_QUADS);
        glTexCoord2f (fcol, frow);
        glVertex2f (x, y);
@@ -238,7 +232,7 @@ void Draw_Character (int x, int y, int num)
        glEnd ();
 
        // LordHavoc: revert to LINEAR mode
-//     if (glwidth < (int) vid.width)
+//     if (vid.realwidth <= (int) vid.conwidth)
 //     {
 //             glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 //             glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -257,7 +251,7 @@ void Draw_String (int x, int y, char *str, int maxlen)
        float frow, fcol;
        if (!r_render.value)
                return;
-       if (y <= -8 || y >= (int) vid.height || x >= (int) vid.width || *str == 0) // completely offscreen or no text to print
+       if (y <= -8 || y >= (int) vid.conheight || x >= (int) vid.conwidth || *str == 0) // completely offscreen or no text to print
                return;
        if (maxlen < 1)
                maxlen = strlen(str);
@@ -266,7 +260,7 @@ void Draw_String (int x, int y, char *str, int maxlen)
        glBindTexture(GL_TEXTURE_2D, R_GetTexture(char_texture));
 
        // LordHavoc: NEAREST mode on text if not scaling up
-       if (glwidth <= (int) vid.width)
+       if (vid.realwidth <= (int) vid.conwidth)
        {
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -277,9 +271,12 @@ void Draw_String (int x, int y, char *str, int maxlen)
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        }
 
-       glColor3f(1,1,1);
+       if (lighthalf)
+               glColor3f(0.5f,0.5f,0.5f);
+       else
+               glColor3f(1.0f,1.0f,1.0f);
        glBegin (GL_QUADS);
-       while (maxlen-- && x < (int) vid.width) // stop rendering when out of characters or room
+       while (maxlen-- && x < (int) vid.conwidth) // stop rendering when out of characters or room
        {
                if ((num = *str++) != 32) // skip spaces
                {
@@ -295,18 +292,30 @@ void Draw_String (int x, int y, char *str, int maxlen)
        glEnd ();
 
        // LordHavoc: revert to LINEAR mode
-//     if (glwidth < (int) vid.width)
+//     if (vid.realwidth < (int) vid.conwidth)
 //     {
 //             glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 //             glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 //     }
 }
 
+void Draw_AdditiveString (int x, int y, char *str, int maxlen)
+{
+       if (!r_render.value)
+               return;
+       glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+       Draw_String(x, y, str, maxlen);
+       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+}
+
 void Draw_GenericPic (rtexture_t *tex, float red, float green, float blue, float alpha, int x, int y, int width, int height)
 {
        if (!r_render.value)
                return;
-       glColor4f(red,green,blue,alpha);
+       if (lighthalf)
+               glColor4f(red * 0.5f, green * 0.5f, blue * 0.5f, alpha);
+       else
+               glColor4f(red, green, blue, alpha);
        glBindTexture(GL_TEXTURE_2D, R_GetTexture(tex));
        glBegin (GL_QUADS);
        glTexCoord2f (0, 0);glVertex2f (x, y);
@@ -323,7 +332,8 @@ Draw_AlphaPic
 */
 void Draw_AlphaPic (int x, int y, qpic_t *pic, float alpha)
 {
-       Draw_GenericPic(((glpic_t *)pic->data)->tex, 1,1,1,alpha, x,y,pic->width, pic->height);
+       if (pic)
+               Draw_GenericPic(((glpic_t *)pic->data)->tex, 1,1,1,alpha, x,y,pic->width, pic->height);
 }
 
 
@@ -334,7 +344,19 @@ Draw_Pic
 */
 void Draw_Pic (int x, int y, qpic_t *pic)
 {
-       Draw_GenericPic(((glpic_t *)pic->data)->tex, 1,1,1,1, x,y,pic->width, pic->height);
+       if (pic)
+               Draw_GenericPic(((glpic_t *)pic->data)->tex, 1,1,1,1, x,y,pic->width, pic->height);
+}
+
+
+void Draw_AdditivePic (int x, int y, qpic_t *pic)
+{
+       if (pic)
+       {
+               glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+               Draw_GenericPic(((glpic_t *)pic->data)->tex, 1,1,1,1, x,y,pic->width, pic->height);
+               glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       }
 }
 
 
@@ -351,6 +373,9 @@ void Draw_PicTranslate (int x, int y, qpic_t *pic, byte *translation)
        byte                    *trans, *src, *dest;
        rtexture_t              *rt;
 
+       if (pic == NULL)
+               return;
+
        c = pic->width * pic->height;
        src = menuplyr_pixels;
        dest = trans = qmalloc(c);
@@ -374,9 +399,9 @@ Draw_ConsoleBackground
 */
 void Draw_ConsoleBackground (int lines)
 {
-       Draw_GenericPic (conbacktex, 1,1,1,scr_conalpha.value*lines/vid.height, 0, lines - vid.height, vid.width, vid.height);
+       Draw_GenericPic (conbacktex, 1,1,1,scr_conalpha.value * lines / vid.conheight, 0, lines - vid.conheight, vid.conwidth, vid.conheight);
        // LordHavoc: draw version
-       Draw_String(engineversionx, lines - vid.height + engineversiony, engineversion, 9999);
+       Draw_String(engineversionx, lines - vid.conheight + engineversiony, engineversion, 9999);
 }
 
 /*
@@ -391,7 +416,13 @@ void Draw_Fill (int x, int y, int w, int h, int c)
        if (!r_render.value)
                return;
        glDisable (GL_TEXTURE_2D);
-       glColor3f (host_basepal[c*3]/255.0, host_basepal[c*3+1]/255.0, host_basepal[c*3+2]/255.0);
+       if (lighthalf)
+       {
+               byte *tempcolor = (byte *)&d_8to24table[c];
+               glColor4ub ((byte) (tempcolor[0] >> 1), (byte) (tempcolor[1] >> 1), (byte) (tempcolor[2] >> 1), tempcolor[3]);
+       }
+       else
+               glColor4ubv ((byte *)&d_8to24table[c]);
 
        glBegin (GL_QUADS);
 
@@ -419,11 +450,11 @@ void GL_Set2D (void)
 {
        if (!r_render.value)
                return;
-       glViewport (glx, gly, glwidth, glheight);
+       glViewport (vid.realx, vid.realy, vid.realwidth, vid.realheight);
 
        glMatrixMode(GL_PROJECTION);
     glLoadIdentity ();
-       glOrtho  (0, vid.width, vid.height, 0, -99999, 99999);
+       glOrtho  (0, vid.conwidth, vid.conheight, 0, -99999, 99999);
 
        glMatrixMode(GL_MODELVIEW);
     glLoadIdentity ();
@@ -454,7 +485,7 @@ typedef struct showlmp_s
 
 showlmp_t showlmp[SHOWLMP_MAXLABELS];
 
-void SHOWLMP_decodehide()
+void SHOWLMP_decodehide(void)
 {
        int i;
        byte *lmplabel;
@@ -467,14 +498,14 @@ void SHOWLMP_decodehide()
                }
 }
 
-void SHOWLMP_decodeshow()
+void SHOWLMP_decodeshow(void)
 {
        int i, k;
        byte lmplabel[256], picname[256];
        float x, y;
        strcpy(lmplabel,MSG_ReadString());
        strcpy(picname, MSG_ReadString());
-       if (nehahra) // LordHavoc: nasty old legacy junk
+       if (gamemode == GAME_NEHAHRA) // LordHavoc: nasty old legacy junk
        {
                x = MSG_ReadByte();
                y = MSG_ReadByte();
@@ -506,7 +537,7 @@ void SHOWLMP_decodeshow()
        showlmp[k].y = y;
 }
 
-void SHOWLMP_drawall()
+void SHOWLMP_drawall(void)
 {
        int i;
        for (i = 0;i < SHOWLMP_MAXLABELS;i++)
@@ -514,7 +545,7 @@ void SHOWLMP_drawall()
                        Draw_Pic(showlmp[i].x, showlmp[i].y, Draw_CachePic(showlmp[i].pic));
 }
 
-void SHOWLMP_clear()
+void SHOWLMP_clear(void)
 {
        int i;
        for (i = 0;i < SHOWLMP_MAXLABELS;i++)