mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-09 09:39:53 +00:00
Added screenshot function
This commit is contained in:
parent
737b29035d
commit
c17015dfb5
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
|
screenshot*.png
|
||||||
*.o
|
*.o
|
||||||
*~
|
*~
|
||||||
data
|
data
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "input/poller.hpp"
|
#include "input/poller.hpp"
|
||||||
#include "boost/bind.hpp"
|
#include "boost/bind.hpp"
|
||||||
#include "game/mwrender/playerpos.hpp"
|
#include "game/mwrender/playerpos.hpp"
|
||||||
|
#include "platform/strings.h"
|
||||||
|
|
||||||
namespace MWInput
|
namespace MWInput
|
||||||
{
|
{
|
||||||
@ -13,6 +14,8 @@ namespace MWInput
|
|||||||
{
|
{
|
||||||
A_Quit, // Exit the program
|
A_Quit, // Exit the program
|
||||||
|
|
||||||
|
A_Screenshot, // Take a screenshot
|
||||||
|
|
||||||
A_MoveLeft, // Move player left / right
|
A_MoveLeft, // Move player left / right
|
||||||
A_MoveRight,
|
A_MoveRight,
|
||||||
A_MoveUp, // Move up / down
|
A_MoveUp, // Move up / down
|
||||||
@ -29,27 +32,45 @@ namespace MWInput
|
|||||||
// Note: the order here is important. The OISManager must be
|
// Note: the order here is important. The OISManager must be
|
||||||
// initialized before poller and listener.
|
// initialized before poller and listener.
|
||||||
Input::Dispatcher disp;
|
Input::Dispatcher disp;
|
||||||
|
Render::OgreRenderer &ogre;
|
||||||
Input::OISManager input;
|
Input::OISManager input;
|
||||||
Input::Poller poller;
|
Input::Poller poller;
|
||||||
Input::InputListener listener;
|
Input::InputListener listener;
|
||||||
MWRender::PlayerPos &player;
|
MWRender::PlayerPos &player;
|
||||||
|
|
||||||
|
// Count screenshots. TODO: We should move this functionality to
|
||||||
|
// OgreRender or somewhere else.
|
||||||
|
int shotCount;
|
||||||
|
|
||||||
|
// Write screenshot to file.
|
||||||
|
void screenshot()
|
||||||
|
{
|
||||||
|
// TODO: add persistent counting so we don't overwrite shots
|
||||||
|
// from previous runs.
|
||||||
|
char buf[50];
|
||||||
|
snprintf(buf,50, "screenshot%d.png", shotCount++);
|
||||||
|
ogre.screenshot(buf);
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MWInputManager(Render::OgreRenderer &ogre,
|
MWInputManager(Render::OgreRenderer &_ogre,
|
||||||
MWRender::PlayerPos &_player)
|
MWRender::PlayerPos &_player)
|
||||||
: disp(A_LAST),
|
: disp(A_LAST),
|
||||||
input(ogre),
|
ogre(_ogre),
|
||||||
|
input(_ogre),
|
||||||
poller(input),
|
poller(input),
|
||||||
listener(ogre, input, disp),
|
listener(_ogre, input, disp),
|
||||||
player(_player)
|
player(_player),
|
||||||
|
shotCount(0)
|
||||||
{
|
{
|
||||||
using namespace Input;
|
using namespace Input;
|
||||||
using namespace OIS;
|
using namespace OIS;
|
||||||
|
|
||||||
// Bind MW-specific functions
|
// Bind MW-specific functions
|
||||||
disp.funcs.bind(A_Quit,
|
disp.funcs.bind(A_Quit, boost::bind(&InputListener::exitNow, &listener),
|
||||||
boost::bind(&InputListener::exitNow, &listener),
|
|
||||||
"Quit program");
|
"Quit program");
|
||||||
|
disp.funcs.bind(A_Screenshot, boost::bind(&MWInputManager::screenshot, this),
|
||||||
|
"Screenshot");
|
||||||
|
|
||||||
// Add ourselves as a frame listener, to catch movement keys
|
// Add ourselves as a frame listener, to catch movement keys
|
||||||
ogre.getRoot()->addFrameListener(this);
|
ogre.getRoot()->addFrameListener(this);
|
||||||
@ -60,6 +81,7 @@ namespace MWInput
|
|||||||
// Key bindings
|
// Key bindings
|
||||||
disp.bind(KC_Q, A_Quit);
|
disp.bind(KC_Q, A_Quit);
|
||||||
disp.bind(KC_ESCAPE, A_Quit);
|
disp.bind(KC_ESCAPE, A_Quit);
|
||||||
|
disp.bind(KC_SYSRQ, A_Screenshot);
|
||||||
|
|
||||||
// Key bindings for polled keys
|
// Key bindings for polled keys
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "nif/node.hpp"
|
#include "nif/node.hpp"
|
||||||
#include "nif/data.hpp"
|
#include "nif/data.hpp"
|
||||||
#include "nif/property.hpp"
|
#include "nif/property.hpp"
|
||||||
|
#include "platform/strings.h"
|
||||||
|
|
||||||
// For warning messages
|
// For warning messages
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -252,10 +253,6 @@ static void createMaterial(const String &name,
|
|||||||
// make sure that all materials are given unique names.
|
// make sure that all materials are given unique names.
|
||||||
static String getUniqueName(const String &input)
|
static String getUniqueName(const String &input)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
|
||||||
#define snprintf _snprintf
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int addon = 0;
|
static int addon = 0;
|
||||||
static char buf[8];
|
static char buf[8];
|
||||||
snprintf(buf, 8, "_%d", addon++);
|
snprintf(buf, 8, "_%d", addon++);
|
||||||
|
@ -15,6 +15,11 @@ void OgreRenderer::cleanup()
|
|||||||
mRoot = NULL;
|
mRoot = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OgreRenderer::screenshot(const std::string &file)
|
||||||
|
{
|
||||||
|
mWindow->writeContentsToFile(file);
|
||||||
|
}
|
||||||
|
|
||||||
bool OgreRenderer::configure(bool showConfig,
|
bool OgreRenderer::configure(bool showConfig,
|
||||||
const std::string &pluginCfg,
|
const std::string &pluginCfg,
|
||||||
bool _logging)
|
bool _logging)
|
||||||
|
@ -42,6 +42,9 @@ namespace Render
|
|||||||
/// Start the main rendering loop
|
/// Start the main rendering loop
|
||||||
void start() { mRoot->startRendering(); }
|
void start() { mRoot->startRendering(); }
|
||||||
|
|
||||||
|
/// Write a screenshot to file
|
||||||
|
void screenshot(const std::string &file);
|
||||||
|
|
||||||
/// Get the Root
|
/// Get the Root
|
||||||
Ogre::Root *getRoot() { return mRoot; }
|
Ogre::Root *getRoot() { return mRoot; }
|
||||||
|
|
||||||
|
@ -92,14 +92,6 @@ public:
|
|||||||
MorroFrameListener mFrameListener;
|
MorroFrameListener mFrameListener;
|
||||||
InputListener mInput;
|
InputListener mInput;
|
||||||
|
|
||||||
// Functions called from D during event handling
|
|
||||||
|
|
||||||
// Dump screen contents to file
|
|
||||||
extern "C" void ogre_screenshot(char* filename)
|
|
||||||
{
|
|
||||||
mWindow->writeContentsToFile(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current camera orientation, in the form of 'front' and 'up'
|
// Get current camera orientation, in the form of 'front' and 'up'
|
||||||
// vectors.
|
// vectors.
|
||||||
extern "C" void ogre_getCameraOrientation(float *fx, float *fy, float *fz,
|
extern "C" void ogre_getCameraOrientation(float *fx, float *fy, float *fz,
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
#ifndef _STRINGS_WRAPPER_H
|
#ifndef _STRINGS_WRAPPER_H
|
||||||
#define _STRINGS_WRAPPER_H
|
#define _STRINGS_WRAPPER_H
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
#pragma warning(disable: 4996)
|
#pragma warning(disable: 4996)
|
||||||
|
|
||||||
#define strcasecmp stricmp
|
#define strcasecmp stricmp
|
||||||
|
#define snprintf _snprintf
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user