0
\$\begingroup\$

Please forgive me if I'm asking a question that has been answered before, but for the life of me, search as I might, I couldn't find a problem exactly like this anywhere.

I'm trying to render a series of sprites, all sourced from transparent PNGs, to a texture. Each of these rendered textures would be layers in a 2D environment which could be subjected to shaders/effects before being placed on the screen.

My problem is that when I try this, the screen fills with black, and only the last texture rendered is visible.

I have tried: * clearing the graphics device after setting my render target, using color.transparent. * every surface format (those formats mean nothing to me at this interim)

I am new to this particular environment, so I am probably missing something that I can't easily look up.

\$\endgroup\$
5
  • \$\begingroup\$ What settings do your PNGs have in monogame pipeline tool? \$\endgroup\$ Commented Jul 17, 2019 at 6:06
  • \$\begingroup\$ @trollingchar - Premultiplied Alpha, format is color. I actually just sort of solved the problem a moment ago, by just drawing everything to a texture, and only putting those rendertargets onto the screen. In other environments I've worked in, that's never been an issue, but everything has its quirks. \$\endgroup\$
    – user130089
    Commented Jul 17, 2019 at 6:12
  • \$\begingroup\$ If you solved your own problem, post an answer, so anyone checking it out in the future can find the solution too. \$\endgroup\$
    – Bálint
    Commented Jul 17, 2019 at 16:17
  • \$\begingroup\$ My gut feeling is that it's possible to solve this but you'd need to provide a little more context. Post some code that you've tried (it doesn't need to be everything, just the last thing that didn't work) and provide details about the platform you're targeting (Windows? OpenGL or DirectX?) \$\endgroup\$ Commented Jul 17, 2019 at 23:45
  • \$\begingroup\$ @craftworkgames - I'm targeting multi=platform desktop, which implements GL despite asking for DX-centric stuff going in. I did manage to solve the problem, though this being a problem is more bizarre considering it's GL once it builds. If you draw a RenderTarget2D to the screen, it will wipe any plain Batch.Draw(Texture2D ...) results from the buffer for some reason. GL doesn't normally do that, so I will chalk it up to something weird in MonoGame/XNA's wrapper. RenderTarger2D's can draw over each other fine though. \$\endgroup\$
    – user130089
    Commented Jul 18, 2019 at 12:57

2 Answers 2

1
\$\begingroup\$

Turns out, while no documentation I've seen backs this up, that if you throw a texture2D directly at the screen via rendertarget being null, it gets wiped out by any RenderTargets you draw via SpriteBatch.Draw(). I've never encountered this in any other platform, but I also haven't used every platform in the universe, so this could be more commonplace than I would initially think.

Feel free to correct me if this is a symptom of something I'm missing, but problem solved regardless.

\$\endgroup\$
1
\$\begingroup\$

Digging up this old post since it has no verified answer. I had the same issue with drawing to multiple render targets. Then drawing them stacked as layers. Nothing was working till I discovered putting:

GraphicsDevice.DiscardColor = Color.Transparent;

in game1 constructor.

Hope this saved you time on a solution.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .