]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_draw.c
fix a minor typo causing a slight misprediction
[xonotic/darkplaces.git] / gl_draw.c
index 039a9c91ece200b32dd04ae8bf07df8659e59299..faa0c9180fa473a5c06bff3972f696c096a06831 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -67,7 +67,7 @@ static rtexture_t *draw_generateconchars(void)
        double random;
        rtexture_t *tex;
 
-       data = LoadTGA_BGRA (concharimage, FONT_FILESIZE);
+       data = LoadTGA_BGRA (concharimage, FONT_FILESIZE, NULL);
 // Gold numbers
        for (i = 0;i < 8192;i++)
        {
@@ -109,7 +109,7 @@ static rtexture_t *draw_generateconchars(void)
        Image_WriteTGABGRA ("gfx/generated_conchars.tga", 256, 256, data);
 #endif
 
-       tex = R_LoadTexture2D(drawtexturepool, "conchars", 256, 256, data, TEXTYPE_BGRA, TEXF_ALPHA, NULL);
+       tex = R_LoadTexture2D(drawtexturepool, "conchars", 256, 256, data, TEXTYPE_BGRA, TEXF_ALPHA, -1, NULL);
        Mem_Free(data);
        return tex;
 }
@@ -121,7 +121,7 @@ static rtexture_t *draw_generateditherpattern(void)
        for (y = 0;y < 8;y++)
                for (x = 0;x < 8;x++)
                        pixels[y][x] = ((x^y) & 4) ? 254 : 0;
-       return R_LoadTexture2D(drawtexturepool, "ditherpattern", 8, 8, pixels[0], TEXTYPE_PALETTE, TEXF_FORCENEAREST, palette_bgra_transparent);
+       return R_LoadTexture2D(drawtexturepool, "ditherpattern", 8, 8, pixels[0], TEXTYPE_PALETTE, TEXF_FORCENEAREST, -1, palette_bgra_transparent);
 }
 
 typedef struct embeddedpic_s
@@ -292,7 +292,7 @@ static rtexture_t *draw_generatepic(const char *name, qboolean quiet)
        const embeddedpic_t *p;
        for (p = embeddedpics;p->name;p++)
                if (!strcmp(name, p->name))
-                       return R_LoadTexture2D(drawtexturepool, p->name, p->width, p->height, (const unsigned char *)p->pixels, TEXTYPE_PALETTE, TEXF_ALPHA, palette_bgra_embeddedpic);
+                       return R_LoadTexture2D(drawtexturepool, p->name, p->width, p->height, (const unsigned char *)p->pixels, TEXTYPE_PALETTE, TEXF_ALPHA, -1, palette_bgra_embeddedpic);
        if (!strcmp(name, "gfx/conchars"))
                return draw_generateconchars();
        if (!strcmp(name, "gfx/colorcontrol/ditherpattern"))
@@ -356,15 +356,15 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
        pic->autoload = (cachepicflags & CACHEPICFLAG_NOTPERSISTENT);
 
        // load a high quality image from disk if possible
-       pixels = loadimagepixelsbgra(path, false, true, r_texture_convertsRGB_2d.integer);
+       pixels = loadimagepixelsbgra(path, false, true, r_texture_convertsRGB_2d.integer, NULL);
        if (pixels == NULL && !strncmp(path, "gfx/", 4))
-               pixels = loadimagepixelsbgra(path+4, false, true, r_texture_convertsRGB_2d.integer);
+               pixels = loadimagepixelsbgra(path+4, false, true, r_texture_convertsRGB_2d.integer, NULL);
        if (pixels)
        {
                pic->width = image_width;
                pic->height = image_height;
                if (!pic->autoload)
-                       pic->tex = R_LoadTexture2D(drawtexturepool, path, image_width, image_height, pixels, TEXTYPE_BGRA, pic->texflags, NULL);
+                       pic->tex = R_LoadTexture2D(drawtexturepool, path, image_width, image_height, pixels, TEXTYPE_BGRA, pic->texflags, -1, NULL);
        }
        else
        {
@@ -389,7 +389,7 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
                        pic->height = lmpdata[4] + lmpdata[5] * 256 + lmpdata[6] * 65536 + lmpdata[7] * 16777216;
                        // if no high quality replacement image was found, upload the original low quality texture
                        if (!pixels)
-                               pic->tex = R_LoadTexture2D(drawtexturepool, path, pic->width, pic->height, lmpdata + 8, TEXTYPE_PALETTE, pic->texflags, palette_bgra_transparent);
+                               pic->tex = R_LoadTexture2D(drawtexturepool, path, pic->width, pic->height, lmpdata + 8, TEXTYPE_PALETTE, pic->texflags, -1, palette_bgra_transparent);
                }
                Mem_Free(lmpdata);
        }
@@ -405,7 +405,7 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
                        pic->height = 128;
                        // if no high quality replacement image was found, upload the original low quality texture
                        if (!pixels)
-                               pic->tex = R_LoadTexture2D(drawtexturepool, path, 128, 128, lmpdata, TEXTYPE_PALETTE, pic->texflags, palette_bgra_font);
+                               pic->tex = R_LoadTexture2D(drawtexturepool, path, 128, 128, lmpdata, TEXTYPE_PALETTE, pic->texflags, -1, palette_bgra_font);
                }
                else
                {
@@ -413,7 +413,7 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
                        pic->height = lmpdata[4] + lmpdata[5] * 256 + lmpdata[6] * 65536 + lmpdata[7] * 16777216;
                        // if no high quality replacement image was found, upload the original low quality texture
                        if (!pixels)
-                               pic->tex = R_LoadTexture2D(drawtexturepool, path, pic->width, pic->height, lmpdata + 8, TEXTYPE_PALETTE, pic->texflags, palette_bgra_transparent);
+                               pic->tex = R_LoadTexture2D(drawtexturepool, path, pic->width, pic->height, lmpdata + 8, TEXTYPE_PALETTE, pic->texflags, -1, palette_bgra_transparent);
                }
        }
 
@@ -514,7 +514,7 @@ cachepic_t *Draw_NewPic(const char *picname, int width, int height, int alpha, u
        pic->height = height;
        if (pic->tex)
                R_FreeTexture(pic->tex);
-       pic->tex = R_LoadTexture2D(drawtexturepool, picname, width, height, pixels_bgra, TEXTYPE_BGRA, (alpha ? TEXF_ALPHA : 0) | TEXF_ALLOWUPDATES, NULL);
+       pic->tex = R_LoadTexture2D(drawtexturepool, picname, width, height, pixels_bgra, TEXTYPE_BGRA, (alpha ? TEXF_ALPHA : 0) | TEXF_ALLOWUPDATES, -1, NULL);
        return pic;
 }
 
