]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - palette.c
fixed some dynamic lighting bugs related to glowing self
[xonotic/darkplaces.git] / palette.c
index c7dd2e85b99a5eb3280d9a66b37b6057e9a6d610..1978eefe1fded65a6595b0cd1144141d8a51079a 100644 (file)
--- a/palette.c
+++ b/palette.c
@@ -1,7 +1,15 @@
 
 #include "quakedef.h"
 
-unsigned int d_8to24table[256];
+unsigned int palette_complete[256];
+unsigned int palette_nofullbrights[256];
+unsigned int palette_onlyfullbrights[256];
+unsigned int palette_nocolormapnofullbrights[256];
+unsigned int palette_pantsaswhite[256];
+unsigned int palette_shirtaswhite[256];
+unsigned int palette_alpha[256];
+unsigned int palette_font[256];
+
 qbyte host_basepal[768];
 
 cvar_t v_gamma = {CVAR_SAVE, "v_gamma", "1"};
@@ -13,18 +21,90 @@ cvar_t v_hwgamma = {0, "v_hwgamma", "1"};
 void Palette_Setup8to24(void)
 {
        int i;
+       int fullbright_start, fullbright_end;
+       int pants_start, pants_end;
+       int shirt_start, shirt_end;
+       int reversed_start, reversed_end;
        qbyte *in, *out;
+       qbyte *colormap;
 
        in = host_basepal;
-       out = (qbyte *) d_8to24table; // d_8to24table is accessed as 32bit for speed reasons, but is created as 8bit bytes
-       for (i=0 ; i<255 ; i++)
+       out = (qbyte *) palette_complete; // palette is accessed as 32bit for speed reasons, but is created as 8bit bytes
+       for (i = 0;i < 255;i++)
        {
                *out++ = *in++;
                *out++ = *in++;
                *out++ = *in++;
                *out++ = 255;
        }
-       d_8to24table[255] = 0; // completely transparent black
+       palette_complete[255] = 0; // completely transparent black
+
+       // FIXME: fullbright_start should be read from colormap.lmp
+       colormap = COM_LoadFile("gfx/colormap.lmp", true);
+       if (colormap && com_filesize >= 16385)
+               fullbright_start = 256 - colormap[16384];
+       else
+               fullbright_start = 256;
+       if (colormap)
+               Mem_Free(colormap);
+       fullbright_end = 256;
+       pants_start = 96;
+       pants_end = 112;
+       shirt_start = 16;
+       shirt_end = 32;
+       reversed_start = 128;
+       reversed_end = 224;
+
+       for (i = 0;i < fullbright_start;i++)
+               palette_nofullbrights[i] = palette_complete[i];
+       for (i = fullbright_start;i < 255;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];
+       for (i = pants_start;i < pants_end;i++)
+               palette_nocolormapnofullbrights[i] = palette_complete[0];
+       for (i = shirt_start;i < shirt_end;i++)
+               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_pantsaswhite[i] = palette_complete[0];
+       for (i = pants_start;i < pants_end;i++)
+       {
+               if (i >= reversed_start && i < reversed_end)
+                       palette_pantsaswhite[i] = palette_complete[15 - (i - pants_start)];
+               else
+                       palette_pantsaswhite[i] = palette_complete[i - pants_start];
+       }
+
+       for (i = 0;i < 256;i++)
+               palette_shirtaswhite[i] = palette_complete[0];
+       for (i = shirt_start;i < shirt_end;i++)
+       {
+               if (i >= reversed_start && i < reversed_end)
+                       palette_shirtaswhite[i] = palette_complete[15 - (i - shirt_start)];
+               else
+                       palette_shirtaswhite[i] = palette_complete[i - shirt_start];
+       }
+
+       for (i = 0;i < 255;i++)
+               palette_alpha[i] = 0xFFFFFFFF;
+       palette_alpha[255] = 0;
+
+       palette_font[0] = 0;
+       for (i = 1;i < 255;i++)
+               palette_font[i] = palette_complete[i];
+       palette_font[255] = 0;
 }