[Scummvm-cvs-logs] SF.net SVN: scummvm:[51299] scummvm/branches/gsoc2010-opengl/backends/ graphics/opengl

vgvgf at users.sourceforge.net vgvgf at users.sourceforge.net
Mon Jul 26 08:52:59 CEST 2010


Revision: 51299
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51299&view=rev
Author:   vgvgf
Date:     2010-07-26 06:52:58 +0000 (Mon, 26 Jul 2010)

Log Message:
-----------
OPENGL: Implement saveScreenshot().

Modified Paths:
--------------
    scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp
    scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h
    scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp	2010-07-26 06:30:15 UTC (rev 51298)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp	2010-07-26 06:52:58 UTC (rev 51299)
@@ -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 @@
 	_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::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

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h	2010-07-26 06:30:15 UTC (rev 51298)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h	2010-07-26 06:52:58 UTC (rev 51299)
@@ -164,6 +164,8 @@
 	virtual void setScale(int newScale);
 	virtual void setAspectRatioCorrection(int mode);
 
+	bool _formatBGR;
+
 	//
 	// Game screen
 	//

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp	2010-07-26 06:30:15 UTC (rev 51298)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp	2010-07-26 06:52:58 UTC (rev 51299)
@@ -207,6 +207,8 @@
 		}
 	}
 
+	_formatBGR = _hwscreen->format->Rshift != 0;
+
 	return OpenGLGraphicsManager::loadGFXMode();
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list