Heaps - save Screen to PNG

I started trying out the heaps game engine. Now I am looking for a way to capture the screen into a BitmapData Object. I am not familiar with the engine, so it would be nice if somebody could give me a hint where to start.

I was digging in the source code and there seems to be a function that saves BitmapData to a PNG. But first of course I need to capture the screen to a BitmapData.

Maybe rendering the scene on a texture and then creating a BitmapData from that texture, then saving as png?

Thank you.

Now I override function render and add that:

engine.driver.setRenderTarget(renderTexture, 0);
var pixels = renderTexture.capturePixels();

But the pixels seem to be empty. Why?



did the trick.

Hello Friends. I have a new problem.

I want to capture the screen from a 3D Scene. I am using the cool game engine HEAPS for this.
It is working, but I noticed I messed up the z-ordering, so I added a Depthbuffer. But now nothing is rendered at all, the png is empty. What did I do wrong?

	override function render(e:Engine)
		var renderTexture = new Texture(1024, 1024, [TextureFlags.Target]);
		renderTexture.depthBuffer = new DepthBuffer(renderTexture.width, renderTexture.height);
		var pixels = renderTexture.capturePixels();
		File.saveBytes("test.png", pixels.toPNG());

You should try the heaps gitter heapsio/Lobby - Gitter you’ll have better chance to get an answer.

You might need to clear the texture and depth before rendering, use engine.clear(0,1);

This does’nt work. Like you see in the function render, I create a Render Texture to render on (in the original code not in the render function). When I comment out the second line:

var renderTexture = new Texture(1024, 1024, [TextureFlags.Target]);
//renderTexture.depthBuffer = new DepthBuffer(renderTexture.width, renderTexture.heigh, Depth24);

then the 3D Scene is rendered to the render texture and I get a png-file with the scene as an Image. But the z-ordering ist messed up. When I enable it by creating a new DepthBuffer or use the default one and apply it to the renderTexture, then nothing is rendered or at least nothing is on the renderTexture except the clear color.

I don’t know if this should work and it is a bug, or I forgot something, because I did not find a documentation for that task and I am not really experienced with 3D coding. Clearing the main DepthBuffer and the renderTexture does not help.

I am using the Haxe 4 Preview and the heaps on git.