From b80c4fae413aca443d380df4bf056a7efad70a0a Mon Sep 17 00:00:00 2001 From: "J. M. Ellis" <75238062+Othelas@users.noreply.github.com> Date: Tue, 14 May 2024 22:13:06 -0700 Subject: [PATCH] Added render targeting for retro scale. (#1) --- Game1.cs | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/Game1.cs b/Game1.cs index 7e0dbf6..55ade89 100644 --- a/Game1.cs +++ b/Game1.cs @@ -6,32 +6,50 @@ namespace LunaLightXMG { public class Game1 : Game { - private GraphicsDeviceManager _graphics; - private SpriteBatch _spriteBatch; + private GraphicsDeviceManager graphics; + private SpriteBatch spriteBatch; + + // Test Render Target + private RenderTarget2D renderTarget; + private Rectangle renderDestination; + + // Native retro scale + private int retroWidth = 320; + private int retroHeight = 180; public Game1() { - _graphics = new GraphicsDeviceManager(this); + graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; IsMouseVisible = true; + + //Window.ClientSizeChanged += OnClientSizeChanged; // Jensen can implement + Window.AllowUserResizing = true; + IsMouseVisible = true; } protected override void Initialize() { - // TODO: Add your initialization logic here + // Set initial window size + graphics.PreferredBackBufferWidth = 1920; + graphics.PreferredBackBufferHeight = 1080; + graphics.ApplyChanges(); base.Initialize(); + //CalculateRenderDestination(); // Jensen can implement } protected override void LoadContent() { - _spriteBatch = new SpriteBatch(GraphicsDevice); + spriteBatch = new SpriteBatch(GraphicsDevice); - // TODO: use this.Content to load your game content here + // Test Render Target + renderTarget = new RenderTarget2D(GraphicsDevice, retroWidth, retroHeight); } protected override void Update(GameTime gameTime) { + // Temporary quit game - eventually handle in a pause menu class if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); @@ -44,7 +62,19 @@ namespace LunaLightXMG { GraphicsDevice.Clear(Color.CornflowerBlue); - // TODO: Add your drawing code here + // Test Render Target - Draw sprites to the render target + GraphicsDevice.SetRenderTarget(renderTarget); + + // Test Sprite + spriteBatch.Begin(samplerState: SamplerState.PointClamp); + // Draw sprites here + spriteBatch.End(); + + // Test Render Target - Draw render target to the screen + GraphicsDevice.SetRenderTarget(null); + spriteBatch.Begin(samplerState: SamplerState.PointClamp); + spriteBatch.Draw(renderTarget, renderDestination, Color.White); + spriteBatch.End(); base.Draw(gameTime); }