Saving dynamic textures         Saving the contents of a rendertarget to disk

To save an image, add this function to your code:

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*>(;        
     Image img;
     img = img.loadDynamicImage (readrefdata, TextureToSave->getWidth(),
         TextureToSave->getHeight(), TextureToSave->getFormat());;

Then simply call SaveImage()

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

Practical method with RenderTexture

The class RenderTarget contains a function "writeContentsToFile(string)" which does exactly what you want:

RenderTexture* mRenderTexture = mRoot->getRenderSystem()->createRenderTexture("depthMap", 512, 512, TEX_TYPE_2D, PF_FLOAT16_RGBA );

Shortest method

void SaveImage(TexturePtr TextureToSave, String filename)
     Image img;