include/tga.h source/tga.c:

new function WriteTGAfile. Also, put in the tga header structure.
	NOTE: this is currently broken for non gcc ocmilers. you will get a
	#error message.
include/quakefs.h source/quakefs.c:
	new function COM_WriteBuffers. Like COM_WriteFile, but scatter/gather
	style.
source/gl_screen.c source/screen.c:
	misc cleanups. differences are getting fewer. should be mostly
	mergable soon (minus truly sw/gl specific code).
This commit is contained in:
Bill Currie 2000-12-11 06:38:58 +00:00
parent d1ef9bbc3f
commit 0bd4b8d288
6 changed files with 95 additions and 82 deletions

View file

@ -49,6 +49,8 @@ extern char com_gamedir[MAX_OSPATH];
extern char gamedirfile[MAX_OSPATH]; extern char gamedirfile[MAX_OSPATH];
void COM_WriteFile (char *filename, void *data, int len); void COM_WriteFile (char *filename, void *data, int len);
void COM_WriteBuffers (const char *filename, int count, ...);
int _COM_FOpenFile (char *filename, QFile **gzfile, char *foundname, int zip); int _COM_FOpenFile (char *filename, QFile **gzfile, char *foundname, int zip);
int COM_FOpenFile (char *filename, QFile **gzfile); int COM_FOpenFile (char *filename, QFile **gzfile);
void COM_CloseFile (QFile *h); void COM_CloseFile (QFile *h);

View file

@ -29,9 +29,29 @@
#ifndef __tga_h #ifndef __tga_h
#define __tga_h #define __tga_h
#include "gcc_attr.h"
#include "qtypes.h" #include "qtypes.h"
byte * #ifndef __GNUC__
LoadTGA (QFile *fin); #error do some data packing magic here (#pragma pack?)
#endif
typedef struct _TargaHeader {
unsigned char id_length __attribute__((packed));
unsigned char colormap_type __attribute__((packed));
unsigned char image_type __attribute__((packed));
unsigned short colormap_index __attribute__((packed));
unsigned short colormap_length __attribute__((packed));
unsigned char colormap_size __attribute__((packed));
unsigned short x_origin __attribute__((packed));
unsigned short y_origin __attribute__((packed));
unsigned short width __attribute__((packed));
unsigned short height __attribute__((packed));
unsigned char pixel_size __attribute__((packed));
unsigned char attributes __attribute__((packed));
} TargaHeader;
byte *LoadTGA (QFile *fin);
void WriteTGAfile (const char *tganame, byte *data, int width, int height);
#endif // __tga_h #endif // __tga_h

View file

@ -46,6 +46,7 @@
#include "sbar.h" #include "sbar.h"
#include "skin.h" #include "skin.h"
#include "sys.h" #include "sys.h"
#include "tga.h"
#include "view.h" #include "view.h"
/* /*
@ -182,7 +183,6 @@ SCR_CenterPrint (char *str)
} }
} }
void void
SCR_DrawCenterString (void) SCR_DrawCenterString (void)
{ {
@ -490,8 +490,6 @@ SCR_DrawFPS (void)
fps_count = 0; fps_count = 0;
lastframetime = t; lastframetime = t;
} }
/* Misty: I really do need to read about snprintf a bit. This thing keeps
chewing on my foot! */
snprintf (st, sizeof (st), "%-3d FPS", lastfps); snprintf (st, sizeof (st), "%-3d FPS", lastfps);
/* Misty: New trick! (for me) the ? makes this work like a if then else - /* Misty: New trick! (for me) the ? makes this work like a if then else -
IE: if cl_hudswap->int_val is not null, do first case, else (else is a IE: if cl_hudswap->int_val is not null, do first case, else (else is a
@ -620,15 +618,6 @@ SCR_DrawConsole (void)
============================================================================== ==============================================================================
*/ */
typedef struct _TargaHeader {
unsigned char id_length, colormap_type, image_type;
unsigned short colormap_index, colormap_length;
unsigned char colormap_size;
unsigned short x_origin, y_origin, width, height;
unsigned char pixel_size, attributes;
} TargaHeader;
/* /*
SCR_ScreenShot_f SCR_ScreenShot_f
*/ */
@ -645,21 +634,10 @@ SCR_ScreenShot_f (void)
Con_Printf ("SCR_ScreenShot_f: Couldn't create a TGA file\n"); Con_Printf ("SCR_ScreenShot_f: Couldn't create a TGA file\n");
return; return;
} }
buffer = malloc (glwidth * glheight * 3);
buffer = malloc (glwidth * glheight * 3 + 18);
memset (buffer, 0, 18);
buffer[2] = 2; // uncompressed type
buffer[12] = glwidth & 255;
buffer[13] = glwidth >> 8;
buffer[14] = glheight & 255;
buffer[15] = glheight >> 8;
buffer[16] = 24; // pixel size
glReadPixels (glx, gly, glwidth, glheight, GL_BGR, GL_UNSIGNED_BYTE, glReadPixels (glx, gly, glwidth, glheight, GL_BGR, GL_UNSIGNED_BYTE,
buffer + 18); buffer);
COM_WriteFile (pcxname, buffer, glwidth * glheight * 3 + 18); WriteTGAfile (pcxname, buffer, glwidth, glheight);
free (buffer); free (buffer);
Con_Printf ("Wrote %s\n", pcxname); Con_Printf ("Wrote %s\n", pcxname);
} }
@ -850,14 +828,10 @@ SCR_RSShot_f (void)
free (newbuf); free (newbuf);
Con_Printf ("Wrote %s\n", pcxname); Con_Printf ("Wrote %s\n", pcxname);
Con_Printf ("Sending shot to server...\n");
} }
//=============================================================================
//============================================================================= //=============================================================================
char *scr_notifystring; char *scr_notifystring;

