Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-01-28 15:54:57 +0000
committerStijn Buys <ingar@osirion.org>2012-01-28 15:54:57 +0000
commit986ca13bdbc90bccf8c3e7c05e5c809dea1551fc (patch)
treeaa91eb5678fd8b63d50cb23c904e4ada3f24a888 /src/render/screenshot.cc
parent47c565443b9a09344f58a0639d0de5693fbaec31 (diff)
Added function to write savegame screenshots,
moved client notification from the individual image loaders to the screenshot function.
Diffstat (limited to 'src/render/screenshot.cc')
-rw-r--r--src/render/screenshot.cc58
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