diff options
Diffstat (limited to 'src/render/screenshot.cc')
-rw-r--r-- | src/render/screenshot.cc | 58 |
1 files changed, 58 insertions, 0 deletions
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 <SDL/SDL.h> + 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 |