UPDATE: I’m running Monogame 3.5 & DesktopGL
I got a bit of a curious problem when I dabbled with drawing to a RenderTarget2D and I’ve tried a few different setups and switched a lot of parameters, but perhaps I’m missing something or this is not how it’s intended to be used.
Say I have a RenderTarget2D that I call rtScreen, I draw everything to this RenderTarget2D because I want to be able to draw this scaled up. So the way I do that is:
SetRenderTarget(rtScreen);
// .. draw stuff
SetRenderTarget(null);
spriteBatch.Draw(rtScreen, etc..);
This works great, no problems!
Now, I want to be able to draw a textbox, which consists of different textures, and every texture is 8x8, however I want to draw a textbox that is not limited to a multiple of 8, so what I want to do is draw everything to separate textures and then draw them to rtScreen one by one.
So, my attempts have been something similar to this:
SetRenderTarget(rtTextbox);
// ..draw textbox-stuff
SetRenderTarget(rtScreen);
spriteBatch.Draw(rtTextbox, etc..);
SetRenderTarget(null);
spriteBatch.Draw(rtScreen, etc...);
This draws the rtTextbox in the correct size in the rtScreen (if there’s a background color, i can see it drawing the texture at the correct size), however the actual drawn stuff inside rtTextbox has been garbled and is a one-pixel long line.
Now, I am currently writing this while I’m not at the luxury of providing images, so this will have to be a question that might make people immediately go “wait, you are doing things wrong, here’s how it’s supposed to go”. But for anyone who goes “wait, it does that? let me investigate” I’ll have to later supply with more reasonable examples and/or images of the result.
So, finally, I guess that I could (perhaps should?) use Silhouette functionality, and before I start opening up that can of mystery ~ is drawing in memory like this not supposed to work? And yes, I have enabled Preserve on RenderTargetUsage, I’ve tried changing SurfaceFormat, I’ve tried changing DepthStencilFormat, and yes they’ve all been synchronized to be the same so I haven’t drawn with one set of parameters in one RenderTarget to another, they were all created from the same GraphicsDevice. I’ve tried creating a separate SpriteBatch to draw the stuff to one RenderTarget… let’s say I’ve put a few hours into this and I am finally just throwing this in here and hope that someone knows what I’m dealing with.
If I’ve been rambling, been unhelpful, explained the example badly and/or other stuff, sorry, just tell me and I’ll take your feedback on it.
Regards,
S