The default writeContentsToFile method only take a RGB image screenshot,
How to take a 8bit grey scale image screenshot?
How to take a 8bit grey scale image screenshot
- westpointer
- Halfling
- Posts: 62
- Joined: Fri May 23, 2008 9:29 am
- syedhs
- Silver Sponsor
- Posts: 2703
- Joined: Mon Aug 29, 2005 3:24 pm
- Location: Kuala Lumpur, Malaysia
- x 51
Re: How to take a 8bit grey scale image screenshot
The code for writeContentsToFile is quite simple, found at OgreRenderTarget.cpp :-
You can probably try it yourself by copy-pasting the code above somewhere, changing the first line into
I don't really know whether this will work, but you can give it a test
Code: Select all
PixelFormat pf = suggestPixelFormat();
uchar *data = OGRE_ALLOC_T(uchar, mWidth * mHeight * PixelUtil::getNumElemBytes(pf), MEMCATEGORY_RENDERSYS);
PixelBox pb(mWidth, mHeight, 1, pf, data);
copyContentsToMemory(pb);
Image().loadDynamicImage(data, mWidth, mHeight, 1, pf, false, 1, 0).save(filename);
OGRE_FREE(data, MEMCATEGORY_RENDERSYS);
Code: Select all
PixelFormat pf = PF_L8;
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
- westpointer
- Halfling
- Posts: 62
- Joined: Fri May 23, 2008 9:29 am
Re: How to take a 8bit grey scale image screenshot
Yes, It works. But when I try to save a RTT texture to file, the result looks confusing:
Here is the code:
Here is the code:
Code: Select all
PixelFormat pf = PF_L8;
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual("RttTex",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, width, height, 0, pf, TU_RENDERTARGET);
Ogre::RenderTexture *renderTexture = texture->getBuffer(0,0)->getRenderTarget();
renderTexture->addViewport(mCamera);
renderTexture->getViewport(0)->setClearEveryFrame(true);
renderTexture->getViewport(0)->setBackgroundColour(ColourValue::Black);
renderTexture->getViewport(0)->setOverlaysEnabled(false);
renderTexture->setAutoUpdated(true);
uchar *data = OGRE_ALLOC_T(uchar, mWidth * mHeight * PixelUtil::getNumElemBytes(pf), MEMCATEGORY_RENDERSYS);
PixelBox pb(mWidth, mHeight, 1, pf, data);
renderTexture->copyContentsToMemory(pb,Ogre::RenderTarget::FB_AUTO);
Image().loadDynamicImage(data, mWidth, mHeight, 1, pf, false, 1, 0).save(filename);
OGRE_FREE(data, MEMCATEGORY_RENDERSYS);
- westpointer
- Halfling
- Posts: 62
- Joined: Fri May 23, 2008 9:29 am
Re: How to take a 8bit grey scale image screenshot
I find that the problem comes from this line:
after change it to:
the result is just OK.
But in http://www.ogre3d.org/wiki/index.php/In ... Tutorial_7, it says:
Edit: Damn it, it is all my fault, I shouldn't call setAutoUpdate() every time I take a screenshot.
Code: Select all
renderTexture->setAutoUpdated(true);
Code: Select all
renderTexture->update();
But in http://www.ogre3d.org/wiki/index.php/In ... Tutorial_7, it says:
Quite confusingYou can do this either manually via the update() function or request the application to automatically update the RenderTexture by once calling the setAutoUpdate() function.
Edit: Damn it, it is all my fault, I shouldn't call setAutoUpdate() every time I take a screenshot.