Hi all,
I'm trying to create a screenshot of whats being displayed on the monitor.
The png file is saved properly, but the picture is just black always.
This is my code so far:
Code: Select all
if (keyEventRef.key == OIS::KC_SYSRQ)
{
// Screenshot
Ogre::TextureGpuManager* textureManager = this->root->getRenderSystem()->getTextureGpuManager();
Ogre::TextureGpu* screenShotTexture = textureManager->createTexture("captureScreenShotTexture", Ogre::GpuPageOutStrategy::Discard, Ogre::TextureFlags::RenderToTexture, Ogre::TextureTypes::Type2D);
screenShotTexture->setResolution(this->renderWindow->getWidth(), this->renderWindow->getHeight());
screenShotTexture->setNumMipmaps(1u);
screenShotTexture->setPixelFormat(Ogre::PFG_RGBA8_UNORM_SRGB);
// screenShotTexture->setMsaa(1u);
screenShotTexture->scheduleTransitionTo(Ogre::GpuResidency::Resident);
screenShotTexture->waitForData();
std::time_t t = std::time(0); // get time now
std::tm* now = std::localtime(&t);
Ogre::String date = Ogre::StringConverter::toString(now->tm_year + 1900) + "-" + Ogre::StringConverter::toString(now->tm_mon + 1) + "-" +
Ogre::StringConverter::toString(now->tm_mday) + "_" + Ogre::StringConverter::toString(now->tm_min) + "_" + Ogre::StringConverter::toString(now->tm_sec);
screenShotTexture->writeContentsToFile(date + ".png", 0, 0);
textureManager->destroyTexture(screenShotTexture);
return true;
}
Has anybody an idea, what I'm doing wrong?
Any help is appreciated!
Best Regards
Lax