[Orxonox-commit 2300] r7015 - code/branches/presentation3/src/modules/designtools
scheusso at orxonox.net
scheusso at orxonox.net
Sun May 30 14:51:34 CEST 2010
Author: scheusso
Date: 2010-05-30 14:51:33 +0200 (Sun, 30 May 2010)
New Revision: 7015
Added:
code/branches/presentation3/src/modules/designtools/ScreenshotManager.cc
code/branches/presentation3/src/modules/designtools/ScreenshotManager.h
Modified:
code/branches/presentation3/src/modules/designtools/CMakeLists.txt
Log:
adding ScreenshotManager in order to be able to make high-resolution screenshots (not testet or embedded yet, but compiles)
Modified: code/branches/presentation3/src/modules/designtools/CMakeLists.txt
===================================================================
--- code/branches/presentation3/src/modules/designtools/CMakeLists.txt 2010-05-30 12:50:19 UTC (rev 7014)
+++ code/branches/presentation3/src/modules/designtools/CMakeLists.txt 2010-05-30 12:51:33 UTC (rev 7015)
@@ -1,6 +1,7 @@
SET_SOURCE_FILES(DESIGNTOOLS_SRC_FILES
SkyboxGenerator.cc
CreateStars.cc
+ ScreenshotManager.cc
)
ORXONOX_ADD_LIBRARY(designtools
Added: code/branches/presentation3/src/modules/designtools/ScreenshotManager.cc
===================================================================
--- code/branches/presentation3/src/modules/designtools/ScreenshotManager.cc (rev 0)
+++ code/branches/presentation3/src/modules/designtools/ScreenshotManager.cc 2010-05-30 12:51:33 UTC (rev 7015)
@@ -0,0 +1,145 @@
+/* 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>
+#include <OgreCamera.h>
+#include <OgreRoot.h>
+
+#include "core/GraphicsManager.h"
+
+//using namespace Ogre;
+
+namespace orxonox
+{
+
+ ScreenshotManager::ScreenshotManager(Ogre::RenderWindow* pRenderWindow, int gridSize, std::string fileExtension, bool overlayFlag)
+ {
+ //set file extension for the Screenshot files
+ mFileExtension = fileExtension;
+ // the gridsize
+ mGridSize = gridSize;
+ // flag for overlay rendering
+ mDisableOverlays = overlayFlag;
+ //get current window size
+ mWindowWidth = pRenderWindow->getWidth();
+ mWindowHeight = pRenderWindow->getHeight();
+ //create temporary texture
+ mTempTex = Ogre::TextureManager::getSingleton().createManual("ScreenShotTex",
+ Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,
+ mWindowWidth, mWindowHeight,0, Ogre::PF_B8G8R8, Ogre::TU_RENDERTARGET);
+
+ //get The current Render Target of the temp Texture
+ mRT = mTempTex->getBuffer()->getRenderTarget();
+
+ //HardwarePixelBufferSharedPtr to the Buffer of the temp Texture
+ mBuffer = mTempTex->getBuffer();
+
+ //create PixelBox
+ uint8_t* data_ = new uint8_t[(mWindowWidth * mGridSize) * (mWindowHeight * mGridSize) * 3];
+ mFinalPicturePB = Ogre::PixelBox(mWindowWidth * mGridSize,mWindowHeight * mGridSize,1,Ogre::PF_B8G8R8,data_);
+
+ }
+
+
+ ScreenshotManager::~ScreenshotManager()
+ {
+ delete[] data_;
+ }
+
+
+ /* 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 ScreenshotManager::makeScreenshot(Ogre::Camera* camera, std::string fileName) const
+ {
+
+ //Remove all viewports, so the added Viewport(camera) ist the only
+ mRT->removeAllViewports();
+ mRT->addViewport(camera);
+
+ //set the viewport settings
+ Ogre::Viewport *vp = mRT->getViewport(0);
+ vp->setClearEveryFrame(true);
+ vp->setOverlaysEnabled(false);
+
+ // remind current overlay flag
+ bool enableOverlayFlag = GraphicsManager::getInstance().getViewport()->getOverlaysEnabled();
+
+ // we disable overlay rendering if it is set in config file and the viewport setting is enabled
+ if(mDisableOverlays && enableOverlayFlag)
+ GraphicsManager::getInstance().getViewport()->setOverlaysEnabled(false);
+
+ if(mGridSize <= 1)
+ {
+ // Simple case where the contents of the screen are taken directly
+ // Also used when an invalid value is passed within gridSize (zero or negative grid size)
+ mRT->update(); //render
+
+ //write the file on the Harddisk
+ mRT->writeContentsToFile(fileName + "." + mFileExtension);
+ }
+ else
+ {
+ //define the original frustum extents variables
+ Ogre::Real originalFrustumLeft, originalFrustumRight, originalFrustumTop, originalFrustumBottom;
+ // set the original Frustum extents
+ camera->getFrustumExtents(originalFrustumLeft, originalFrustumRight, originalFrustumTop, originalFrustumBottom);
+
+ // compute the Stepsize for the drid
+ Ogre::Real frustumGridStepHorizontal = (originalFrustumRight * 2) / mGridSize;
+ Ogre::Real frustumGridStepVertical = (originalFrustumTop * 2) / mGridSize;
+
+ // process each grid
+ Ogre::Real frustumLeft, frustumRight, frustumTop, frustumBottom;
+ for (unsigned int nbScreenshots = 0; nbScreenshots < mGridSize * mGridSize; nbScreenshots++)
+ {
+ int y = nbScreenshots / mGridSize;
+ int x = nbScreenshots - y * mGridSize;
+
+ // Shoggoth frustum extents setting
+ // compute the new frustum extents
+ frustumLeft = originalFrustumLeft + frustumGridStepHorizontal * x;
+ frustumRight = frustumLeft + frustumGridStepHorizontal;
+ frustumTop = originalFrustumTop - frustumGridStepVertical * y;
+ frustumBottom = frustumTop - frustumGridStepVertical;
+
+ // set the frustum extents value to the camera
+ camera->setFrustumExtents(frustumLeft, frustumRight, frustumTop, frustumBottom);
+
+ // ignore time duration between frames
+ Ogre::Root::getSingletonPtr()->clearEventTimes();
+ mRT->update(); //render
+
+ //define the current
+ Ogre::Box subBox = Ogre::Box(x* mWindowWidth,y * mWindowHeight,x * mWindowWidth + mWindowWidth, y * mWindowHeight + mWindowHeight);
+ //copy the content from the temp buffer into the final picture PixelBox
+ //Place the tempBuffer content at the right position
+ mBuffer->blitToMemory(mFinalPicturePB.getSubVolume(subBox));
+
+ }
+
+ // set frustum extents to previous settings
+ camera->resetFrustumExtents();
+
+ Ogre::Image finalImage; //declare the final Image Object
+ //insert the PixelBox data into the Image Object
+ finalImage = finalImage.loadDynamicImage(static_cast<unsigned char*>(mFinalPicturePB.data), mFinalPicturePB.getWidth(),mFinalPicturePB.getHeight(),Ogre::PF_B8G8R8);
+ // Save the Final image to a file
+ finalImage.save(fileName + "." + mFileExtension);
+
+ }
+
+ // do we have to re-enable our overlays?
+ if(enableOverlayFlag)
+ GraphicsManager::getInstance().getViewport()->setOverlaysEnabled(true);
+
+
+ // reset time since last frame to pause the scene
+ Ogre::Root::getSingletonPtr()->clearEventTimes();
+ }
+
+}
Added: code/branches/presentation3/src/modules/designtools/ScreenshotManager.h
===================================================================
--- code/branches/presentation3/src/modules/designtools/ScreenshotManager.h (rev 0)
+++ code/branches/presentation3/src/modules/designtools/ScreenshotManager.h 2010-05-30 12:51:33 UTC (rev 7015)
@@ -0,0 +1,56 @@
+/* COPYRIGHT: this code comes from http://www.ogre3d.org/wiki/index.php/High_resolution_screenshots */
+
+#ifndef __ScreenshotManager_h__
+#define __ScreenshotManager_h__
+
+#include <string>
+#include <OgrePrerequisites.h>
+#include <OgreTexture.h>
+#include <OgreHardwarePixelBuffer.h>
+#include <stdint.h>
+#include <cstring>
+#include <cstdlib>
+
+namespace orxonox
+{
+
+
+ /* Class encapsulates Screenshot functionality and provides a method for making multi grid screenshots.
+ * pRenderWindow: Pointer to the render window. This could be "mWindow" from the ExampleApplication,
+ * the window automatically created obtained when calling
+ * Ogre::Root::getSingletonPtr()->initialise(false) and retrieved by calling
+ * "Ogre::Root::getSingletonPtr()->getAutoCreatedWindow()", or the manually created
+ * window from calling "mRoot->createRenderWindow()".
+ * gridSize: The magnification factor. A 2 will create a 2x2 grid, doubling the size of the
+ screenshot. A 3 will create a 3x3 grid, tripling the size of the screenshot.
+ * 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
+ {
+ public:
+ ScreenshotManager(Ogre::RenderWindow* pRenderWindow, int gridSize, std::string fileExtension, bool overlayFlag);
+ ~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;
+
+ protected:
+ std::string mFileExtension;
+ unsigned int mGridSize, mWindowWidth, mWindowHeight;
+ bool mDisableOverlays;
+ //temp texture with current screensize
+ Ogre::TexturePtr mTempTex;
+ Ogre::RenderTexture* mRT;
+ Ogre::HardwarePixelBufferSharedPtr mBuffer;
+ //PixelBox for a large Screenshot, if grid size is > 1
+ Ogre::PixelBox mFinalPicturePB;
+ uint8_t* data_;
+ };
+
+}
+
+#endif // __ScreenshotManager_h__
More information about the Orxonox-commit
mailing list