From 84f54db12e3c99e13ec006d266131e63599d6c62 Mon Sep 17 00:00:00 2001 From: VB Date: Fri, 3 Mar 2017 22:29:37 +0100 Subject: [PATCH] screenshoty --- CMakeLists.txt | 7 ++++++- EU07.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 016bc89c..bd25b5ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ set(SOURCES "skydome.cpp" "Sound.cpp" "Spring.cpp" +"shader.cpp" ) if (WIN32) @@ -99,4 +100,8 @@ target_link_libraries(${PROJECT_NAME} ${GLUT_LIBRARIES}) find_package(PythonLibs 2 REQUIRED) include_directories(${PYTHON_INCLUDE_DIRS}) -target_link_libraries(${PROJECT_NAME} ${PYTHON_LIBRARIES}) \ No newline at end of file +target_link_libraries(${PROJECT_NAME} ${PYTHON_LIBRARIES}) + +find_package(PNG REQUIRED) +include_directories(${PNG_INCLUDE_DIRS}) +target_link_libraries(${PROJECT_NAME} ${PNG_LIBRARIES}) \ No newline at end of file diff --git a/EU07.cpp b/EU07.cpp index aca1353e..ff930ebb 100644 --- a/EU07.cpp +++ b/EU07.cpp @@ -18,6 +18,8 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others */ #include "stdafx.h" +#include +#include #include "Globals.h" #include "Logs.h" @@ -34,6 +36,45 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others TWorld World; +void screenshot_save_thread(char *img) +{ + png_image png; + memset(&png, 0, sizeof(png_image)); + png.version = PNG_IMAGE_VERSION; + png.width = Global::ScreenWidth; + png.height = Global::ScreenHeight; + png.format = PNG_FORMAT_RGB; + + char datetime[64]; + time_t timer; + struct tm* tm_info; + time(&timer); + tm_info = localtime(&timer); + strftime(datetime, 64, "%Y-%m-%d_%H-%M-%S", tm_info); + + uint64_t perf; + QueryPerformanceCounter((LARGE_INTEGER*)&perf); + + std::string filename = "screenshots/" + std::string(datetime) + + "_" + std::to_string(perf) + ".png"; + + if (png_image_write_to_file(&png, filename.c_str(), 0, img, -Global::ScreenWidth * 3, nullptr) == 1) + WriteLog("saved " + filename + "."); + else + WriteLog("failed to save screenshot."); + + delete[] img; +} + +void make_screenshot() +{ + char *img = new char[Global::ScreenWidth * Global::ScreenHeight * 3]; + glReadPixels(0, 0, Global::ScreenWidth, Global::ScreenHeight, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)img); + + std::thread t(screenshot_save_thread, img); + t.detach(); +} + void window_resize_callback(GLFWwindow *window, int w, int h) { Global::ScreenWidth = w; @@ -68,6 +109,9 @@ void key_callback( GLFWwindow *window, int key, int scancode, int action, int mo switch( key ) { + case GLFW_KEY_F11: + make_screenshot(); + break; case GLFW_KEY_ESCAPE: { //[Esc] pauzuje tylko bez Debugmode if( DebugModeFlag )