diff --git a/libs/models/alias/gl_model_alias.c b/libs/models/alias/gl_model_alias.c index 210b6b445..210115885 100644 --- a/libs/models/alias/gl_model_alias.c +++ b/libs/models/alias/gl_model_alias.c @@ -132,7 +132,7 @@ Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group, maliasskindesc_t *skindesc) { byte *pskin; - char name[32]; + char name[32], modname[MAX_QPATH + 4]; int fb_texnum = 0, texnum = 0; pskin = Hunk_AllocName (skinsize, loadname); @@ -148,21 +148,23 @@ Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group, memcpy (player_8bit_texels, pskin, skinsize); } + QFS_StripExtension (loadmodel->name, modname); + if (!loadmodel->fullbright) { if (group) { - snprintf (name, sizeof (name), "fb_%s_%i_%i", loadmodel->name, + snprintf (name, sizeof (name), "fb_%s_%i_%i", modname, snum, gnum); } else { - snprintf (name, sizeof (name), "fb_%s_%i", loadmodel->name, snum); + snprintf (name, sizeof (name), "fb_%s_%i", modname, snum); } fb_texnum = Mod_Fullbright (pskin, pheader->mdl.skinwidth, pheader->mdl.skinheight, name); } if (group) { - snprintf (name, sizeof (name), "%s_%i_%i", loadmodel->name, snum, + snprintf (name, sizeof (name), "%s_%i_%i", modname, snum, gnum); } else { - snprintf (name, sizeof (name), "%s_%i", loadmodel->name, snum); + snprintf (name, sizeof (name), "%s_%i", modname, snum); } texnum = GL_LoadTexture (name, pheader->mdl.skinwidth, pheader->mdl.skinheight, pskin, true, false, 1); @@ -267,41 +269,61 @@ Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr) static void Mod_LoadExternalSkin (maliasskindesc_t *pskindesc, char *filename) { - tex_t *tex; + tex_t *tex, *glow; + char *ptr; - tex = LoadImage (va ("progs/%s", filename)); + ptr = strrchr (filename, '/'); + if (!ptr) + ptr = filename; + + tex = LoadImage (filename); if (!tex) - tex = LoadImage (va ("textures/%s", filename)); + tex = LoadImage (va ("textures/%s", ptr)); if (tex) { - if (tex->format < 4) - pskindesc->texnum = GL_LoadTexture - (filename, tex->width, tex->height, tex->data, true, false, 3); - else - pskindesc->texnum = GL_LoadTexture - (filename, tex->width, tex->height, tex->data, true, false, 4); + pskindesc->texnum = GL_LoadTexture (filename, tex->width, tex->height, + tex->data, true, false, + tex->format > 2 ? tex->format : 1); + + pskindesc->fb_texnum = 0; + + glow = LoadImage (va ("%s_glow", filename)); + if (!glow) + glow = LoadImage (va ("textures/%s_glow", ptr)); + if (glow) + pskindesc->fb_texnum = GL_LoadTexture (va ("fb_%s", filename), + glow->width, glow->height, + glow->data, true, true, + glow->format > 2 ? glow->format : 1); + else if (tex->format < 3) + pskindesc->fb_texnum = Mod_Fullbright (tex->data, tex->width, + tex->height, + va ("fb_%s", filename)); } } void Mod_LoadExternalSkins (model_t *mod) { - char filename[MAX_QPATH + 4]; + char filename[MAX_QPATH + 4], modname[MAX_QPATH + 4]; int i, j; maliasskindesc_t *pskindesc; maliasskingroup_t *pskingroup; + QFS_StripExtension (mod->name, modname); + for (i = 0; i < pheader->mdl.numskins; i++) { pskindesc = ((maliasskindesc_t *) ((byte *) pheader + pheader->skindesc)) + i; if (pskindesc->type == ALIAS_SKIN_SINGLE) { - snprintf (filename, sizeof (filename), "%s_%i", mod->name, i); + snprintf (filename, sizeof (filename), "%s_%i", modname, i); Mod_LoadExternalSkin (pskindesc, filename); } else { pskingroup = (maliasskingroup_t *) ((byte *) pheader + pskindesc->skin); + for (j = 0; j < pskingroup->numskins; j++) { snprintf (filename, sizeof (filename), "%s_%i_%i", - mod->name, i, j); + modname, i, j); Mod_LoadExternalSkin (pskingroup->skindescs + j, filename); } } diff --git a/libs/models/alias/model_alias.c b/libs/models/alias/model_alias.c index 100bc3158..5e2ab9ba7 100644 --- a/libs/models/alias/model_alias.c +++ b/libs/models/alias/model_alias.c @@ -291,6 +291,8 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator) Mod_FinalizeAliasModel (mod, pheader); + Mod_LoadExternalSkins (mod); + // move the complete, relocatable alias model to the cache end = Hunk_LowMark (); total = end - start; diff --git a/libs/models/brush/gl_model_brush.c b/libs/models/brush/gl_model_brush.c index fe6640ec8..17ac4312e 100644 --- a/libs/models/brush/gl_model_brush.c +++ b/libs/models/brush/gl_model_brush.c @@ -111,7 +111,8 @@ Mod_LoadExternalTextures (model_t *mod) if ((base = Mod_LoadAnExternalTexture (tx->name, mod->name))) { tx->gl_texturenum = GL_LoadTexture (tx->name, base->width, base->height, - base->data, true, false, base->format); + base->data, true, false, + base->format > 2 ? base->format : 1); luma = Mod_LoadAnExternalTexture (va ("%s_luma", tx->name), mod->name); @@ -120,14 +121,15 @@ Mod_LoadExternalTextures (model_t *mod) mod->name); tx->gl_fb_texturenum = 0; + if (luma) { tx->gl_fb_texturenum = GL_LoadTexture (va ("fb_%s", tx->name), luma->width, - luma->height, luma->data, true, true, - luma->format); - } else if (base->format == 1) { + luma->height, luma->data, true, true, + luma->format > 2 ? luma->format : 1); + } else if (base->format < 3) { tx->gl_fb_texturenum = - Mod_Fullbright (luma->data, luma->width, luma->height, + Mod_Fullbright (base->data, base->width, base->height, va ("fb_%s", tx->name)); } } diff --git a/libs/models/model.c b/libs/models/model.c index 028921b89..b221676d6 100644 --- a/libs/models/model.c +++ b/libs/models/model.c @@ -200,7 +200,6 @@ Mod_RealLoadModel (model_t *mod, qboolean crash, cache_allocator_t allocator) case IDPOLYHEADER: case POLYHEADER16: Mod_LoadAliasModel (mod, buf, allocator); - Mod_LoadExternalSkins (mod); break; case IDSPRITEHEADER: diff --git a/libs/util/quakefs.c b/libs/util/quakefs.c index b0992d471..144ea5083 100644 --- a/libs/util/quakefs.c +++ b/libs/util/quakefs.c @@ -1222,16 +1222,22 @@ QFS_SkipPath (const char *pathname) void QFS_StripExtension (const char *in, char *out) { - while (*in && *in != '.') - *out++ = *in++; - *out = 0; + char *tmp; + + strcpy (out, in); + + if ((tmp = strrchr (out, '.'))) + *tmp = 0; } const char * QFS_FileExtension (const char *in) { - while (*in && *in != '.') - in++; + char *tmp; + + if ((tmp = strrchr (in, '.'))) + return tmp; + return in; } diff --git a/libs/video/renderer/gl/gl_sky.c b/libs/video/renderer/gl/gl_sky.c index afe9c8037..914ac9fd2 100644 --- a/libs/video/renderer/gl/gl_sky.c +++ b/libs/video/renderer/gl/gl_sky.c @@ -127,7 +127,7 @@ R_LoadSkys (const char *skyname) qfglBindTexture (GL_TEXTURE_2D, SKY_TEX + i); targa = LoadImage (name = va ("env/%s%s", skyname, suf[i])); - if (!targa) { + if (!targa || targa->format < 3) { // FIXME Can't do PCX right now Con_DPrintf ("Couldn't load %s\n", name); // also look in gfx/env, where Darkplaces looks for skies targa = LoadImage (name = va ("gfx/env/%s%s", skyname, suf[i])); @@ -138,9 +138,11 @@ R_LoadSkys (const char *skyname) } } + // FIXME need better texture loading qfglTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, targa->width, - targa->height, 0, targa->format, GL_UNSIGNED_BYTE, - &targa->data); + targa->height, 0, + targa->format == 3 ? GL_RGB : GL_RGBA, + GL_UNSIGNED_BYTE, &targa->data); qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);