Skip to main content

History: Saving dynamic textures

Source of version: 3

Copy to clipboard
            To save an image add this function to your code:

{CODE(wrap="1", colors="c++")} void SaveImage(TexturePtr TextureToSave, String filename)
 {
     HardwarePixelBufferSharedPtr readbuffer;
     readbuffer = TextureToSave->getBuffer(0, 0);
     readbuffer->lock(HardwareBuffer::HBL_NORMAL );
     const PixelBox &readrefpb = readbuffer->getCurrentLock();    
     uchar *readrefdata = static_cast<uchar*>(readrefpb.data);        
 
     Image img;
     img = img.loadDynamicImage (readrefdata, TextureToSave->getWidth(),
         TextureToSave->getHeight(), TextureToSave->getFormat());    
     img.save(filename);
     
     readbuffer->unlock();
 }
{CODE}
and then simply call SaveImage

e.g {MONO()}SaveImage(texture, "test.png");{MONO}
where texture is the TexturePtr you have drawn your dynamic texture into.

Will Bricknell

!!Practical method with RenderTexture
The class RenderTarget contains a function "writeContentsToFile(string)" which do exactly what you want :

{CODE(wrap="1", colors="c++")}RenderTexture* mRenderTexture = mRoot->getRenderSystem()->createRenderTexture("depthMap", 512, 512, TEX_TYPE_2D, PF_FLOAT16_RGBA );
....
mRenderTexture->writeContentsToFile(filename);{CODE}

Rockeye.
        

History

Information Version
Thu 14 of Apr, 2011 07:24 GMT-0000 spacegaier some cleanup 5
Wed 13 of Apr, 2011 23:26 GMT-0000 Vitefalcon 4
Sat 02 of Jan, 2010 05:35 GMT-0000 jacmoe 3
Thu 24 of Dec, 2009 17:56 GMT-0000 jacmoe 2
Mon 10 of Nov, 2008 19:35 GMT-0000 OgreWikiBot Robot: Cosmetic changes 1