Add a very crude screenshot function (press F3)

Files are named after the current date+time (down to seconds),
and written to the gameFolder directory.
This commit is contained in:
Jonas Kulla 2013-12-20 09:17:15 +01:00
parent 3a5c4eba52
commit cb36a28b09
3 changed files with 49 additions and 1 deletions

View File

@ -185,6 +185,9 @@ void EventThread::process(RGSSThreadData &rtData)
break; break;
} }
if (event.key.keysym.scancode == SDL_SCANCODE_F3)
rtData.rqScreenshot = true;
keyStates[event.key.keysym.scancode] = true; keyStates[event.key.keysym.scancode] = true;
break; break;

View File

@ -176,6 +176,8 @@ struct RGSSThreadData
QByteArray rgssErrorMsg; QByteArray rgssErrorMsg;
volatile bool rqScreenshot;
RGSSThreadData(EventThread *ethread, RGSSThreadData(EventThread *ethread,
const char *argv0, const char *argv0,
SDL_Window *window) SDL_Window *window)
@ -184,7 +186,8 @@ struct RGSSThreadData
ethread(ethread), ethread(ethread),
argv0(argv0), argv0(argv0),
window(window), window(window),
sizeResoRatio(1, 1) sizeResoRatio(1, 1),
rqScreenshot(false)
{} {}
}; };

View File

@ -37,8 +37,10 @@
#include <SDL_video.h> #include <SDL_video.h>
#include <SDL_timer.h> #include <SDL_timer.h>
#include <SDL_image.h>
#include <time.h> #include <time.h>
#include <sys/time.h>
#include <algorithm> #include <algorithm>
struct PingPong struct PingPong
@ -513,6 +515,44 @@ struct GraphicsPrivate
swapGLBuffer(); swapGLBuffer();
} }
void writeScreenshot(const char *filename)
{
int bpp;
uint32_t rm, gm, bm, am;
SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ABGR8888, &bpp, &rm, &gm, &bm, &am);
/* Discard alpha channel because it might have bogus values */
SDL_Surface *screenshot =
SDL_CreateRGBSurface(0, scRes.x, scRes.y, bpp, rm, gm, bm, 0);
screen.getPP().bindLastBuffer();
glReadPixels(0, 0, scSize.x, scSize.y, GL_RGBA, GL_UNSIGNED_BYTE, screenshot->pixels);
IMG_SavePNG(screenshot, filename);
SDL_FreeSurface(screenshot);
}
void checkScreenshotRq()
{
if (!threadData->rqScreenshot)
return;
threadData->rqScreenshot = false;
struct timeval tv;
gettimeofday(&tv, 0);
struct tm tm = *localtime(&tv.tv_sec);
char filename[32];
snprintf(filename, sizeof(filename), "%d%02d%02d-%02d%02d%02d.png",
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
writeScreenshot(filename);
}
}; };
Graphics::Graphics(RGSSThreadData *data) Graphics::Graphics(RGSSThreadData *data)
@ -536,6 +576,8 @@ void Graphics::update()
// p->cpuTimer->endTiming(); // p->cpuTimer->endTiming();
// p->gpuTimer->startTiming(); // p->gpuTimer->startTiming();
p->checkScreenshotRq();
if (p->frozen) if (p->frozen)
return; return;