View file

@ -29,21 +29,9 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#include "qtypes.h"
#include "quakefs.h"
#include "sys.h"
#include "console.h"
#include "draw.h"
#include "cmd.h"
#include "cvar.h"
#include "commdef.h"
#include "qendian.h"
#include "info.h"
#include "server.h"
#include "va.h"
#include "qargs.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
@ -67,6 +55,20 @@
#define _POSIX_ #define _POSIX_
#endif #endif
#include <limits.h> #include <limits.h>
#include "qtypes.h"
#include "quakefs.h"
#include "sys.h"
#include "console.h"
#include "draw.h"
#include "cmd.h"
#include "cvar.h"
#include "commdef.h"
#include "qendian.h"
#include "info.h"
#include "server.h"
#include "va.h"
#include "qargs.h"
// LordHavoc: win32 would not compile without this // LordHavoc: win32 would not compile without this
#ifndef __const #ifndef __const
@ -393,6 +395,40 @@ COM_WriteFile (char *filename, void *data, int len)
Qclose (f); Qclose (f);
} }
/*
COM_WriteBuffers
The filename will be prefixed by the current game directory
*/
void
COM_WriteBuffers (const char *filename, int count, ...)
{
QFile *f;
char name[MAX_OSPATH];
va_list args;
va_start (args, count);
snprintf (name, sizeof (name), "%s/%s", com_gamedir, filename);
f = Qopen (name, "wb");
if (!f) {
Sys_mkdir (com_gamedir);
f = Qopen (name, "wb");
if (!f)
Sys_Error ("Error opening %s", filename);
}
Sys_Printf ("COM_WriteFile: %s\n", name);
while (count--) {
void *data = va_arg (args, void*);
int len = va_arg (args, int);
Qwrite (f, data, len);
}
Qclose (f);
va_end (args);
}
/* /*
COM_CreatePath COM_CreatePath

View file

@ -183,26 +183,6 @@ SCR_CenterPrint (char *str)
} }
} }
void
SCR_EraseCenterString (void)
{
int y;
if (scr_erase_center++ > vid.numpages) {
scr_erase_lines = 0;
return;
}
if (scr_center_lines <= 4)
y = vid.height * 0.35;
else
y = 48;
scr_copytop = 1;
Draw_TileClear (0, y, vid.width,
min (8 * scr_erase_lines, vid.height - y - 1));
}
void void
SCR_DrawCenterString (void) SCR_DrawCenterString (void)
{ {
@ -624,13 +604,8 @@ SCR_SetUpToDrawConsole (void)
} }
if (clearconsole++ < vid.numpages) { if (clearconsole++ < vid.numpages) {
scr_copytop = 1;
Draw_TileClear (0, (int) scr_con_current, vid.width,
vid.height - (int) scr_con_current);
Sbar_Changed (); Sbar_Changed ();
} else if (clearnotify++ < vid.numpages) { } else if (clearnotify++ < vid.numpages) {
scr_copytop = 1;
Draw_TileClear (0, 0, vid.width, con_notifylines);
} else } else
con_notifylines = 0; con_notifylines = 0;
} }
@ -871,7 +846,7 @@ SCR_RSShot_f (void)
// mapped in // mapped in
// for linear writes all the time // for linear writes all the time
// Con_Printf ("Wrote %s\n", pcxname); Con_Printf ("Wrote %s\n", pcxname);
Con_Printf ("Sending shot to server...\n"); Con_Printf ("Sending shot to server...\n");
} }
@ -993,7 +968,6 @@ SCR_UpdateScreen (void)
SCR_SetUpToDrawConsole (); SCR_SetUpToDrawConsole ();
SCR_EraseCenterString ();
D_DisableBackBufferAccess (); // for adapters that can't stay D_DisableBackBufferAccess (); // for adapters that can't stay
// mapped in // mapped in

View file

@ -30,19 +30,11 @@
# include "config.h" # include "config.h"
#endif #endif
#include "qendian.h"
#include "quakefs.h" #include "quakefs.h"
#include "sys.h" #include "sys.h"
#include "tga.h" #include "tga.h"
typedef struct _TargaHeader {
unsigned char id_length, colormap_type, image_type;
unsigned short colormap_index, colormap_length;
unsigned char colormap_size;
unsigned short x_origin, y_origin, width, height;
unsigned char pixel_size, attributes;
} TargaHeader;
static int static int
fgetLittleShort (QFile *f) fgetLittleShort (QFile *f)
{ {
@ -229,3 +221,18 @@ LoadTGA (QFile *fin)
Qclose (fin); Qclose (fin);
return targa_rgba; return targa_rgba;
} }
void
WriteTGAfile (const char *tganame, byte *data, int width, int height)
{
TargaHeader header;
memset (&header, 0, sizeof (header));
header.image_type = 2; // uncompressed type
header.width = LittleShort (width);
header.height = LittleShort (height);
header.pixel_size = 24;
COM_WriteBuffers (tganame, 2, &header, sizeof (header), data,
width * height * 3);
}