Create bitmap render in background (not onscreen) from .NET app

Hello,

I’ve been making a 2D rigging cutout animation studio with a Monogame runtime engine. People in the community also would like a prerender-animation-to-spritesheet feature so they don’t need a runtime engine in their game perse.

The app is made with Microsoft WPF and exporting the viewport’s content to bitmap using the WPF solution (RenderTargetBitmap) turned out to be lower quality than what is shown on screen.

So, instead, I thought to run an invisible MonoGame instead: create a minimal Game subclass linked to an (invisible?) Window, a GraphicsDeviceManager, Initialize(), RenderSingleFrame() -> Texture -> Bitmap…

Would this work? Or conflict with what WPF is doing? Or do you have better ideas?

I remember SharpDX has a WPF Control somewhere, but it was deprecated? And there was a MonoGame WPF control I used once, but it had issues recovering after a PC sleep. I read some time ago MonoGame was looking into a new DirectX wrapper initiative, as SharpDX is frozen, but I can’t find it back anymore…

Sorry this is a bit of a stretch to ask here, but I’m sure this is tangential to knowledge that thrives here :slight_smile:

thank you

If it is a tool, why not just show a preview and use that preview as the export frame?

Hi,

The viewport is a WPF Viewport3D control, which is a relatively thin layer on top of DirectX, but there is no way for me to get hold of the output of that viewport as a bitmap (WPF has this feature, but the export is lower quality than the on-screen rendering … i think it uses a software renderer for the export feature)

Some context:

As you mentioned, i already have a viewport. But there is no (good) way to get to the pixels of what is shown there. I just define triangles, a camera, … and the viewport control does the DirectX rendering to screen below the hood.

A poor solution is to just render each animation frame in the viewport and grab screenshots, but that is very unrobust. The user cannot alt-tab away, no other app is allowed to overlap, etc… poor solution.

So, I was hoping to have a MonoGame in the background render the same tris as my viewport and render to a texture2d…