|
From: Yoda-JM <yo...@us...> - 2009-11-28 16:46:52
|
Module: performous
Branch: master
Commit: 34f294fd5556b38499f24e65bdbcb3a7390e6fef
Author: Vincent Le Ligeour <yo...@us...>
Date: Sat Nov 28 17:46:34 2009 +0100
Bump version, Added screenshot by pressing F11 (need tweak)
---
CMakeLists.txt | 2 +-
game/main.cc | 14 ++++++++++++++
game/video_driver.cc | 26 ++++++++++++++++++++++++++
game/video_driver.hh | 2 ++
4 files changed, 43 insertions(+), 1 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6437a8e..a549d2a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
project(Performous CXX)
cmake_minimum_required(VERSION 2.6)
cmake_policy(VERSION 2.6)
-set(PROJECT_VERSION "0.4.0")
+set(PROJECT_VERSION "0.4.0+")
# Avoid source tree pollution
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
diff --git a/game/main.cc b/game/main.cc
index dcfa16a..3d42c90 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -31,6 +31,8 @@
volatile bool g_quit = false;
+bool g_take_screenshot = false;
+
extern "C" void quit(int) {
g_quit = true;
}
@@ -68,6 +70,9 @@ static void checkEvents_SDL(ScreenManager& sm, Window& window) {
config["graphic/fullscreen"].b() = !config["graphic/fullscreen"].b();
continue; // Already handled here...
}
+ if (keypressed == SDLK_F11 ) {
+ g_take_screenshot = true;
+ }
if (keypressed == SDLK_F4 && modifier & KMOD_ALT) {
sm.finished();
continue; // Already handled here...
@@ -156,6 +161,15 @@ void mainLoop(std::string const& songlist) {
boost::xtime time = now();
unsigned frames = 0;
while (!sm.isFinished()) {
+ if( g_take_screenshot ) {
+ try {
+ window.screenshot();
+ std::cout << ">>> Screenshot taken" << std::endl;
+ } catch (std::exception& e) {
+ std::cerr << "ERROR: " << e.what() << std::endl;
+ }
+ g_take_screenshot = false;
+ }
try {
checkEvents_SDL(sm, window);
window.blank();
diff --git a/game/video_driver.cc b/game/video_driver.cc
index 0fb7ddb..ac6a69d 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -5,7 +5,9 @@
#include "fs.hh"
#include "util.hh"
#include "joystick.hh"
+
#include <SDL.h>
+#include <Magick++.h>
namespace {
unsigned s_width;
@@ -54,6 +56,30 @@ bool Window::getFullscreen() {
return m_fullscreen;
}
+void Window::screenshot() {
+ static unsigned int count = 0;
+ unsigned width = m_fullscreen ? m_fsW : m_windowW;
+ unsigned height = m_fullscreen ? m_fsH : m_windowH;
+
+ std::vector<char> buffer(width*height*3);
+ glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, &buffer[0]);
+ Magick::Blob blob( &buffer[0], width*height*3);
+
+ Magick::Image image;
+ char geometry[16];
+ sprintf(geometry,"%dx%d",width,height);
+ image.size(geometry);
+ image.depth(8);
+ image.magick( "RGB" );
+ image.read(blob);
+ image.flip();
+ char filename[256];
+ sprintf(filename,"/tmp/performous_screenshot_%u.png",count);
+ image.write(filename);
+ count++;
+}
+
+
void Window::resize() {
unsigned width = m_fullscreen ? m_fsW : m_windowW;
unsigned height = m_fullscreen ? m_fsH : m_windowH;
diff --git a/game/video_driver.hh b/game/video_driver.hh
index 38ac892..4ac703e 100644
--- a/game/video_driver.hh
+++ b/game/video_driver.hh
@@ -33,6 +33,8 @@ class Window {
void setFullscreen(bool _fs);
/// gets fullscreen state
bool getFullscreen();
+ /// take a screenshot
+ void screenshot();
private:
SDL_Surface* screen;
|