[Add] Screenshot key.

This commit is contained in:
Rtch90 2018-04-14 16:04:16 +01:00
parent 25d0b29aea
commit 862cd92a7f
2 changed files with 32 additions and 2 deletions

9
README
View File

@ -49,7 +49,12 @@ External View:
Special:
~~~~~~~~
ctrl-q - quit.
i - show some ugly debug info.
ctrl-q - quit.
i - show some ugly debug info.
ctrl-prntscrn - Screenshot.
F11 - Fullscreen.
F12 - Add a ship.
shift-F12 - Add a station.
F9 - Quicksave.

View File

@ -93,6 +93,7 @@ void L3D::Init(IniConfig& config) {
}
}
SDL_WM_SetCaption("Lephisto", "Lephisto"); /* It's about time we name our application window.. */
L3D::scrWidth = width;
L3D::scrHeight = height;
L3D::scrAspect = width / (float)height;
@ -154,6 +155,23 @@ void L3D::SetView(View* v) {
currentView->ShowAll();
}
void Screendump(char* destFile) {
const int W = L3D::GetScrHeight();
const int H = L3D::GetScrWidth();
char pixel_data[3*W*H];
short TGAhead[] = { 0, 2, 0, 0, 0, 0, W, H, 24 };
FILE* out = fopen(destFile, "w");
if(!out) goto error;
glReadBuffer(GL_FRONT);
glReadPixels(0, 0, W, H, GL_BGR, GL_UNSIGNED_BYTE, pixel_data);
if(fwrite(&TGAhead, sizeof(TGAhead), 3, out) != 3) goto error;
if(fwrite(pixel_data, 3*W*H, 1, out) != 1) goto error;
fclose(out);
return;
error:
printf("Failed to write screendump.\n");;
}
void L3D::HandleEvents(void) {
SDL_Event event;
@ -164,6 +182,13 @@ void L3D::HandleEvents(void) {
case SDL_KEYDOWN:
if(KeyState(SDLK_LCTRL) && (event.key.keysym.sym == SDLK_q)) L3D::Quit();
if(event.key.keysym.sym == SDLK_i) L3D::showDebugInfo = !L3D::showDebugInfo;
if((event.key.keysym.sym == SDLK_PRINT) && KeyState(SDLK_LCTRL)) {
char buf[256];
const time_t t = time(0);
struct tm* _tm = localtime(&t);
strftime(buf, sizeof(buf), "screenshot-%Y%m%d-%h%M%S.tga", _tm);
Screendump(buf);
}
#ifdef DEBUG
if(event.key.keysym.sym == SDLK_F12) {
matrix4x4d m; L3D::player->GetRotMatrix(m);