From b4defcab54c336690116466804b00a6d1127dc03 Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Sat, 14 Apr 2018 16:04:16 +0100 Subject: [PATCH] [Add] Screenshot key. --- README | 9 +++++++-- src/main.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README b/README index b57b6c0..5de91c8 100644 --- a/README +++ b/README @@ -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. diff --git a/src/main.cpp b/src/main.cpp index 77873f3..7938e9a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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);