User Tools

Site Tools


code_snippets:psx_scaling

This is an old revision of the document!


PSX Scaling

The code below should help you set up PlayStation 1 era visuals and should be commented enough.

Fields

Fields:
private RenderTarget2D renderTarget;

Initialize()

Initialize()
{
// set backbuffer to PlayStation 1 Wide Screen 720x480
_graphics.PreferredBackBufferWidth = 720; // 320
_graphics.PreferredBackBufferHeight = 480; // 240
_graphics.ApplyChanges(); // !
base.Initialize();
}

LoadContent()

LoadContent()
{
// Define your lower resolution render target
renderTarget = new RenderTarget2D(GraphicsDevice, 640, 480);
}

Draw()

// ! means this is important
Draw()
{
// Render your scene to the render target
GraphicsDevice.SetRenderTarget(renderTarget);  // !
GraphicsDevice.Clear(Color.CornflowerBlue);

_spriteBatch.Begin(SpriteSortMode.Deferred, 
BlendState.AlphaBlend, SamplerState.PointClamp); // pointclamp !
_spriteBatch.Draw(); // something
_spriteBatch.Draw(); // something
_spriteBatch.End();  // !

// Reset the render target to the backbuffer
GraphicsDevice.SetRenderTarget(null); // !

// Calculate the scaling factors
float scaleX = GraphicsDevice.Viewport.Width / 720f; // !
float scaleY = GraphicsDevice.Viewport.Height / 480f; // !

// Set up the viewport and scaling matrix
var viewport = new Viewport(0, 0, 720, 480); // !
var scaleMatrix = Matrix.CreateScale(scaleX, scaleY, 1.0f); // !

// Draw the render target to the backbuffer, scaling it to fill the screen
GraphicsDevice.Clear(Color.CornflowerBlue);
_spriteBatch.Begin(transformMatrix: scaleMatrix); // !
_spriteBatch.Draw(renderTarget, new Rectangle(0, 0, 720, 480), Color.White); // !
_spriteBatch.End(); // !

base.Draw(gameTime);
}

code_snippets/psx_scaling.1729537171.txt.gz · Last modified: 2024/10/21 18:59 by mrvalentine