From 8a8086d758d7618f3900df057ac840667e867d0c Mon Sep 17 00:00:00 2001 From: Björn Steinbrink Date: Sun, 18 Sep 2005 00:45:38 +0000 Subject: Changed Graphics::saveScreenshot to Graphics::getScreenshot. Now using the ImageWriter to save that screenshot. --- src/openglgraphics.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'src/openglgraphics.cpp') 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 #include #include @@ -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; -- cgit v1.2.3-60-g2f50