How to take a 8bit grey scale image screenshot

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
westpointer
Halfling
Posts: 62
Joined: Fri May 23, 2008 9:29 am

How to take a 8bit grey scale image screenshot

Post by westpointer »

The default writeContentsToFile method only take a RGB image screenshot,
How to take a 8bit grey scale image screenshot?
User avatar
syedhs
Silver Sponsor
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

Post by syedhs »

The code for writeContentsToFile is quite simple, found at OgreRenderTarget.cpp :-

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);
You can probably try it yourself by copy-pasting the code above somewhere, changing the first line into

Code: Select all

PixelFormat pf = PF_L8;
I don't really know whether this will work, but you can give it a test :)
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
User avatar
westpointer
Halfling
Posts: 62
Joined: Fri May 23, 2008 9:29 am

Re: How to take a 8bit grey scale image screenshot

Post by westpointer »

Yes, It works. But when I try to save a RTT texture to file, the result looks confusing:
Image
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);
User avatar
westpointer
Halfling
Posts: 62
Joined: Fri May 23, 2008 9:29 am

Re: How to take a 8bit grey scale image screenshot

Post by westpointer »

I find that the problem comes from this line:

Code: Select all

renderTexture->setAutoUpdated(true);    
after change it to:

Code: Select all

renderTexture->update(); 
the result is just OK.
But in http://www.ogre3d.org/wiki/index.php/In ... Tutorial_7, it says:
You can do this either manually via the update() function or request the application to automatically update the RenderTexture by once calling the setAutoUpdate() function.
Quite confusing :o

Edit: Damn it, it is all my fault, :oops: I shouldn't call setAutoUpdate() every time I take a screenshot.
Post Reply