From eaa3f27fa7a517dfae5bda9e7ed86f9d80e9c213 Mon Sep 17 00:00:00 2001 From: havoc Date: Tue, 27 Dec 2005 02:29:40 +0000 Subject: [PATCH] reworked transparency in palettes, made palette_complete be strictly opaque, added palette_transparent (and switched a few things over to it), made palette_font actually be used (and it no longer has a transparent color 255, only color 0 is transparent in the font, correctly matching software quake), this should hopefully fix bugs with models using color 255 in their skin git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5865 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_draw.c | 11 +++-------- image.c | 2 +- menu.c | 2 +- model_shared.c | 29 +++++++---------------------- palette.c | 33 +++++++++++++++++---------------- palette.h | 9 +++++---- 6 files changed, 34 insertions(+), 52 deletions(-) diff --git a/gl_draw.c b/gl_draw.c index 7509ea46..db8579f4 100644 --- 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 549ca9c1..aeaca35c 100644 --- 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 eca046cf..0cb56cd3 100644 --- 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"); diff --git a/model_shared.c b/model_shared.c index 4354ee7e..91d2063b 100644 --- a/model_shared.c +++ b/model_shared.c @@ -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 diff --git a/palette.c b/palette.c index f18d7e01..c536b332 100644 --- 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); diff --git a/palette.h b/palette.h index d344df27..c0afb198 100644 --- 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); -- 2.39.2