Multiple Viewports on the one screen

Hi folks,
Back again.

OK so I have started fresh and used the C# Mono game template and it runs and makes the basic full screen game window out of the box.

All Good,
so then I have begun to add the render target code line by line from HERE

All went well until I added…

_graphics.GraphicsDevice.SetRenderTarget(onScreen);

then it crashes, at this line on the Draw Method

With this exception

Clearly I am missing the point here :slight_smile: I do that quite a bit lol

I feel if I can nut out my error I can use the default C# template for the full screen window
and add render targets as needed I will be good to go.

Here is my code in full, it really is just the Vis Stud 2019 Mono game template with a few added lines from the link above,

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Trek02
{
    public class Game1 : Game
    {
        private GraphicsDeviceManager _graphics;
        private SpriteBatch _spriteBatch;
        RenderTarget2D onScreen;

        const int onScreenWidth = 800;
        const int onScreenHeight = 400;


        //GraphicsDevice.SetRenderTarget(myRenderTarget1);
        public Game1()
        {
            _graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            IsMouseVisible = true;
        }

        // TODO: Add your initialization logic here
        protected override void Initialize()
        {
            // Full Screen
            _graphics.PreferredBackBufferWidth = 1920;
            _graphics.PreferredBackBufferHeight = 1080;

            // on screen window 800 x 400
            var onScreenDevice = _graphics.GraphicsDevice;
            onScreen = new RenderTarget2D(onScreenDevice, onScreenWidth, onScreenHeight, false, onScreenDevice.DisplayMode.Format, DepthFormat.Depth24);
           
            
            
       //     mSpriteBatch = new SpriteBatch(device);


            _graphics.ApplyChanges();
            base.Initialize();
        }

        // TODO: use this.Content to load your game content here
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

        }

        // TODO: Add your update logic here
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();


            base.Update(gameTime);
        }

        // TODO: Add your drawing code here
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Silver);
          
            _graphics.GraphicsDevice.SetRenderTarget(onScreen); // <--- This is the line that kills all

            base.Draw(gameTime);
        }
    }
}

Sorry for the lengthy post, I think I was an ENT in a past life :slight_smile: