From 37bfbfbd234cce09b67c1d53e1ef7d91a46e53cc Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 23 Aug 2008 13:47:16 +0000 Subject: png screenshots --- src/client/video.cc | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'src/client/video.cc') diff --git a/src/client/video.cc b/src/client/video.cc index 2c1fe6b..aed25ae 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -7,11 +7,13 @@ #include #include +#include "auxiliary/functions.h" #include "client/video.h" #include "client/view.h" #include "render/camera.h" #include "render/render.h" #include "render/tga.h" +#include "render/pngfile.h" #include "core/core.h" #include "filesystem/filesystem.h" #include "sys/sys.h" @@ -30,6 +32,8 @@ int height = 0; int width_prev = 0; int height_prev = 0; +int screenshot_number = 0; + const int width_default = 1024; const int height_default = 768; @@ -39,6 +43,8 @@ core::Cvar *r_width; core::Cvar *r_height; core::Cvar *r_fullscreen; +core::Cvar *screenshotformat; + void reset() { // setup our viewport. @@ -65,6 +71,9 @@ bool init() r_fullscreen = core::Cvar::get("r_fullscreen", "0", core::Cvar::Archive); r_fullscreen->set_info("[bool] enable or disable fullscreen video"); + screenshotformat = core::Cvar::get("screenshotformat", "tga", core::Cvar::Archive); + screenshotformat->set_info("[string] screenshot format: tga png"); + int bpp = 0; int flags = 0; @@ -183,27 +192,39 @@ void shutdown() void screenshot() { - int number = 0; bool available = false; std::string shortname; std::string filename; + const int TYPETGA = 0; + const int TYPEPNG = 1; + int filetype = TYPETGA; // make sure the screenshots folder exists filename.assign(filesystem::writedir()); filename.append("screenshots/"); sys::mkdir(filename); + aux::lowercase(screenshotformat->str()); + + if (screenshotformat->str().compare("png") == 0) { + filetype = TYPEPNG; + } else { + filetype = TYPETGA; + (*screenshotformat) = "tga"; + } + // find the first available screenshotxxx.tga do { std::stringstream nstr; - nstr << number; + nstr << screenshot_number; shortname.assign(nstr.str()); while(shortname.size() < 3) shortname.insert(0, 1, '0'); shortname.insert(0, "screenshots/osirion"); - shortname.append(".tga"); + shortname.append("."); + shortname.append(screenshotformat->str()); filename.assign(filesystem::writedir()); filename.append(shortname); @@ -211,10 +232,10 @@ void screenshot() FILE *handle = fopen(filename.c_str(), "r"); if (handle) { fclose(handle); - number++; } else { - available = true; + available = true; } + screenshot_number++; } while (!available); render::Image image((unsigned int)video::width, (unsigned int)video::height, 3); @@ -222,7 +243,13 @@ void screenshot() glReadPixels(0, 0, (GLsizei) video::width, (GLsizei) video::height, GL_RGB, GL_UNSIGNED_BYTE, (void *) image.data()); - render::TGA::save(filename.c_str(), image); + image.flip(); + + if (filetype == TYPEPNG) { + render::PNG::save(filename.c_str(), image); + } else if (filetype == TYPETGA) { + render::TGA::save(filename.c_str(), image); + } } -- cgit v1.2.3