Advertisement
Guest User

upscaled window in monogame

a guest
Oct 13th, 2021
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. public class Game1 : Game
  2.     {
  3.  
  4.        
  5.         private GraphicsDeviceManager graphics;
  6.         private SpriteBatch spriteBatch;
  7.         private RenderTarget2D renderTarget;
  8.         private int gameWidth = 320;
  9.         private int gameHeight = 180;
  10.         private Rectangle upScaledResulution= new Rectangle(0, 0, 1920, 1080);
  11.        
  12.  
  13.         public Game1()
  14.         {
  15.             graphics = new GraphicsDeviceManager(this);
  16.             Content.RootDirectory = "Content";
  17.             IsMouseVisible = true;
  18.         }
  19.  
  20.         protected override void Initialize()
  21.         {
  22.             // TODO: Add your initialization logic here
  23.  
  24.             graphics.PreferredBackBufferWidth = 1920;
  25.             graphics.PreferredBackBufferHeight = 1080;
  26.             graphics.ApplyChanges();
  27.             renderTarget = new RenderTarget2D(GraphicsDevice, gameWidth, gameHeight);
  28.             base.Initialize();
  29.         }
  30.  
  31.         protected override void LoadContent()
  32.         {
  33.             spriteBatch = new SpriteBatch(GraphicsDevice);
  34.            
  35.             //load your content like normal here
  36.            
  37.         }
  38.  
  39.         protected override void Update(GameTime gameTime)
  40.         {
  41.  
  42.  
  43.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
  44.                 Exit();
  45.  
  46.  
  47.            
  48.             base.Update(gameTime);
  49.         }
  50.  
  51.         protected override void Draw(GameTime gameTime)
  52.         {
  53.             GraphicsDevice.SetRenderTarget(renderTarget);
  54.             GraphicsDevice.Clear(Color.CornflowerBlue);
  55.             spriteBatch.Begin(samplerState: SamplerState.PointClamp);
  56.  
  57.             //draw your sprites, just like you normally would here
  58.  
  59.  
  60.             spriteBatch.End();
  61.             GraphicsDevice.SetRenderTarget(null);
  62.             spriteBatch.Begin(samplerState: SamplerState.PointClamp);
  63.             //this will draw the rendertarget to the screen
  64.             spriteBatch.Draw(renderTarget, upScaledResulution, Color.White);
  65.             spriteBatch.End();
  66.            
  67.  
  68.             base.Draw(gameTime);
  69.         }
  70.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement