Hello everybody! I’m having a strange issue where my RenderTarget2D is completely black in the background, despite the code that should say otherwise (I’m using DirectX not OpenGL btw):
protected override void Draw(GameTime gameTime)
spriteRenderer.Draw(spriteRenderer.Scene, Vector2.Zero, Color.White);
Here is an image of the game when I draw to the RenderTarget2D (The rotation is completely irrelevant to this issue):
And here is an image of the game when I draw directly to the backbuffer:
Am I missing a line somewhere? Sorry, I fairly new to coding with graphics.
Show us where you create the render target
public SpriteRenderer(GraphicsDevice graphicsDevice) : base (graphicsDevice)
for (int i = 0; i < 3; i++)
layers[i] = new RenderTarget2D(graphicsDevice, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height);
SpiteRenderer is just an extension of SpriteBatch I’m using for convenience sake.
and/or set the RenderState to Premultiplied or Alpha in spriteRenderer.Begin().
Clearing to transparent didn’t work. How do you change the RenderState?
ok . i think its the blend state, not renderate. it a parameter in spritebatch.begin.
I tried that. Still black.
Nevermind I figured it out. I had to clear after setting the render target.
I have an additional question about render targets:
If I wanted my game to have a virtual resolution of say 480x270, for a pixelated look, but run in 1080p, would I have to run Vector2s and Rectangles through some sort of transform method, if I’m using them for logic rather than drawing, or is there an easier way to do that?