Save Texture Back To File

Started by sushobhit, July 08, 2014, 12:29:38 PM

Previous topic - Next topic

sushobhit

Hi ,

I am facing difficulty in saving Texture Back to File.

OK.

So , I get the  rendered scene into a Texture.

Now , how can I save this Texture into a bitmap ????



EgonOlsen

You can't, at least not directly. But you can blit the texture into the FrameBuffer and get the pixels via FrameBuffer.getPixels(). Convert that int[]-array into a bitmap, crop and save it.

sushobhit

Also a very peculiar issue that crops up during the process of putting the rendered scene onto a Texture is the resulting image is

Mirrored & inverted 180 degrees (is it a bug or am I doing something wrong)

I do something like this :

fb.setRenderTarget(TextureManager.getInstance().getTexture("theimage"));

world.renderScene(fb);
world.draw(fb);

fb.display();

fb.removeRenderTarget();

/// Then I blit the image on the fb

fb.blit(TextureManager.getInstance().getTexture("theimage"),0,0,0,0,512,512,fb.getWidth(),fb.getHeight(),-1,false);

/// This image I get is rotated 180degrees and mirrored ?? why so ??? I dont know !!!

EgonOlsen

That's how it's supposed to be. It's caused by the way in which OpenGL works. You can either blit the texture with yStart at the bottom and a negative height or flip the bitmap after grabbing it.

sushobhit

Thanks I works perfectly now ... I just changed this :

From :

fb.blit(TextureManager.getInstance().getTexture("cctv1"),0,0,0,0,512,512,300,200,-1,false);

To :

fb.blit(TextureManager.getInstance().getTexture("cctv1"),0,0,0,200,512,512,300,-200,-1,false);