Skip to content

Instantly share code, notes, and snippets.

@TheSpydog
Created June 25, 2020 19:18
Show Gist options
  • Save TheSpydog/3dafb5c289f66804c3df3624cf0c5bb5 to your computer and use it in GitHub Desktop.
Save TheSpydog/3dafb5c289f66804c3df3624cf0c5bb5 to your computer and use it in GitHub Desktop.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace ShaderTest
{
class ShaderTestGame : Game
{
GraphicsDeviceManager graphics;
RenderTarget2D renderTarget;
SpriteBatch spriteBatch;
SamplerState lowDetail;
Texture2D surge;
public static void Main(string[] args)
{
using (ShaderTestGame game = new ShaderTestGame())
{
game.Run();
}
}
public ShaderTestGame()
{
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
graphics.PreferMultiSampling = false;
Content.RootDirectory = "Content";
Window.AllowUserResizing = false;
IsMouseVisible = true;
}
protected override void LoadContent()
{
base.LoadContent();
spriteBatch = new SpriteBatch(GraphicsDevice);
renderTarget = new RenderTarget2D(GraphicsDevice, 200, 200, true, SurfaceFormat.Color, DepthFormat.None);
surge = Content.Load<Texture2D>("surge");
lowDetail = SamplerState.PointClamp;
lowDetail.MaxMipLevel = 2;
}
protected override void UnloadContent()
{
base.UnloadContent();
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(surge, Vector2.Zero, Color.White);
spriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
spriteBatch.Draw(renderTarget, Vector2.Zero, Color.White);
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, lowDetail, DepthStencilState.None, RasterizerState.CullNone);
spriteBatch.Draw(renderTarget, new Vector2(0, 200), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment