]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
reworked transparency in palettes, made palette_complete be strictly opaque, added...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 27 Dec 2005 02:29:40 +0000 (02:29 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 27 Dec 2005 02:29:40 +0000 (02:29 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5865 d7cf8633-e32d-0410-b094-e92efae38249

gl_draw.c
image.c
menu.c
model_shared.c
palette.c
palette.h

index 7509ea46e907ee13011d656d526cbf21cd7f0a47..db8579f4d2c60420f1cc243f9dc3efdd6a6033b1 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -353,16 +353,11 @@ cachepic_t        *Draw_CachePic (const char *path, qboolean persistent)
                {
                        if (!strcmp(path, "gfx/conchars"))
                        {
-                               unsigned char *pix;
-                               // conchars is a raw image and with the wrong transparent color
-                               pix = (unsigned char *)p;
-                               for (i = 0;i < 128 * 128;i++)
-                                       if (pix[i] == 0)
-                                               pix[i] = 255;
-                               pic->tex = R_LoadTexture2D(drawtexturepool, path, 128, 128, pix, TEXTYPE_PALETTE, flags, palette_complete);
+                               // conchars is a raw image and with color 0 as transparent instead of 255
+                               pic->tex = R_LoadTexture2D(drawtexturepool, path, 128, 128, (unsigned char *)p, TEXTYPE_PALETTE, flags, palette_font);
                        }
                        else
-                               pic->tex = R_LoadTexture2D(drawtexturepool, path, p->width, p->height, p->data, TEXTYPE_PALETTE, flags, palette_complete);
+                               pic->tex = R_LoadTexture2D(drawtexturepool, path, p->width, p->height, p->data, TEXTYPE_PALETTE, flags, palette_transparent);
                }
        }
 
diff --git a/image.c b/image.c
index 549ca9c1afc9de9bdaf3c6a9f57c4e67044848a1..aeaca35c8ab50d6342af77a8d8890f2ccbcca2d0 100644 (file)
--- a/image.c
+++ b/image.c
@@ -571,7 +571,7 @@ unsigned char *LoadLMP (const unsigned char *f, int filesize, int matchwidth, in
        else
        {
                image_buffer = (unsigned char *)Mem_Alloc(tempmempool, image_width * image_height * 4);
-               Image_Copy8bitRGBA(f + 8, image_buffer, image_width * image_height, palette_complete);
+               Image_Copy8bitRGBA(f + 8, image_buffer, image_width * image_height, palette_transparent);
        }
        return image_buffer;
 }
diff --git a/menu.c b/menu.c
index eca046cf10cc57a4d5641b4e92e6d23284f74e44..0cb56cd386a290bbbad16ceec588d83e4e6f7b1a 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -1351,7 +1351,7 @@ void M_Setup_Draw (void)
                        menuplyr_bottom = setup_bottom;
                        M_BuildTranslationTable(menuplyr_top*16, menuplyr_bottom*16);
                        for (i = 0;i < menuplyr_width * menuplyr_height;i++)
-                               menuplyr_translated[i] = palette_complete[translationTable[menuplyr_pixels[i]]];
+                               menuplyr_translated[i] = palette_transparent[translationTable[menuplyr_pixels[i]]];
                        Draw_NewPic("gfx/menuplyr", menuplyr_width, menuplyr_height, true, (unsigned char *)menuplyr_translated);
                }
                M_DrawPic(160, 48, "gfx/bigbox");
index 4354ee7ee1db0a3de561f1c82695053e616db7d3..91d2063bd7938ecfa548951ccbd2154d6ae76343 100644 (file)
@@ -1004,31 +1004,16 @@ int Mod_LoadSkinFrame_Internal(skinframe_t *skinframe, const char *basename, int
                        Mem_Free(temp1);
                }
                // use either a custom palette, or the quake palette
-               if (palette)
-                       skinframe->base = skinframe->merged = GL_TextureForSkinLayer(skindata, width, height, va("%s_merged", basename), palette, textureflags); // all
-               else if (loadglowtexture)
-               {
+               skinframe->base = skinframe->merged = GL_TextureForSkinLayer(skindata, width, height, va("%s_merged", basename), palette ? palette : (loadglowtexture ? palette_nofullbrights : palette_complete), textureflags); // all
+               if (!palette && loadglowtexture)
                        skinframe->glow = GL_TextureForSkinLayer(skindata, width, height, va("%s_glow", basename), palette_onlyfullbrights, textureflags); // glow
-                       skinframe->base = skinframe->merged = GL_TextureForSkinLayer(skindata, width, height, va("%s_merged", basename), palette_nofullbrights, textureflags); // all but fullbrights
-                       if (loadpantsandshirt)
-                       {
-                               skinframe->pants = GL_TextureForSkinLayer(skindata, width, height, va("%s_pants", basename), palette_pantsaswhite, textureflags); // pants
-                               skinframe->shirt = GL_TextureForSkinLayer(skindata, width, height, va("%s_shirt", basename), palette_shirtaswhite, textureflags); // shirt
-                               if (skinframe->pants || skinframe->shirt)
-                                       skinframe->base = GL_TextureForSkinLayer(skindata, width, height, va("%s_nospecial", basename), palette_nocolormapnofullbrights, textureflags); // no special colors
-                       }
-               }
-               else
+               if (!palette && loadpantsandshirt)
                {
-                       skinframe->base = skinframe->merged = GL_TextureForSkinLayer(skindata, width, height, va("%s_merged", basename), palette_complete, textureflags); // all
-                       if (loadpantsandshirt)
-                       {
-                               skinframe->pants = GL_TextureForSkinLayer(skindata, width, height, va("%s_pants", basename), palette_pantsaswhite, textureflags); // pants
-                               skinframe->shirt = GL_TextureForSkinLayer(skindata, width, height, va("%s_shirt", basename), palette_shirtaswhite, textureflags); // shirt
-                               if (skinframe->pants || skinframe->shirt)
-                                       skinframe->base = GL_TextureForSkinLayer(skindata, width, height, va("%s_nospecial", basename), palette_nocolormap, textureflags); // no pants or shirt
-                       }
+                       skinframe->pants = GL_TextureForSkinLayer(skindata, width, height, va("%s_pants", basename), palette_pantsaswhite, textureflags); // pants
+                       skinframe->shirt = GL_TextureForSkinLayer(skindata, width, height, va("%s_shirt", basename), palette_shirtaswhite, textureflags); // shirt
                }
+               if (skinframe->pants || skinframe->shirt)
+                       skinframe->base = GL_TextureForSkinLayer(skindata, width, height, va("%s_nospecial", basename),loadglowtexture ? palette_nocolormapnofullbrights : palette_nocolormap, textureflags); // no special colors
                if (textureflags & TEXF_ALPHA)
                {
                        // if not using a custom alphapalette, use the quake one
index f18d7e01873b598c0549e17d4687534ae3b3a16e..c536b332e90b1891dd1bcd60c76ac6fd9bf21214 100644 (file)
--- a/palette.c
+++ b/palette.c
@@ -2,14 +2,15 @@
 #include "quakedef.h"
 
 unsigned int palette_complete[256];
+unsigned int palette_font[256];
+unsigned int palette_alpha[256];
+unsigned int palette_nocolormap[256];
+unsigned int palette_nocolormapnofullbrights[256];
 unsigned int palette_nofullbrights[256];
 unsigned int palette_onlyfullbrights[256];
-unsigned int palette_nocolormapnofullbrights[256];
-unsigned int palette_nocolormap[256];
 unsigned int palette_pantsaswhite[256];
 unsigned int palette_shirtaswhite[256];
-unsigned int palette_alpha[256];
-unsigned int palette_font[256];
+unsigned int palette_transparent[256];
 
 // John Carmack said the quake palette.lmp can be considered public domain because it is not an important asset to id, so I include it here as a fallback if no external palette file is found.
 unsigned char host_quakepal[768] =
@@ -29,6 +30,7 @@ void Palette_SetupSpecialPalettes(void)
        int pants_start, pants_end;
        int shirt_start, shirt_end;
        int reversed_start, reversed_end;
+       int transparentcolor;
        unsigned char *colormap;
        fs_offset_t filesize;
 
@@ -46,18 +48,21 @@ void Palette_SetupSpecialPalettes(void)
        shirt_end = 32;
        reversed_start = 128;
        reversed_end = 224;
+       transparentcolor = 255;
+
+       for (i = 0;i < 256;i++)
+               palette_transparent[i] = palette_complete[i];
+       palette_transparent[transparentcolor] = 0;
 
        for (i = 0;i < fullbright_start;i++)
                palette_nofullbrights[i] = palette_complete[i];
-       for (i = fullbright_start;i < 255;i++)
+       for (i = fullbright_start;i < fullbright_end;i++)
                palette_nofullbrights[i] = palette_complete[0];
-       palette_nofullbrights[255] = 0;
 
        for (i = 0;i < 256;i++)
                palette_onlyfullbrights[i] = palette_complete[0];
        for (i = fullbright_start;i < fullbright_end;i++)
                palette_onlyfullbrights[i] = palette_complete[i];
-       palette_onlyfullbrights[255] = 0;
 
        for (i = 0;i < 256;i++)
                palette_nocolormapnofullbrights[i] = palette_complete[i];
@@ -67,7 +72,6 @@ void Palette_SetupSpecialPalettes(void)
                palette_nocolormapnofullbrights[i] = palette_complete[0];
        for (i = fullbright_start;i < fullbright_end;i++)
                palette_nocolormapnofullbrights[i] = palette_complete[0];
-       palette_nocolormapnofullbrights[255] = 0;
 
        for (i = 0;i < 256;i++)
                palette_nocolormap[i] = palette_complete[i];
@@ -75,7 +79,6 @@ void Palette_SetupSpecialPalettes(void)
                palette_nocolormap[i] = palette_complete[0];
        for (i = shirt_start;i < shirt_end;i++)
                palette_nocolormap[i] = palette_complete[0];
-       palette_nocolormap[255] = 0;
 
        for (i = 0;i < 256;i++)
                palette_pantsaswhite[i] = palette_complete[0];
@@ -97,14 +100,13 @@ void Palette_SetupSpecialPalettes(void)
                        palette_shirtaswhite[i] = palette_complete[i - shirt_start];
        }
 
-       for (i = 0;i < 255;i++)
+       for (i = 0;i < 256;i++)
                palette_alpha[i] = 0xFFFFFFFF;
-       palette_alpha[255] = 0;
+       palette_alpha[transparentcolor] = 0;
 
-       palette_font[0] = 0;
-       for (i = 1;i < 255;i++)
+       for (i = 0;i < 256;i++)
                palette_font[i] = palette_complete[i];
-       palette_font[255] = 0;
+       palette_font[0] = 0;
 }
 
 void BuildGammaTable8(float prescale, float gamma, float scale, float base, unsigned char *out)
@@ -199,14 +201,13 @@ void Palette_Init(void)
                in = host_quakepal;
        }
        out = (unsigned char *) palette_complete; // palette is accessed as 32bit for speed reasons, but is created as 8bit bytes
-       for (i = 0;i < 255;i++)
+       for (i = 0;i < 256;i++)
        {
                *out++ = texturegammaramp[*in++];
                *out++ = texturegammaramp[*in++];
                *out++ = texturegammaramp[*in++];
                *out++ = 255;
        }
-       palette_complete[255] = 0; // completely transparent black
        if (palfile)
                Mem_Free(palfile);
 
index d344df278201762e84e1dc9c5fe21248d4137f70..c0afb198648c8368ddb21f31343bd646d1c3bb9a 100644 (file)
--- a/palette.h
+++ b/palette.h
@@ -3,14 +3,15 @@
 #define PALLETE_H
 
 extern unsigned int palette_complete[256];
+extern unsigned int palette_font[256];
+extern unsigned int palette_alpha[256];
+extern unsigned int palette_nocolormap[256];
+extern unsigned int palette_nocolormapnofullbrights[256];
 extern unsigned int palette_nofullbrights[256];
 extern unsigned int palette_onlyfullbrights[256];
-extern unsigned int palette_nocolormapnofullbrights[256];
-extern unsigned int palette_nocolormap[256];
 extern unsigned int palette_pantsaswhite[256];
 extern unsigned int palette_shirtaswhite[256];
-extern unsigned int palette_alpha[256];
-extern unsigned int palette_font[256];
+extern unsigned int palette_transparent[256];
 
 // used by hardware gamma functions in vid_* files
 void BuildGammaTable8(float prescale, float gamma, float scale, float base, unsigned char *out);