Migration Issue - Using Spritebatch in Console Application

Hi everbody,

we used to transform Bitmaps with a Spritebatch in XNA4. All of this was happening in a Console Application. Simply inheriting the used Classes from Windows.Forms was enough to use the Spritebatch in XNA4. Is there a way to do the same in Monogame?

Regards
Samuel

Not that I know of. How did you do it with XNA exactly? It seems weird to me that you’d be able to do that.

With MonoGame you can do this by creating a render target, extracting the color data from the bitmap and using Texture2D.SetData to copy over the content, edit it like you did before and afterwards use Texture2D.GetData and set the color back on the bitmap. Since you have to copy data from RAM to VRAM and back, I don’t see an easier way of doing it.

To be specific thats exactly what we are doing now. I have to admit my desription is not very specific… Normaly you use MonoGame with a GameWindow but we are using it inside a Console Application without any Windows. When we used XNA it was enough to inherit from Form to get access to the GPU but with MonoGame this doesn’t work anymore.

class GPUMagic : Form { var target = new RenderTarget2D(deviceService.GraphicsDevice, TargetWidth, TargetHeight); deviceService.GraphicsDevice.SetRenderTarget(target); /* * Do Shader &Spritebatch Magic here */ deviceService.GraphicsDevice.SetRenderTarget(null); //Extract Bitmap from target }