@@ -552,8 +552,9 @@ void LoadFont(qboolean override, const char *name, dp_font_t *fnt, float scale,
        if(override || !fnt->texpath[0])
        {
                strlcpy(fnt->texpath, name, sizeof(fnt->texpath));
-
-               // load the cvars when the font is FIRST loaded
+               // load the cvars when the font is FIRST loader
+               fnt->settings.scale = scale;
+               fnt->settings.voffset = voffset;
                fnt->settings.antialias = r_font_antialias.integer;
                fnt->settings.hinting = r_font_hinting.integer;
                fnt->settings.outline = r_font_postprocess_outline.value;
@@ -562,6 +563,9 @@ void LoadFont(qboolean override, const char *name, dp_font_t *fnt, float scale,
                fnt->settings.shadowy = r_font_postprocess_shadow_y.value;
                fnt->settings.shadowz = r_font_postprocess_shadow_z.value;
        }
+       // fix bad scale
+       if (fnt->settings.scale <= 0)
+               fnt->settings.scale = 1;
 
        if(drawtexturepool == NULL)
                return; // before gl_draw_start, so will be loaded later
@@ -658,7 +662,7 @@ void LoadFont(qboolean override, const char *name, dp_font_t *fnt, float scale,
                                        {
                                                if(!COM_ParseToken_Simple(&p, false, false))
                                                        return;
-                                               scale = atof(com_token);
+                                               fnt->settings.scale = atof(com_token);
                                        }
                                        else
                                        {
@@ -679,9 +683,7 @@ void LoadFont(qboolean override, const char *name, dp_font_t *fnt, float scale,
        fnt->maxwidth = maxwidth;
 
        // fix up maxwidth for overlap
-       fnt->maxwidth *= scale;
-       fnt->scale = scale;
-       fnt->voffset = voffset;
+       fnt->maxwidth *= fnt->settings.scale;
 
        if(fnt == FONT_CONSOLE)
                con_linewidth = -1; // rewrap console in next frame
@@ -750,9 +752,9 @@ static float snap_to_pixel_y(float y, float roundUpAt)
 static void LoadFont_f(void)
 {
        dp_font_t *f;
-       int i;
+       int i, sizes;
        const char *filelist, *c, *cm;
-       float sz;
+       float sz, scale, voffset;
        char mainfont[MAX_QPATH];
 
        if(Cmd_Argc() < 2)
@@ -760,7 +762,7 @@ static void LoadFont_f(void)
                Con_Printf("Available font commands:\n");
                for(i = 0; i < dp_fonts.maxsize; ++i)
                        if (dp_fonts.f[i].title[0])
-                               Con_Printf("  loadfont %s gfx/tgafile[...] [sizes...]\n", dp_fonts.f[i].title);
+                               Con_Printf("  loadfont %s gfx/tgafile[...] [custom switches] [sizes...]\n", dp_fonts.f[i].title);
                Con_Printf("A font can simply be gfx/tgafile, or alternatively you\n"
                           "can specify multiple fonts and faces\n"
                           "Like this: gfx/vera-sans:2,gfx/fallback:1\n"
@@ -769,6 +771,9 @@ static void LoadFont_f(void)
                           "You can also specify a list of font sizes to load, like this:\n"
                           "loadfont console gfx/conchars,gfx/fallback 8 12 16 24 32\n"
                           "In many cases, 8 12 16 24 32 should be a good choice.\n"
+                          "custom switches:\n"
+                          " scale x : scale all characters by this amount when rendering (doesnt change line height)\n"
+                          " voffset x : offset all chars vertical when rendering, this is multiplied to character height\n"
                        );
                return;
        }
@@ -839,17 +844,38 @@ static void LoadFont_f(void)
        for(i = 1; i < MAX_FONT_SIZES; ++i)
                f->req_sizes[i] = -1;
 
-       if(Cmd_Argc() >= 3)
+       scale = 1;
+       voffset = 0;
+       if(Cmd_Argc() >= 4)
        {
-               for(i = 0; i < Cmd_Argc()-3; ++i)
+               for(sizes = 0, i = 3; i < Cmd_Argc(); ++i)
                {
-                       sz = atof(Cmd_Argv(i+3));
+                       // special switches
+                       if (!strcmp(Cmd_Argv(i), "scale"))
+                       {
+                               i++;
+                               if (i < Cmd_Argc())
+                                       scale = atof(Cmd_Argv(i));
+                               continue;
+                       }
+                       if (!strcmp(Cmd_Argv(i), "voffset"))
+                       {
+                               i++;
+                               if (i < Cmd_Argc())
+                                       voffset = atof(Cmd_Argv(i));
+                               continue;
+                       }
+                       // parse one of sizes
+                       sz = atof(Cmd_Argv(i));
                        if (sz > 0.001f && sz < 1000.0f) // do not use crap sizes
-                               f->req_sizes[i] = sz;
+                       {
+                               f->req_sizes[sizes] = sz;
+                               sizes++;
+                       }
                }
        }
 
-       LoadFont(true, mainfont, f, 1, 0);
+       LoadFont(true, mainfont, f, scale, voffset);
 }
 
 /*
@@ -870,7 +896,7 @@ static void gl_draw_start(void)
        // load default font textures
        for(i = 0; i < dp_fonts.maxsize; ++i)
                if (dp_fonts.f[i].title[0])
-                       LoadFont(false, va("gfx/font_%s", &dp_fonts.f[i].title), &dp_fonts.f[i], 1, 0);
+                       LoadFont(false, va("gfx/font_%s", dp_fonts.f[i].title), &dp_fonts.f[i], 1, 0);
 
        // draw the loading screen so people have something to see in the newly opened window
        SCR_UpdateLoadingScreen(true);
@@ -1182,8 +1208,8 @@ float DrawQ_TextWidth_UntilWidth_TrackColors_Scale(const char *text, size_t *max
                snap = false;
        }
        // do this in the end
-       w *= fnt->scale;
-       h *= fnt->scale;
+       w *= fnt->settings.scale;
+       h *= fnt->settings.scale;
 
        // find the most fitting size:
        if (ft2 != NULL)
@@ -1378,9 +1404,9 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                snap = false;
        }
 
-       starty -= (fnt->scale - 1) * h * 0.5 - fnt->voffset*h; // center & offset
-       w *= fnt->scale;
-       h *= fnt->scale;
+       starty -= (fnt->settings.scale - 1) * h * 0.5 - fnt->settings.voffset*h; // center & offset
+       w *= fnt->settings.scale;
+       h *= fnt->settings.scale;
 
        if (ft2 != NULL)
        {