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.