I'm trying to get the output from the render to texture to write into a file.
I have modifed the RenderToTexture example, and it works for the ApfelBaum software renderer, but none of the others. Lock returns a valid pointer, but the data is empty. Can someone tell me what I'm doing wrong? (ie: why it will not work with DX8,9 & OpenGL)
Thank you!
Code: Select all
if (rt)
{
// draw scene into render target
// set render target texture
driver->setRenderTarget(rt, true, true, video::SColor(0,0,0,255));
// make cube invisible and set fixed camera as active camera
test->setVisible(false);
smgr->setActiveCamera(fixedCam);
// draw whole scene into render buffer
smgr->drawAll();
//NEW CODE FOLLOWS::
core::dimension2d<s32> rtsize;
unsigned char *data = (unsigned char *)rt->lock();
rtsize = rt->getSize();
video::ECOLOR_FORMAT ecf = rt->getColorFormat();
//assuming 32bit ARGB, writing out to a 24bit RGB
FILE *fout = fopen("output.raw","wb");
for (int j=0;j<rtsize.Height;j++)
for (int i=0;i<rtsize.Width;i++) {
fwrite(&data[i*4+rt->getPitch()*j],sizeof(char),3,fout);
}
fflush(fout);
fclose(fout);
rt->unlock();
//END NEW CODE
// set back old render target
driver->setRenderTarget(0);
// make the cube visible and set the user controlled camera as active one
test->setVisible(true);
smgr->setActiveCamera(fpsCamera);
}