Improved screenshot functionality:
- Support arbitrary formats (though still hardcoded) - Use PNG as default - Fixed crash: resize texture before filling it git-svn-id: https://svn.code.sf.net/p/extremetuxracer/code/trunk@566 0420edf4-82e4-42fc-9478-35b55e6d67a3master
parent
a39f589d05
commit
e7d7ff4c88
|
@ -46,7 +46,7 @@ void CPaused::Keyb(sf::Keyboard::Key key, bool release, int x, int y) {
|
|||
if (release) return;
|
||||
switch (key) {
|
||||
case sf::Keyboard::S:
|
||||
ScreenshotN();
|
||||
Winsys.TakeScreenshot();
|
||||
break;
|
||||
case sf::Keyboard::F5:
|
||||
sky = !sky;
|
||||
|
|
|
@ -103,7 +103,7 @@ void CRacing::Keyb(sf::Keyboard::Key key, bool release, int x, int y) {
|
|||
if (!release) State::manager.RequestEnterState(Reset);
|
||||
break;
|
||||
case sf::Keyboard::S:
|
||||
if (!release) ScreenshotN();
|
||||
if (!release) Winsys.TakeScreenshot();
|
||||
break;
|
||||
|
||||
// view changing
|
||||
|
|
|
@ -21,7 +21,6 @@ GNU General Public License for more details.
|
|||
|
||||
#include "textures.h"
|
||||
#include "spx.h"
|
||||
#include "course.h"
|
||||
#include "winsys.h"
|
||||
#include "ogl.h"
|
||||
#include "gui.h"
|
||||
|
@ -298,39 +297,3 @@ void CTexture::DrawNumStr(const string& s, int x, int y, float size, const sf::C
|
|||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// screenshot
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// 0 ppm, 1 tga, 2 bmp
|
||||
#define SCREENSHOT_PROC 2
|
||||
|
||||
void ScreenshotN() {
|
||||
sf::Texture tex;
|
||||
tex.update(Winsys.getWindow());
|
||||
sf::Image img = tex.copyToImage();
|
||||
|
||||
string path = param.screenshot_dir;
|
||||
path += SEP;
|
||||
path += g_game.course->dir;
|
||||
path += '_';
|
||||
path += GetTimeString();
|
||||
int type = SCREENSHOT_PROC;
|
||||
|
||||
switch (type) {
|
||||
case 0:
|
||||
path += ".ppm";
|
||||
img.saveToFile(path);
|
||||
break;
|
||||
case 1:
|
||||
path += ".tga";
|
||||
img.saveToFile(path);
|
||||
break;
|
||||
case 2:
|
||||
path += ".bmp";
|
||||
img.saveToFile(path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,5 @@ public:
|
|||
|
||||
extern CTexture Tex;
|
||||
|
||||
void ScreenshotN();
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -148,14 +148,12 @@ void CharKeys(sf::Keyboard::Key key, bool release, int x, int y) {
|
|||
QuitTool();
|
||||
break;
|
||||
case sf::Keyboard::F10:
|
||||
ScreenshotN();
|
||||
case sf::Keyboard::C:
|
||||
Winsys.TakeScreenshot();
|
||||
break;
|
||||
case sf::Keyboard::S:
|
||||
SaveToolCharacter();
|
||||
break;
|
||||
case sf::Keyboard::C:
|
||||
ScreenshotN();
|
||||
break;
|
||||
case sf::Keyboard::M:
|
||||
TestChar.useMaterials = !TestChar.useMaterials;
|
||||
break;
|
||||
|
|
|
@ -165,7 +165,7 @@ void SingleFrameKeys(sf::Keyboard::Key key, bool release, int x, int y) {
|
|||
TestFrame.CopyFrame(curr_frame-1, curr_frame);
|
||||
break;
|
||||
case sf::Keyboard::F10:
|
||||
ScreenshotN();
|
||||
Winsys.TakeScreenshot();
|
||||
break;
|
||||
|
||||
case sf::Keyboard::Num1:
|
||||
|
|
|
@ -20,6 +20,7 @@ GNU General Public License for more details.
|
|||
#endif
|
||||
|
||||
#include "winsys.h"
|
||||
#include "course.h"
|
||||
#include "game_ctrl.h"
|
||||
#include "score.h"
|
||||
#include "ogl.h"
|
||||
|
@ -155,3 +156,19 @@ void CWinsys::PrintJoystickInfo() const {
|
|||
cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void CWinsys::TakeScreenshot() const {
|
||||
sf::Texture tex;
|
||||
tex.create(window.getSize().x, window.getSize().y);
|
||||
tex.update(window);
|
||||
sf::Image img = tex.copyToImage();
|
||||
|
||||
string path = param.screenshot_dir;
|
||||
path += SEP;
|
||||
path += g_game.course->dir;
|
||||
path += '_';
|
||||
path += GetTimeString();
|
||||
|
||||
path += SCREENSHOT_FORMAT;
|
||||
img.saveToFile(path);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
|
||||
#define NUM_RESOLUTIONS 10
|
||||
#define SCREENSHOT_FORMAT ".png"
|
||||
|
||||
extern TVector2i cursor_pos;
|
||||
|
||||
|
@ -66,6 +67,7 @@ public:
|
|||
void endSFML() { if (sfmlRenders) window.popGLStates(); sfmlRenders = false; }
|
||||
bool PollEvent(sf::Event& event) { return window.pollEvent(event); }
|
||||
const sf::Window& getWindow() const { return window; }
|
||||
void TakeScreenshot() const;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue