[Orxonox-commit 2326] r7041 - code/branches/presentation3/src/modules/designtools
rgrieder at orxonox.net
rgrieder at orxonox.net
Mon May 31 13:30:58 CEST 2010
Author: rgrieder
Date: 2010-05-31 13:30:58 +0200 (Mon, 31 May 2010)
New Revision: 7041
Modified:
code/branches/presentation3/src/modules/designtools/ScreenshotManager.cc
code/branches/presentation3/src/modules/designtools/ScreenshotManager.h
Log:
ScreenshotManager working now, though there might be a memory leak in the destructor.
The command is "printScreenHD".
Modified: code/branches/presentation3/src/modules/designtools/ScreenshotManager.cc
===================================================================
--- code/branches/presentation3/src/modules/designtools/ScreenshotManager.cc 2010-05-31 10:06:55 UTC (rev 7040)
+++ code/branches/presentation3/src/modules/designtools/ScreenshotManager.cc 2010-05-31 11:30:58 UTC (rev 7041)
@@ -1,7 +1,7 @@
/* COPYRIGHT: this code comes from http://www.ogre3d.org/wiki/index.php/High_resolution_screenshots */
-//#include <stdafx.h>
#include "ScreenshotManager.h"
+
#include <OgreRenderWindow.h>
#include <OgreViewport.h>
#include <OgreRenderTexture.h>
@@ -9,20 +9,31 @@
#include <OgreRoot.h>
#include "core/GraphicsManager.h"
+#include "core/PathConfig.h"
+#include "core/ScopedSingletonManager.h"
+#include "core/ConsoleCommand.h"
-//using namespace Ogre;
+#include "CameraManager.h"
+#include "graphics/Camera.h"
namespace orxonox
{
+ ManageScopedSingleton(ScreenshotManager, ScopeID::Graphics, false);
+ SetConsoleCommandAlias(ScreenshotManager, makeScreenshot_s, "printScreenHD", true);
- ScreenshotManager::ScreenshotManager(Ogre::RenderWindow* pRenderWindow, int gridSize, std::string fileExtension, bool overlayFlag)
+ ScreenshotManager::ScreenshotManager()
{
+ Ogre::RenderWindow* pRenderWindow = GraphicsManager::getInstance().getRenderWindow();
+ int gridSize = 3;
+ std::string fileExtension = ".png";
+ bool overlayFlag = true;
+
//set file extension for the Screenshot files
- mFileExtension = fileExtension;
+ mFileExtension = fileExtension;
// the gridsize
- mGridSize = gridSize;
+ mGridSize = gridSize;
// flag for overlay rendering
- mDisableOverlays = overlayFlag;
+ mDisableOverlays = overlayFlag;
//get current window size
mWindowWidth = pRenderWindow->getWidth();
mWindowHeight = pRenderWindow->getHeight();
@@ -46,7 +57,8 @@
ScreenshotManager::~ScreenshotManager()
{
- delete[] data_;
+ // Don't delete data_. Somehow this pointer points anywhere but to memory location.
+ //delete[] data_;
}
@@ -54,8 +66,10 @@
* @param camera Pointer to the camera "looking at" the scene of interest
* @param fileName the filename of the screenshot file.
*/
- void ScreenshotManager::makeScreenshot(Ogre::Camera* camera, std::string fileName) const
+ void ScreenshotManager::makeScreenshot() const
{
+ Ogre::Camera* camera = CameraManager::getInstance().getActiveCamera()->getOgreCamera();
+ std::string fileName = PathConfig::getInstance().getLogPathString() + "screenshot_" + this->getTimestamp();
//Remove all viewports, so the added Viewport(camera) ist the only
mRT->removeAllViewports();
@@ -142,4 +156,19 @@
Ogre::Root::getSingletonPtr()->clearEventTimes();
}
+ std::string ScreenshotManager::getTimestamp()
+ {
+ struct tm *pTime;
+ time_t ctTime; time(&ctTime);
+ pTime = localtime( &ctTime );
+ std::ostringstream oss;
+ oss << std::setw(2) << std::setfill('0') << (pTime->tm_mon + 1)
+ << std::setw(2) << std::setfill('0') << pTime->tm_mday
+ << std::setw(2) << std::setfill('0') << (pTime->tm_year + 1900)
+ << "_" << std::setw(2) << std::setfill('0') << pTime->tm_hour
+ << std::setw(2) << std::setfill('0') << pTime->tm_min
+ << std::setw(2) << std::setfill('0') << pTime->tm_sec;
+ return oss.str();
+ }
+
}
Modified: code/branches/presentation3/src/modules/designtools/ScreenshotManager.h
===================================================================
--- code/branches/presentation3/src/modules/designtools/ScreenshotManager.h 2010-05-31 10:06:55 UTC (rev 7040)
+++ code/branches/presentation3/src/modules/designtools/ScreenshotManager.h 2010-05-31 11:30:58 UTC (rev 7041)
@@ -3,14 +3,19 @@
#ifndef __ScreenshotManager_h__
#define __ScreenshotManager_h__
+#include "DesignToolsPrereqs.h"
+
#include <string>
+#include <cstring>
+#include <cstdlib>
+
#include <OgrePrerequisites.h>
#include <OgreTexture.h>
#include <OgreHardwarePixelBuffer.h>
-#include "OrxonoxConfig.h"
-#include <cstring>
-#include <cstdlib>
+#include "util/Singleton.h"
+#include "core/OrxonoxClass.h"
+
namespace orxonox
{
@@ -26,19 +31,26 @@
* fileExtension: The extension of the screenshot file name, hence the type of graphics file to generate.
* To generate "MyScreenshot.png" this parameter would contain ".png".
*/
- class ScreenshotManager
+ class ScreenshotManager : public OrxonoxClass, public Singleton<ScreenshotManager>
{
+ friend class Singleton<ScreenshotManager>;
+
public:
- ScreenshotManager(Ogre::RenderWindow* pRenderWindow, int gridSize, std::string fileExtension, bool overlayFlag);
+ ScreenshotManager();
~ScreenshotManager();
/* Creates a screenshot with the given camera.
* @param camera Pointer to the camera "looking at" the scene of interest
* @param fileName the filename of the screenshot file.
*/
- void makeScreenshot(Ogre::Camera* camera, Ogre::String fileName) const;
+ void makeScreenshot() const;
+
+ static void makeScreenshot_s()
+ { getInstance().makeScreenshot(); }
protected:
+ static std::string ScreenshotManager::getTimestamp();
+
std::string mFileExtension;
unsigned int mGridSize, mWindowWidth, mWindowHeight;
bool mDisableOverlays;
@@ -49,6 +61,8 @@
//PixelBox for a large Screenshot, if grid size is > 1
Ogre::PixelBox mFinalPicturePB;
uint8_t* data_;
+
+ static ScreenshotManager* singletonPtr_s;
};
}
More information about the Orxonox-commit
mailing list