Added render targeting for retro scale. (#1)

This commit is contained in:
J. M. Ellis
2024-05-14 22:13:06 -07:00
committed by GitHub
parent f497f2a422
commit b80c4fae41
+37 -7
View File
@@ -6,32 +6,50 @@ namespace LunaLightXMG
{ {
public class Game1 : Game public class Game1 : Game
{ {
private GraphicsDeviceManager _graphics; private GraphicsDeviceManager graphics;
private SpriteBatch _spriteBatch; 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() public Game1()
{ {
_graphics = new GraphicsDeviceManager(this); graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content"; Content.RootDirectory = "Content";
IsMouseVisible = true; IsMouseVisible = true;
//Window.ClientSizeChanged += OnClientSizeChanged; // Jensen can implement
Window.AllowUserResizing = true;
IsMouseVisible = true;
} }
protected override void Initialize() protected override void Initialize()
{ {
// TODO: Add your initialization logic here // Set initial window size
graphics.PreferredBackBufferWidth = 1920;
graphics.PreferredBackBufferHeight = 1080;
graphics.ApplyChanges();
base.Initialize(); base.Initialize();
//CalculateRenderDestination(); // Jensen can implement
} }
protected override void LoadContent() 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) 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)) if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit(); Exit();
@@ -44,7 +62,19 @@ namespace LunaLightXMG
{ {
GraphicsDevice.Clear(Color.CornflowerBlue); 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); base.Draw(gameTime);
} }