summaryrefslogtreecommitdiff
path: root/src/openglgraphics.cpp
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2005-09-18 00:45:38 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2005-09-18 00:45:38 +0000
commit8a8086d758d7618f3900df057ac840667e867d0c (patch)
treef1953a29a2b17e32fd18ab9be581c9ee2a8dbd8d /src/openglgraphics.cpp
parent76892afa102fd814b3821c246547f28feb3d7394 (diff)
downloadmana-client-8a8086d758d7618f3900df057ac840667e867d0c.tar.gz
mana-client-8a8086d758d7618f3900df057ac840667e867d0c.tar.bz2
mana-client-8a8086d758d7618f3900df057ac840667e867d0c.tar.xz
mana-client-8a8086d758d7618f3900df057ac840667e867d0c.zip
Changed Graphics::saveScreenshot to Graphics::getScreenshot. Now using the ImageWriter to save that screenshot.
Diffstat (limited to 'src/openglgraphics.cpp')
-rw-r--r--src/openglgraphics.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index 86bb734a..b9591591 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -25,6 +25,7 @@
#include "openglgraphics.h"
+#include <iostream>
#include <SDL.h>
#include <guichan/image.hpp>
@@ -134,6 +135,60 @@ void OpenGLGraphics::_endDraw()
{
}
+SDL_Surface* OpenGLGraphics::getScreenshot()
+{
+ // TODO I expect this to be unneeded for OpenGL, someone with a PPC or
+ // sth. else that is big endian should check this.
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ int rmask = 0xff000000;
+ int gmask = 0x00ff0000;
+ int bmask = 0x0000ff00;
+#else
+ int rmask = 0x000000ff;
+ int gmask = 0x0000ff00;
+ int bmask = 0x00ff0000;
+#endif
+ int amask = 0x00000000;
+
+ SDL_Surface *screenshot = SDL_CreateRGBSurface(SDL_SWSURFACE, mScreen->w,
+ mScreen->h, 24, rmask, gmask, bmask, amask);
+
+ if (SDL_MUSTLOCK(screenshot)) {
+ SDL_LockSurface(screenshot);
+ }
+ glPixelStorei(GL_PACK_ALIGNMENT, 1);
+ glReadPixels(0, 0, mScreen->w, mScreen->h, GL_RGB, GL_UNSIGNED_BYTE, screenshot->pixels);
+
+ unsigned char *data = (unsigned char*)screenshot->pixels;
+ for (int x = 0; x < mScreen->w; x++) {
+ for (int y=0; y < mScreen->h / 2; y++) {
+ int i1 = (y * mScreen->w + x) * 3;
+ int i2 = ((mScreen->h - y - 1) * mScreen->w + x) * 3;
+
+ unsigned char temp = data[i1];
+ data[i1] = data[i2];
+ data[i2] = temp;
+
+ i1++; i2++;
+ temp = data[i1];
+ data[i1] = data[i2];
+ data[i2] = temp;
+
+ i1++; i2++;
+ temp = data[i1];
+ data[i1] = data[i2];
+ data[i2] = temp;
+
+ }
+ }
+
+ if (SDL_MUSTLOCK(screenshot)) {
+ SDL_UnlockSurface(screenshot);
+ }
+
+ return screenshot;
+}
+
bool OpenGLGraphics::pushClipArea(gcn::Rectangle area)
{
int transX = 0;