]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_draw.c
add menu QC drawsubpic() to draw just part of an image; revert change to DrawQ_SuperPic
[xonotic/darkplaces.git] / gl_draw.c
index 164eebdde647be6130efa63466537a931122c757..2f01464dbeeb48f7bcca3f0d76cabafad61a7db6 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "cl_video.h"
 
 cvar_t r_textshadow = {CVAR_SAVE, "r_textshadow", "0", "draws a shadow on all text to improve readability (note: value controls offset, 1 = 1 pixel, 1.5 = 1.5 pixels, etc)"};
+cvar_t r_textbrightness = {CVAR_SAVE, "r_textbrightness", "0", "additional brightness for text color codes (0 keeps colors as is, 1 makes them all white)"};
 
 static rtexture_t *char_texture;
 cachepic_t *r_crosshairs[NUMCROSSHAIRS+1];
@@ -341,11 +342,11 @@ cachepic_t        *Draw_CachePic (const char *path, qboolean persistent)
                flags |= TEXF_CLAMP;
 
        // load a high quality image from disk if possible
-       pic->tex = loadtextureimage(drawtexturepool, path, 0, 0, false, flags);
+       pic->tex = loadtextureimage(drawtexturepool, path, 0, 0, false, flags | (gl_texturecompression_2d.integer ? TEXF_COMPRESS : 0));
        if (pic->tex == NULL && !strncmp(path, "gfx/", 4))
        {
                // compatibility with older versions which did not require gfx/ prefix
-               pic->tex = loadtextureimage(drawtexturepool, path + 4, 0, 0, false, flags);
+               pic->tex = loadtextureimage(drawtexturepool, path + 4, 0, 0, false, flags | (gl_texturecompression_2d.integer ? TEXF_COMPRESS : 0));
        }
        // if a high quality image was loaded, set the pic's size to match it, just
        // in case there's no low quality version to get the size from
@@ -531,6 +532,7 @@ static void gl_draw_newmap(void)
 void GL_Draw_Init (void)
 {
        Cvar_RegisterVariable(&r_textshadow);
+       Cvar_RegisterVariable(&r_textbrightness);
        R_RegisterModule("GL_Draw", gl_draw_start, gl_draw_shutdown, gl_draw_newmap);
 }
 
@@ -550,6 +552,7 @@ static void _DrawQ_Setup(void)
 
        GL_DepthMask(true);
        GL_DepthRange(0, 1);
+       GL_PolygonOffset(0, 0);
        GL_DepthTest(false);
        GL_Color(1,1,1,1);
        GL_AlphaTest(false);
@@ -593,10 +596,17 @@ void DrawQ_Pic(float x, float y, cachepic_t *pic, float width, float height, flo
                        height = pic->height;
                R_Mesh_TexBind(0, R_GetTexture(pic->tex));
                R_Mesh_TexCoordPointer(0, 2, floats + 12, 0, 0);
-               floats[12] = 0;floats[13] = 0;
-               floats[14] = 1;floats[15] = 0;
-               floats[16] = 1;floats[17] = 1;
-               floats[18] = 0;floats[19] = 1;
+
+      // AK07: lets be texel correct on the corners
+      {
+         float horz_offset = 0.5f / pic->width;
+         float vert_offset = 0.5f / pic->height;
+
+                  floats[12] = 0.0f + horz_offset;floats[13] = 0.0f + vert_offset;
+                  floats[14] = 1.0f - horz_offset;floats[15] = 0.0f + vert_offset;
+                  floats[16] = 1.0f - horz_offset;floats[17] = 1.0f - vert_offset;
+                  floats[18] = 0.0f + horz_offset;floats[19] = 1.0f - vert_offset;
+      }
        }
 
        floats[2] = floats[5] = floats[8] = floats[11] = 0;
@@ -660,8 +670,9 @@ static vec4_t string_colors[] =
 
 static void DrawQ_GetTextColor(float color[4], int colorindex, float r, float g, float b, float a, qboolean shadow)
 {
+       float v = r_textbrightness.value;
        Vector4Copy(string_colors[colorindex], color);
-       Vector4Set(color, color[0] * r, color[1] * g, color[2] * b, color[3] * a);
+       Vector4Set(color, (color[0] * (1-v) + v) * r, (color[1] * (1-v) + v) * g, (color[2] * (1-v) + v) * b, color[3] * a);
        if (shadow)
        {
                float shadowalpha = color[0]+color[1]+color[2] * 0.8;
@@ -671,7 +682,7 @@ static void DrawQ_GetTextColor(float color[4], int colorindex, float r, float g,
 
 float DrawQ_String(float startx, float starty, const char *text, int maxlen, float w, float h, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor, qboolean ignorecolorcodes)
 {
-       int i, num, shadow, colorindex;
+       int i, num, shadow, colorindex = STRING_COLOR_DEFAULT;
        float x = startx, y, s, t, u, v;
        float *av, *at, *ac;
        float color[4];
@@ -711,8 +722,6 @@ float DrawQ_String(float startx, float starty, const char *text, int maxlen, flo
                        x += r_textshadow.value;
                        y += r_textshadow.value;
                }
-               // because this loop increments x before it draws, we must bias x first
-               x -= w;
                for (i = 0;i < maxlen && text[i];i++, x += w)
                {
                        if (text[i] == ' ')
@@ -779,6 +788,10 @@ float DrawQ_String(float startx, float starty, const char *text, int maxlen, flo
                        GL_LockArrays(0, 0);
                }
        }
+
+       if (outcolor)
+               *outcolor = colorindex;
+
        // note: this relies on the proper text (not shadow) being drawn last
        return x;
 }
@@ -943,6 +956,7 @@ void R_DrawGamma(void)
                R_Mesh_ResetTextureState();
                GL_DepthMask(true);
                GL_DepthRange(0, 1);
+               GL_PolygonOffset(0, 0);
                GL_DepthTest(false);
                if (v_color_enable.integer)
                {