I have a variety of controls that are composed then drawn. One of them is more complex than the others, and is showing as a black square. I suppose I should mention that this was working under XNA 4.0, and I am shifting over to MG3.8, which has been mostly a painless process, but there are just a few differences, perhaps between DX9 and DX11. This seems like it is probably just one of the differences.
Since I have working code form other controls, I chopped most everything out of the recalcitrant control, then compared what was left, which was pretty minimal. I then altered the code a bit to more closely match the working code, and by doing so, I believe I narrowed it down to at least one line, which takes just a bit of a backstory.
I set one render target, do some drawing to that, set a second render target, do some drawing to that, then draw the first target onto the second. There’s a bit of clipping going on in there based on a stencil, and I may yet find an issue with that, but I was able to comment out all of that, to isolate the current issue.
So, what matters is that I set one render target, do some drawing, set a second render target, do some drawing, then draw one on the other. I then have this line:
GraphicalDevice.SetRenderTarget(Nothing)
Following which, I draw a texture, draw the combined rendertarget2D from the earlier step, then draw a couple more things.
It is the line shown that seems to be the source of the problem. In the working control, there is only one layer, not the blending of a few different layers (it’s just a rectangle), so I never call SetRenderTarget, I just start drawing.
Is SetRenderTarget(Nothing) the right thing to be doing having set two other render targets earlier in the code?
I also saw the other thread about a png image being all black, so I followed that SetRenderTarget line with a call to GraphicalDevice.Clear(Color.Transparent), but that didn’t appear to have any effect.
I guess I should add that the reason I feel that one line is the issue is because, if I comment out everything before it (all the rendering to other targets), I still get a black square. If I then comment out that one line, I now get a drawing. It isn’t the RIGHT drawing, since all the other composition is commented out, but it isn’t a black square, and what drawing remains is correct. So the difference between a black square and a drawing, is that one line.