From 43dcecee10781e53e11ce4f9a4d4a6a43074db82 Mon Sep 17 00:00:00 2001 From: lordhavoc Date: Mon, 29 Jan 2001 06:10:57 +0000 Subject: [PATCH] make screenshots rightside up again (or rather, upside down like TGA wants, which happens to be the output format of glReadPixels, a fact I was unaware of, so the flipping was turning it to rightside up, which is upside down in TGA... follow that logic? good :) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@137 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_screen.c | 2 +- image.c | 29 +++++++++++++++++++++++++++++ image.h | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/gl_screen.c b/gl_screen.c index 722dfa60..045afa6e 100644 --- a/gl_screen.c +++ b/gl_screen.c @@ -617,7 +617,7 @@ void SCR_ScreenShot_f (void) buffer = malloc(glwidth*glheight*3); glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer); - Image_WriteTGARGB(filename, glwidth, glheight, buffer); + Image_WriteTGARGB_preflipped(filename, glwidth, glheight, buffer); free (buffer); Con_Printf ("Wrote %s\n", filename); diff --git a/image.c b/image.c index f4520e98..4ba31707 100644 --- a/image.c +++ b/image.c @@ -539,6 +539,35 @@ int loadtextureimagewithmask (char* filename, int matchwidth, int matchheight, q return texnum; } +void Image_WriteTGARGB_preflipped (char *filename, int width, int height, byte *data) +{ + byte *buffer, *in, *out, *end; + + buffer = malloc(width*height*3 + 18); + + memset (buffer, 0, 18); + buffer[2] = 2; // uncompressed type + buffer[12] = (width >> 0) & 0xFF; + buffer[13] = (width >> 8) & 0xFF; + buffer[14] = (height >> 0) & 0xFF; + buffer[15] = (height >> 8) & 0xFF; + buffer[16] = 24; // pixel size + + // swap rgb to bgr + in = data; + out = buffer + 18; + end = in + width*height*3; + for (;in < end;in += 3) + { + *out++ = in[2]; + *out++ = in[1]; + *out++ = in[0]; + } + COM_WriteFile (filename, buffer, width*height*3 + 18 ); + + free(buffer); +} + void Image_WriteTGARGB (char *filename, int width, int height, byte *data) { int y; diff --git a/image.h b/image.h index 20096ff8..ebaafd58 100644 --- a/image.h +++ b/image.h @@ -8,5 +8,6 @@ extern byte* loadimagepixelsmask (char* filename, qboolean complain, int matchwi extern int loadtextureimagemask (char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap); extern int image_masktexnum; extern int loadtextureimagewithmask (char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap); +extern void Image_WriteTGARGB_preflipped (char *filename, int width, int height, byte *data); extern void Image_WriteTGARGB (char *filename, int width, int height, byte *data); extern void Image_WriteTGARGBA (char *filename, int width, int height, byte *data); -- 2.39.2