diff options
author | Alejandro Marzini | 2010-07-26 06:52:58 +0000 |
---|---|---|
committer | Alejandro Marzini | 2010-07-26 06:52:58 +0000 |
commit | 738a9e78d8e0c2fc096006fd38d66ac743cb7a3d (patch) | |
tree | ef89c085092088a29aaae9201d43f69fab10178c /backends | |
parent | 856c6a18afbc7f4611898731db5e1235a6572ff4 (diff) | |
download | scummvm-rg350-738a9e78d8e0c2fc096006fd38d66ac743cb7a3d.tar.gz scummvm-rg350-738a9e78d8e0c2fc096006fd38d66ac743cb7a3d.tar.bz2 scummvm-rg350-738a9e78d8e0c2fc096006fd38d66ac743cb7a3d.zip |
OPENGL: Implement saveScreenshot().
svn-id: r51299
Diffstat (limited to 'backends')
-rw-r--r-- | backends/graphics/opengl/opengl-graphics.cpp | 45 | ||||
-rw-r--r-- | backends/graphics/opengl/opengl-graphics.h | 2 | ||||
-rw-r--r-- | backends/graphics/openglsdl/openglsdl-graphics.cpp | 2 |
3 files changed, 47 insertions, 2 deletions
diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 7f1f3f3cec..23de9db59e 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -27,6 +27,7 @@ #include "backends/graphics/opengl/opengl-graphics.h" #include "backends/graphics/opengl/glerrorcheck.h" +#include "common/file.h" #include "common/mutex.h" #include "common/translation.h" #include "graphics/font.h" @@ -44,7 +45,8 @@ OpenGLGraphicsManager::OpenGLGraphicsManager() _transactionMode(kTransactionNone), _cursorNeedsRedraw(false), _cursorPaletteDisabled(true), _cursorVisible(false), _cursorKeyColor(0), - _cursorTargetScale(1) { + _cursorTargetScale(1), + _formatBGR(false) { memset(&_oldVideoMode, 0, sizeof(_oldVideoMode)); memset(&_videoMode, 0, sizeof(_videoMode)); @@ -1104,7 +1106,46 @@ bool OpenGLGraphicsManager::notifyEvent(const Common::Event &event) { } bool OpenGLGraphicsManager::saveScreenshot(const char *filename) { - return false; + int width = _videoMode.hardwareWidth; + int height = _videoMode.hardwareHeight; + + // Allocate space for screenshot + uint8 *pixels = new uint8[width * height * 3]; + + // Get pixel data from opengl buffer + if (_formatBGR) + glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, pixels); + else + glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); + + // Open file + Common::DumpFile out; + out.open(filename); + + // Write BMP header + out.writeByte('B'); + out.writeByte('M'); + out.writeUint32LE(height * width * 3 + 52); + out.writeUint32LE(0); + out.writeUint32LE(52); + out.writeUint32LE(40); + out.writeUint32LE(width); + out.writeUint32LE(height); + out.writeUint16LE(1); + out.writeUint16LE(24); + out.writeUint32LE(0); + out.writeUint32LE(0); + out.writeUint32LE(0); + out.writeUint32LE(0); + out.writeUint32LE(0); + out.writeUint32LE(0); + + // Write pixel data to BMP + out.write(pixels, width * height * 3); + + delete[] pixels; + + return true; } #endif diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 7d91b84b34..2db232967b 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -164,6 +164,8 @@ protected: virtual void setScale(int newScale); virtual void setAspectRatioCorrection(int mode); + bool _formatBGR; + // // Game screen // diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index e97e1f2b4f..238a8f5c21 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -207,6 +207,8 @@ bool OpenGLSdlGraphicsManager::loadGFXMode() { } } + _formatBGR = _hwscreen->format->Rshift != 0; + return OpenGLGraphicsManager::loadGFXMode(); } |