Add functions to create/destroy qpics.

The creation uses raw 8-bit data (and the system palette). Destroying a
qpic loaded via other means will probably produce nasal demons.
This commit is contained in:
Bill Currie 2012-02-01 17:46:15 +09:00
parent 2b6adaa2d4
commit bc2aca53c3
5 changed files with 93 additions and 4 deletions

View File

@ -183,6 +183,22 @@ qpic_t *Draw_CachePic (const char *path, qboolean alpha);
*/
void Draw_UncachePic (const char *path);
/** Create a qpic from raw data.
\param width The width of the pic.
\param height The height of the pic.
\param data The raw data bytes. The system palette will be used for
colors.
\return pointer qpic data.
*/
qpic_t *Draw_MakePic (int width, int height, const byte *data);
/** Destroy a qpic created by Draw_MakePic.
\param pic The qpic to destory.
*/
void Draw_DestroyPic (qpic_t *pic);
/** Load a qpic from gfx.wad.
\param name name of the was lump to load
\return pointer qpic data.

View File

@ -150,6 +150,27 @@ Draw_InitText (void)
tVAindices[i] = i;
}
VISIBLE qpic_t *
Draw_MakePic (int width, int height, const byte *data)
{
glpic_t *gl;
qpic_t *pic;
pic = malloc (field_offset (qpic_t, data[sizeof (glpic_t)]));
pic->width = width;
pic->height = height;
gl = (glpic_t *) pic->data;
gl->texnum = GL_LoadTexture ("", width, height, data, false, true, 1);
return pic;
}
VISIBLE void
Draw_DestroyPic (qpic_t *pic)
{
//FIXME gl texture management sucks
free (pic);
}
VISIBLE qpic_t *
Draw_PicFromWad (const char *name)
{

View File

@ -272,6 +272,18 @@ draw_pic (int x, int y, int w, int h, qpic_t *pic,
qfglDisableVertexAttribArray (quake_icon.vertex.location);
}
VISIBLE qpic_t *
Draw_MakePic (int width, int height, const byte *data)
{
return pic_data (0, width, height, data);
}
VISIBLE void
Draw_DestroyPic (qpic_t *pic)
{
pic_free (pic);
}
VISIBLE qpic_t *
Draw_PicFromWad (const char *name)
{

View File

@ -28,8 +28,7 @@
# include "config.h"
#endif
static __attribute__ ((used)) const char rcsid[] =
"$Id$";
static __attribute__ ((used)) const char rcsid[] = "$Id$";
#ifdef HAVE_STRING_H
# include <string.h>
@ -38,6 +37,8 @@ static __attribute__ ((used)) const char rcsid[] =
# include <strings.h>
#endif
#include <stdlib.h>
#include "QF/cvar.h"
#include "QF/draw.h"
#include "QF/quakefs.h"
@ -94,6 +95,25 @@ int numcachepics;
} while (0)
VISIBLE qpic_t *
Draw_MakePic (int width, int height, const byte *data)
{
qpic_t *pic;
int size = width * height;
pic = malloc (field_offset (qpic_t, data[size]));
pic->width = width;
pic->height = height;
memcpy (pic->data, data, size);
return pic;
}
VISIBLE void
Draw_DestroyPic (qpic_t *pic)
{
free (pic);
}
VISIBLE qpic_t *
Draw_PicFromWad (const char *name)
{

View File

@ -28,8 +28,7 @@
# include "config.h"
#endif
static __attribute__ ((used)) const char rcsid[] =
"$Id$";
static __attribute__ ((used)) const char rcsid[] = "$Id$";
#ifdef HAVE_STRING_H
# include <string.h>
@ -38,6 +37,8 @@ static __attribute__ ((used)) const char rcsid[] =
# include <strings.h>
#endif
#include <stdlib.h>
#include "QF/cvar.h"
#include "QF/draw.h"
#include "QF/quakefs.h"
@ -94,6 +95,25 @@ int numcachepics;
} while (0)
VISIBLE qpic_t *
Draw_MakePic (int width, int height, const byte *data)
{
qpic_t *pic;
int size = width * height;
pic = malloc (field_offset (qpic_t, data[size]));
pic->width = width;
pic->height = height;
memcpy (pic->data, data, size);
return pic;
}
VISIBLE void
Draw_DestroyPic (qpic_t *pic)
{
free (pic);
}
VISIBLE qpic_t *
Draw_PicFromWad (const char *name)
{