Multiple RenderTargets Not Working

Hi all,

Given the current context below, my playerTarget rt will not draw to screen, however my background rt will draw just fine.
how can i rectify this/have more than 1 rendertarget active?
If i wanted to add all and any sprites with a render target, how can i achieve that?
Is this the wrong mindset, if so what is the correct way to upscale 32x32 textures in monogame?
My overall goal is to have all textures scaled to at least 2F and be able to dictate scale size across the board for any and all textures I want to bring into game

Any help would be appreciated
Here’s the code:

GraphicsDevice.SetRenderTarget(renderTarget);

        GraphicsDevice.Clear(Color.CornflowerBlue);

       _spriteBatch.Begin(this.camera, SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone);

        
        _spriteBatch.Draw(background, new Vector2(-500, -500), Color.White);
        


        _spriteBatch.End();
        GraphicsDevice.SetRenderTarget(null);

      
        _spriteBatch.Begin(samplerState: SamplerState.PointClamp);
        _spriteBatch.Draw(renderTarget, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, scale: 3.5f, SpriteEffects.None, 0f);
        

        _spriteBatch.End();

        GraphicsDevice.SetRenderTarget(playerTarget);

        _spriteBatch.Begin(this.camera, SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone);

        _spriteBatch.Draw(playerSprite, player.position, Color.White);
        
        _spriteBatch.End();


        _spriteBatch.Begin(samplerState: SamplerState.PointClamp);
        _spriteBatch.Draw(playerTarget, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, scale: 2f, SpriteEffects.None, 0f);


        _spriteBatch.End();
        GraphicsDevice.SetRenderTarget(null);

        base.Draw(gameTime);

First you do

GraphicsDevice.SetRenderTarget(playerTarget);

and a bit later

_spriteBatch.Draw(playerTarget, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, scale: 2f, SpriteEffects.None, 0f);

but you haven’t changed to a different render target in between, which means you are trying to use a render target while it is still being rendered too. That’s not possible. You have to switch to another target (or null) first.

Hi guys, in the end i found out this was a fundamental issue and syntax issue i was experiencing.

I was under the impression i had to use RenderTargets to upscale textures and in the original spritebatch.draw, i was missing an extra line, which at the time made me think i couldn’t use the scale feature.

Been learning MonoGame and c# for 1 month so far, I over complicated it lol :face_exhaling:

When in fact, all i had to do was:


  _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone);

             _spriteBatch.Draw(background, new Vector2(-500, -500), null, Color.White, 0f, Vector2.Zero, scale: 3.4f, SpriteEffects.None, 0);

            _spriteBatch.End();

            _spriteBatch.Begin(this.camera, SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone);
            
            _spriteBatch.Draw(playerSprite, player.position, null, Color.White, 0f, Vector2.Zero, scale: 1.8f, SpriteEffects.None, 0);
            
            _spriteBatch.End();
1 Like