Can we do the rendering in a buffer, or a file



I’d like to take screenshots , and i wonder if i can do the rendering in a buffer or a screen.
May be texture rendering, and then saving the texture data ?

Of course, it would be even better if i could still see the rendering on screen while rendering to the buffer :slight_smile:

Thank you.


Ok, after reading this interesting post , i tried to implement. Alas it doesn’t save the whole scene. It saves hum… i don’t even know, just compare yourself:

This is one of the screenshots serie:

After removing the alpha channel with ImageMagick, i get the colors (?!!)
convert -alpha off screenshot.png screenshot_without_alpha.png

And here is what i should get (captured while running, with xwd)

Here is the code:

  1. in init() , i initialize the texture and its depth buffer:
private var screenshotTexture:h3d.mat.Texture;
private var counter:Int = 1000;
override function init()
  screenshotTexture = new h3d.mat.Texture(512, 512, [h3d.mat.Data.TextureFlags.Target]);
  screenshotTexture.depthBuffer = new h3d.mat.DepthBuffer(screenshotTexture.width, screenshotTexture.height);
  1. the renderer function is overriden, and the original one is called twice: one for the texture, two for the show (three for the money let’s go let’s go!)
override function render(e:h3d.Engine)



  var pixels = screenshotTexture.capturePixels();
  hxd.File.saveBytes("screenshot"+ counter + ".png", pixels.toPNG());

Thank you for reading :slight_smile: