LoadImage is now used for all external textures giving almost transparent

.png and .tga support.
This commit is contained in:
Bill Currie 2003-09-04 18:46:59 +00:00
parent 753dc02deb
commit 39ed540979
7 changed files with 49 additions and 100 deletions

View file

@ -34,6 +34,6 @@
#include "QF/quakeio.h"
struct tex_s *LoadImage (const char *imageFile, QFile *fp);
struct tex_s *LoadImage (const char *imageFile);
#endif//__QF_image_h

View file

@ -47,13 +47,14 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "QF/tga.h"
tex_t *
LoadImage (const char *imageFile, QFile *fp)
LoadImage (const char *imageFile)
{
int tmp;
dstring_t *tmpFile;
char *ext;
tex_t *tex = NULL;
QFile *fp;
/* Get the file name without extension */
tmpFile = dstring_new ();
dstring_copystr (tmpFile, imageFile);
@ -61,7 +62,7 @@ LoadImage (const char *imageFile, QFile *fp)
if (ext)
tmp = ext - tmpFile->str;
else
tmp = tmpFile->size;
tmp = tmpFile->size - 1;
/* Check for a .png */
dstring_replace (tmpFile, tmp, tmpFile->size, ".png", 5);

View file

@ -41,13 +41,13 @@ static __attribute__ ((unused)) const char rcsid[] =
# include <strings.h>
#endif
#include "QF/image.h"
#include "QF/model.h"
#include "QF/qendian.h"
#include "QF/quakefs.h"
#include "QF/skin.h"
#include "QF/sys.h"
#include "QF/texture.h"
#include "QF/tga.h"
#include "QF/va.h"
#include "QF/vid.h"
#include "QF/GL/qf_textures.h"
@ -268,27 +268,18 @@ Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr)
static void
Mod_LoadExternalSkin (maliasskindesc_t *pskindesc, char *filename)
{
tex_t *targa;
QFile *f;
tex_t *tex;
QFS_FOpenFile (filename, &f);
if (!f) {
QFS_FOpenFile (va ("progs/%s", filename), &f);
}
if (!f) {
QFS_FOpenFile (va ("textures/%s", filename), &f);
}
if (f) {
targa = LoadTGA (f);
Qclose (f);
if (targa->format < 4)
tex = LoadImage (va ("progs/%s", filename));
if (!tex)
tex = LoadImage (va ("textures/%s", filename));
if (tex) {
if (tex->format < 4)
pskindesc->texnum = GL_LoadTexture
(filename, targa->width, targa->height, targa->data, true,
false, 3);
(filename, tex->width, tex->height, tex->data, true, false, 3);
else
pskindesc->texnum = GL_LoadTexture
(filename, targa->width, targa->height, targa->data, true,
false, 4);
(filename, tex->width, tex->height, tex->data, true, false, 4);
}
}
@ -304,13 +295,13 @@ Mod_LoadExternalSkins (model_t *mod)
pskindesc = ((maliasskindesc_t *)
((byte *) pheader + pheader->skindesc)) + i;
if (pskindesc->type == ALIAS_SKIN_SINGLE) {
snprintf (filename, sizeof (filename), "%s_%i.tga", mod->name, i);
snprintf (filename, sizeof (filename), "%s_%i", mod->name, 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.tga",
snprintf (filename, sizeof (filename), "%s_%i_%i",
mod->name, i, j);
Mod_LoadExternalSkin (pskingroup->skindescs + j, filename);
}

View file

@ -43,12 +43,12 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/image.h"
#include "QF/model.h"
#include "QF/qendian.h"
#include "QF/quakefs.h"
#include "QF/sys.h"
#include "QF/texture.h"
#include "QF/tga.h"
#include "QF/va.h"
#include "QF/vid.h"
#include "QF/GL/qf_textures.h"
@ -74,11 +74,9 @@ Mod_ProcessTexture (miptex_t *mt, texture_t *tx)
void
Mod_LoadExternalTextures (model_t *mod)
{
char *filename;
int i;
tex_t *targa;
texture_t *tx;
QFile *f;
for (i = 0; i < mod->numtextures; i++) {
tx = mod->textures[i];
@ -87,36 +85,24 @@ Mod_LoadExternalTextures (model_t *mod)
// FIXME: replace special flag characters with # or _?
if (tx->name[0] == '*') {
filename = va ("textures/%.*s/#%s.tga",
(int) strlen (mod->name + 5) - 4,
mod->name + 5, tx->name + 1);
QFS_FOpenFile (filename, &f);
if (!f) {
filename = va ("textures/#%s.tga", tx->name + 1);
QFS_FOpenFile (filename, &f);
}
if (!f) {
filename = va ("maps/#%s.tga", tx->name + 1);
QFS_FOpenFile (filename, &f);
}
targa = LoadImage (va ("textures/%.*s/#%s",
(int) strlen (mod->name + 5) - 4,
mod->name + 5, tx->name + 1));
if (!targa)
targa = LoadImage (va ("textures/#%s", tx->name + 1));
if (!targa)
targa = LoadImage (va ("maps/#%s", tx->name + 1));
} else {
filename = va ("textures/%.*s/%s.tga",
(int) strlen (mod->name + 5) - 4,
mod->name + 5, tx->name);
QFS_FOpenFile (filename, &f);
if (!f) {
filename = va ("textures/%s.tga", tx->name);
QFS_FOpenFile (filename, &f);
}
if (!f) {
filename = va ("maps/%s.tga", tx->name);
QFS_FOpenFile (filename, &f);
}
targa = LoadImage (va ("textures/%.*s/%s",
(int) strlen (mod->name + 5) - 4,
mod->name + 5, tx->name));
if (!targa)
targa = LoadImage (va ("textures/%s", tx->name));
if (!targa)
targa = LoadImage (va ("maps/%s", tx->name));
}
if (f) {
targa = LoadTGA (f);
Qclose (f);
if (targa) {
if (targa->format < 4) {
tx->gl_texturenum =
GL_LoadTexture (tx->name, targa->width, targa->height,

View file

@ -39,10 +39,11 @@ static __attribute__ ((unused)) const char rcsid[] =
#endif
#include "QF/console.h"
#include "QF/image.h"
#include "QF/model.h"
#include "QF/quakefs.h"
#include "QF/texture.h"
#include "QF/tga.h"
#include "QF/va.h"
#include "QF/GL/qf_textures.h"
#include "compat.h"
@ -50,18 +51,11 @@ static __attribute__ ((unused)) const char rcsid[] =
void
Mod_SpriteLoadTexture (mspriteframe_t *pspriteframe, int framenum)
{
char name[64];
char filename[MAX_QPATH + 4];
tex_t *targa;
QFile *f;
const char *name;
snprintf (name, sizeof (name), "%s_%i", loadmodel->name, framenum);
snprintf (filename, sizeof (filename), "%s.tga", name);
QFS_FOpenFile (filename, &f);
if (f) {
targa = LoadTGA (f);
Qclose (f);
targa = LoadImage (name = va ("%s_%i", loadmodel->name, framenum));
if (targa) {
if (targa->format < 4)
pspriteframe->gl_texturenum = GL_LoadTexture (name,
targa->width, targa->height, targa->data,

View file

@ -45,12 +45,12 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "QF/cvar.h"
#include "QF/draw.h"
#include "QF/dstring.h"
#include "QF/image.h"
#include "QF/quakefs.h"
#include "QF/render.h"
#include "QF/screen.h"
#include "QF/sys.h"
#include "QF/texture.h"
#include "QF/tga.h"
#include "QF/va.h"
#include "QF/vid.h"
#include "QF/GL/defines.h"
@ -177,17 +177,11 @@ Draw_PicFromWad (const char *name)
{
glpic_t *gl;
qpic_t *p;
dstring_t *filename = dstring_new ();
QFile *f;
tex_t *targa;
dsprintf (filename, "%s.tga", name);
QFS_FOpenFile (filename->str, &f);
dstring_delete (filename);
if (f) {
targa = LoadTGA (f);
Qclose (f);
targa = LoadImage (name);
if (targa) {
p = malloc (sizeof (qpic_t));
p->width = targa->width;
p->height = targa->height;
@ -223,9 +217,7 @@ Draw_CachePic (const char *path, qboolean alpha)
cachepic_t *pic;
int i;
glpic_t *gl;
QFile *f;
tex_t *targa;
char *filename;
// First, check if its cached..
for (pic = cachepics, i = 0; i < numcachepics; pic++, i++)
@ -239,13 +231,8 @@ Draw_CachePic (const char *path, qboolean alpha)
gl = (glpic_t *) pic->pic.data;
// Check for a .tga first
filename = strdup (path);
if (!strcmp (filename + strlen(filename) - 4, ".lmp"))
strcpy (filename + strlen(filename) - 4, ".tga");
QFS_FOpenFile (filename, &f);
if (f) {
targa = LoadTGA (f);
Qclose (f);
targa = LoadImage (path);
if (targa) {
if (targa->format < 4)
gl->texnum = GL_LoadTexture ("", targa->width, targa->height,
targa->data, false, alpha, 3);
@ -278,11 +265,6 @@ Draw_CachePic (const char *path, qboolean alpha)
pic->dirty = false;
numcachepics++;
// FIXME: A really ugly kluge, keep a specific image in memory
// for the menu system. Some days I really dislike legacy support..
free (filename);
// And now we are done, return what was asked for..
return &pic->pic;
}

View file

@ -40,10 +40,11 @@ static __attribute__ ((unused)) const char rcsid[] =
#include "QF/console.h"
#include "QF/cvar.h"
#include "QF/image.h"
#include "QF/quakefs.h"
#include "QF/render.h"
#include "QF/texture.h"
#include "QF/tga.h"
#include "QF/va.h"
#include "QF/vid.h"
#include "QF/GL/defines.h"
#include "QF/GL/funcs.h"
@ -113,9 +114,8 @@ vec5_t skyvec[6][4] = {
void
R_LoadSkys (const char *skyname)
{
char name[64];
const char *name;
int i, j;
QFile *f;
if (strcasecmp (skyname, "none") == 0) {
skyloaded = false;
@ -127,22 +127,17 @@ R_LoadSkys (const char *skyname)
tex_t *targa;
qfglBindTexture (GL_TEXTURE_2D, SKY_TEX + i);
snprintf (name, sizeof (name), "env/%s%s.tga", skyname, suf[i]);
QFS_FOpenFile (name, &f);
if (!f) {
targa = LoadImage (name = va ("env/%s%s", skyname, suf[i]));
if (!targa) {
Con_DPrintf ("Couldn't load %s\n", name);
// also look in gfx/env, where Darkplaces looks for skies
snprintf (name, sizeof (name), "gfx/env/%s%s.tga", skyname,
suf[i]);
QFS_FOpenFile (name, &f);
if (!f) {
targa = LoadImage (name = va ("gfx/env/%s%s", skyname, suf[i]));
if (!targa) {
Con_DPrintf ("Couldn't load %s\n", name);
skyloaded = false;
continue;
}
}
targa = LoadTGA (f);
Qclose (f);
qfglTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, targa->width,
targa->height, 0, GL_RGBA, GL_UNSIGNED_BYTE,