Ogre-Next create screenshot fails

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Lax
Gnoll
Posts: 665
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 64

Ogre-Next create screenshot fails

Post by Lax »

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

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

User avatar
Crystal Hammer
Orc
Posts: 405
Joined: Sat Jun 23, 2007 5:16 pm
x 115

Re: Ogre-Next create screenshot fails

Post by Crystal Hammer »

IDK how to make a screenshot either.
But from your code I see you're making a texture and saving it. I don't see a line that would fill it with the contents of what's on renderwindow. But IDK how to do that. I'm guessing a workspace would be needed?

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5476
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1358

Re: Ogre-Next create screenshot fails

Post by dark_sylinc »

It's like Crystal Hammer says. You are creating a new blank texture and saving it. That's not what you want to do.

You can see UnitTesting.cpp which saves the contents of the window as RenderWindow_colour.png

Note that these three:

Code: Select all

renderWindow->setWantsToDownload( true );
renderWindow->setManualSwapRelease( true );

// every frame
renderWindow->performManualRelease();

are needed in Metal/macOS (see documentation on setManualSwapRelease) unless you take the picture in a listener, before Window::swapBuffers gets called (you always need to call setWantsToDownload(true) though).