2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2002-08-25 14:25:38 +00:00
|
|
|
gl_model_sprite.c
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-08-25 14:25:38 +00:00
|
|
|
gl support routines for sprite model loading and caching
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2003-09-04 18:46:59 +00:00
|
|
|
#include "QF/image.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2003-09-04 18:46:59 +00:00
|
|
|
#include "QF/va.h"
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/qf_textures.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-07-22 05:40:34 +00:00
|
|
|
#include "compat.h"
|
2012-02-14 12:25:19 +00:00
|
|
|
#include "mod_internal.h"
|
2001-07-22 05:40:34 +00:00
|
|
|
|
2021-12-13 23:36:19 +00:00
|
|
|
static int
|
|
|
|
load_texture (model_t *mod, int framenum, const dspriteframe_t *dframe)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-01-11 04:20:41 +00:00
|
|
|
tex_t *targa;
|
2003-09-04 18:46:59 +00:00
|
|
|
const char *name;
|
2002-01-11 04:20:41 +00:00
|
|
|
|
2021-02-01 05:39:00 +00:00
|
|
|
targa = LoadImage (name = va (0, "%s_%i", mod->path, framenum), 1);
|
2003-09-04 18:46:59 +00:00
|
|
|
if (targa) {
|
2021-12-13 23:36:19 +00:00
|
|
|
if (targa->format < 4) {
|
|
|
|
return GL_LoadTexture (name, targa->width, targa->height,
|
|
|
|
targa->data, true, false, 3);
|
|
|
|
} else {
|
|
|
|
return GL_LoadTexture (name, targa->width, targa->height,
|
|
|
|
targa->data, true, true, 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return GL_LoadTexture (name, dframe->width, dframe->height,
|
|
|
|
(const byte *)(dframe + 1), true, true, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gl_Mod_SpriteLoadFrames (mod_sprite_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < ctx->numframes; i++) {
|
|
|
|
__auto_type dframe = ctx->dframes[i];
|
|
|
|
size_t size = sizeof (mspriteframe_t);
|
|
|
|
mspriteframe_t *frame = Hunk_AllocName (0, size, ctx->mod->name);
|
|
|
|
*ctx->frames[i] = frame;
|
|
|
|
Mod_LoadSpriteFrame (frame, dframe);
|
|
|
|
frame->gl_texturenum = load_texture (ctx->mod, ctx->frame_numbers[i],
|
|
|
|
dframe);
|
2002-01-11 04:20:41 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|