fix screenshots when width isn't a multiple of 4. explained by Sander van Dijk.

also check that malloc() didn't fail.

git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@909 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2014-04-28 08:12:42 +00:00
parent 5e6683608d
commit 1dc482677d

View file

@ -118,6 +118,7 @@ float scr_disabled_time;
int scr_tileclear_updates = 0; //johnfitz
static GLint gl_pack_alignment = 4;
void SCR_ScreenShot_f (void);
/*
@ -425,6 +426,7 @@ void SCR_Init (void)
SCR_LoadPics (); //johnfitz
glGetIntegerv (GL_PACK_ALIGNMENT, &gl_pack_alignment);
scr_initialized = true;
}
@ -781,8 +783,14 @@ void SCR_ScreenShot_f (void)
}
//get data
buffer = (byte *) malloc(glwidth*glheight*3);
if (!(buffer = (byte *) malloc(glwidth*glheight*3)))
{
Con_Printf ("SCR_ScreenShot_f: Couldn't allocate memory\n");
return;
}
glPixelStorei (GL_PACK_ALIGNMENT, 1);/* for widths that aren't a multiple of 4 */
glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer);
glPixelStorei (GL_PACK_ALIGNMENT, gl_pack_alignment);
// now write the file
if (Image_WriteTGA (tganame, buffer, glwidth, glheight, 24, false))