Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 31, 2010, 1:30:58 PM (14 years ago)
Author:
rgrieder
Message:

ScreenshotManager working now, though there might be a memory leak in the destructor.
The command is "printScreenHD".

Location:
code/branches/presentation3/src/modules/designtools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/src/modules/designtools/ScreenshotManager.cc

    r7039 r7041  
    11/* COPYRIGHT: this code comes from http://www.ogre3d.org/wiki/index.php/High_resolution_screenshots */
    22
    3 //#include <stdafx.h>
    43#include "ScreenshotManager.h"
     4
    55#include <OgreRenderWindow.h>
    66#include <OgreViewport.h>
     
    1010
    1111#include "core/GraphicsManager.h"
     12#include "core/PathConfig.h"
     13#include "core/ScopedSingletonManager.h"
     14#include "core/ConsoleCommand.h"
    1215
    13 //using namespace Ogre;
     16#include "CameraManager.h"
     17#include "graphics/Camera.h"
    1418
    1519namespace orxonox
    1620{
     21    ManageScopedSingleton(ScreenshotManager, ScopeID::Graphics, false);
     22    SetConsoleCommandAlias(ScreenshotManager, makeScreenshot_s, "printScreenHD", true);
    1723
    18     ScreenshotManager::ScreenshotManager(Ogre::RenderWindow* pRenderWindow, int gridSize, std::string fileExtension, bool overlayFlag)
     24    ScreenshotManager::ScreenshotManager()
    1925    {
     26        Ogre::RenderWindow* pRenderWindow = GraphicsManager::getInstance().getRenderWindow();
     27        int gridSize = 3;
     28        std::string fileExtension = ".png";
     29        bool overlayFlag = true;
     30
    2031        //set file extension for the Screenshot files
    21         mFileExtension = fileExtension;
     32        mFileExtension   = fileExtension;
    2233        // the gridsize
    23         mGridSize         = gridSize;
     34        mGridSize        = gridSize;
    2435        // flag for overlay rendering
    25         mDisableOverlays  = overlayFlag;
     36        mDisableOverlays = overlayFlag;
    2637        //get current window size
    2738        mWindowWidth   = pRenderWindow->getWidth();
     
    4758    ScreenshotManager::~ScreenshotManager()
    4859    {
    49       delete[] data_;
     60        // Don't delete data_. Somehow this pointer points anywhere but to memory location.
     61        //delete[] data_;
    5062    }
    5163
     
    5567    * @param fileName the filename of the screenshot file.
    5668    */
    57     void ScreenshotManager::makeScreenshot(Ogre::Camera* camera, std::string fileName) const
     69    void ScreenshotManager::makeScreenshot() const
    5870    {
     71        Ogre::Camera* camera = CameraManager::getInstance().getActiveCamera()->getOgreCamera();
     72        std::string fileName = PathConfig::getInstance().getLogPathString() + "screenshot_" + this->getTimestamp();
    5973
    6074        //Remove all viewports, so the added Viewport(camera) ist the only
     
    143157    }
    144158
     159    std::string ScreenshotManager::getTimestamp()
     160    {
     161        struct tm *pTime;
     162        time_t ctTime; time(&ctTime);
     163        pTime = localtime( &ctTime );
     164        std::ostringstream oss;
     165        oss     << std::setw(2) << std::setfill('0') << (pTime->tm_mon + 1)
     166            << std::setw(2) << std::setfill('0') << pTime->tm_mday
     167            << std::setw(2) << std::setfill('0') << (pTime->tm_year + 1900)
     168            << "_" << std::setw(2) << std::setfill('0') << pTime->tm_hour
     169            << std::setw(2) << std::setfill('0') << pTime->tm_min
     170            << std::setw(2) << std::setfill('0') << pTime->tm_sec;
     171        return oss.str();
     172    }
     173
    145174}
  • code/branches/presentation3/src/modules/designtools/ScreenshotManager.h

    r7039 r7041  
    44#define __ScreenshotManager_h__
    55
     6#include "DesignToolsPrereqs.h"
     7
    68#include <string>
     9#include <cstring>
     10#include <cstdlib>
     11
    712#include <OgrePrerequisites.h>
    813#include <OgreTexture.h>
    914#include <OgreHardwarePixelBuffer.h>
    10 #include "OrxonoxConfig.h"
    11 #include <cstring>
    12 #include <cstdlib>
     15
     16#include "util/Singleton.h"
     17#include "core/OrxonoxClass.h"
    1318
    1419namespace orxonox
     
    2732    *              To generate "MyScreenshot.png" this parameter would contain ".png".
    2833    */
    29     class ScreenshotManager
     34    class ScreenshotManager : public OrxonoxClass, public Singleton<ScreenshotManager>
    3035    {
     36        friend class Singleton<ScreenshotManager>;
     37
    3138    public:
    32         ScreenshotManager(Ogre::RenderWindow* pRenderWindow, int gridSize, std::string fileExtension, bool overlayFlag);
     39        ScreenshotManager();
    3340        ~ScreenshotManager();
    3441
     
    3744        * @param fileName the filename of the screenshot file.
    3845      */
    39         void makeScreenshot(Ogre::Camera* camera, Ogre::String fileName) const;
     46        void makeScreenshot() const;
     47
     48        static void makeScreenshot_s()
     49            { getInstance().makeScreenshot(); }
    4050     
    4151    protected:
     52        static std::string ScreenshotManager::getTimestamp();
     53
    4254        std::string    mFileExtension;
    4355        unsigned int   mGridSize, mWindowWidth, mWindowHeight;
     
    5062        Ogre::PixelBox  mFinalPicturePB;
    5163        uint8_t* data_;
     64
     65        static ScreenshotManager* singletonPtr_s;
    5266    };
    5367
Note: See TracChangeset for help on using the changeset viewer.