From 986ca13bdbc90bccf8c3e7c05e5c809dea1551fc Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 28 Jan 2012 15:54:57 +0000 Subject: Added function to write savegame screenshots, moved client notification from the individual image loaders to the screenshot function. --- src/render/jpgfile.cc | 5 ----- src/render/pngfile.cc | 6 ----- src/render/screenshot.cc | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ src/render/screenshot.h | 1 + src/render/tgafile.cc | 7 ------ 5 files changed, 59 insertions(+), 18 deletions(-) (limited to 'src/render') diff --git a/src/render/jpgfile.cc b/src/render/jpgfile.cc index 25093b0..5a0fb7b 100644 --- a/src/render/jpgfile.cc +++ b/src/render/jpgfile.cc @@ -17,7 +17,6 @@ http://www.zarb.org/~gc/html/libpng.html #include "sys/sys.h" #include "filesystem/filesystem.h" #include "render/jpgfile.h" -#include "core/application.h" // work-around for a jpeglib problem, needed on win32 and osx #ifdef HAVE_STDLIB_H @@ -116,10 +115,6 @@ void JPG::save(const char *filename, Image & image, int jpeg_quality) jpeg_destroy_compress(&jpeg_compression_info); //con_print << "Wrote " << filename << std::endl; - std::string message; - message.assign("Wrote "); - message.append(filename); - core::application()->notify_message(core::Message::Info, message); } } diff --git a/src/render/pngfile.cc b/src/render/pngfile.cc index da786ec..70833f3 100644 --- a/src/render/pngfile.cc +++ b/src/render/pngfile.cc @@ -20,7 +20,6 @@ http://www.zarb.org/~gc/html/libpng.html #include "sys/sys.h" #include "filesystem/filesystem.h" #include "render/pngfile.h" -#include "core/application.h" namespace render { @@ -194,11 +193,6 @@ void PNG::save(const char *filename, Image & image) fclose(png_file); png_destroy_write_struct(&png_ptr, &info_ptr); - //con_print << "Wrote " << filename << std::endl; - std::string message; - message.assign("Wrote "); - message.append(filename); - core::application()->notify_message(core::Message::Info, message); } } diff --git a/src/render/screenshot.cc b/src/render/screenshot.cc index 9018a7d..2fd7e9a 100644 --- a/src/render/screenshot.cc +++ b/src/render/screenshot.cc @@ -8,7 +8,10 @@ #include "auxiliary/functions.h" #include "core/core.h" +#include "core/application.h" #include "filesystem/filesystem.h" +#include "render/camera.h" +#include "render/draw.h" #include "render/state.h" #include "render/screenshot.h" #include "render/image.h" @@ -17,6 +20,8 @@ #include "render/tgafile.h" #include "render/gl.h" +#include + namespace render { @@ -27,6 +32,53 @@ core::Cvar *Screenshot::screenshotquality = 0; int Screenshot::current_number = 0; int Screenshot::current_date = 0; +void Screenshot::savegameshot(const std::string & filename) +{ + // TODO do the actual drawing + + // Clear the color and depth buffers. + gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + // set camera transformation + Camera::frame(0.0f); + + render::Camera::frustum(); + + // draw the world + draw(0.0f); + + gl::disable(GL_TEXTURE_2D); + gl::disable(GL_BLEND); + + // swap GL buffers + SDL_GL_SwapBuffers(); + + int w = State::width(); + int h = State::height(); + + // round image size down to a multiplier of 16 + w -= w % 16; + h -= h % 16; + + if ((w > 0) && (h > 0)) { + // read pixels into an image instance + render::Image image(w, h, 3); + + glReadPixels( + (GLsizei) ((State::width() - w) / 2), + (GLsizei) ((State::height() - h) / 2), + w, + h, + GL_RGB, GL_UNSIGNED_BYTE, (void *) image.ptr() + ); + + image.flip_vertical(); + + con_debug << "Saving " << filename << std::endl; + + render::JPG::save(filename.c_str(), image, 85); + } +} void Screenshot::save() { std::string filename; @@ -114,6 +166,12 @@ void Screenshot::save() } else if (filetype == TYPETGA) { render::TGA::save(filename.c_str(), image); } + + // send a notification + std::string message; + message.assign("Wrote "); + message.append(filename); + core::application()->notify_message(core::Message::Info, message); } } // namsepace render diff --git a/src/render/screenshot.h b/src/render/screenshot.h index 5c0e22c..2c6568c 100644 --- a/src/render/screenshot.h +++ b/src/render/screenshot.h @@ -16,6 +16,7 @@ class Screenshot { public: static void save(); + static void savegameshot(const std::string & filename); static core::Cvar *screenshotformat; static core::Cvar *screenshotquality; diff --git a/src/render/tgafile.cc b/src/render/tgafile.cc index efb86e9..15447df 100644 --- a/src/render/tgafile.cc +++ b/src/render/tgafile.cc @@ -34,7 +34,6 @@ #include "sys/sys.h" #include "filesystem/filesystem.h" #include "render/tgafile.h" -#include "core/application.h" const unsigned char TGA_NONE = 0; const unsigned char TGA_TRUECOLOR = 2; @@ -361,12 +360,6 @@ void TGA::save(const char *filename, Image & image) // close file ofs.close(); - - //con_print << "Wrote " << filename << std::endl; - std::string message; - message.assign("Wrote "); - message.append(filename); - core::application()->notify_message(core::Message::Info, message); } } -- cgit v1.2.3