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/screenshot.cc | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src/render/screenshot.cc') 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 -- cgit v1.2.3