partial work toward keeping multiple render targets around for GIF encoding

GitOrigin-RevId: 8061896562453a95013ada91df852afc9e904c76
This commit is contained in:
Colin McMillen 2019-12-09 17:21:22 -05:00
parent 524ed70b9d
commit df6cee8df1

View File

@ -2,13 +2,16 @@
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
namespace Jumpy {
public class JumpyGame : Game {
GraphicsDeviceManager graphics;
RenderTarget2D renderTarget;
const int numRenderTargets = 1;
RenderTarget2D[] renderTargets = new RenderTarget2D[numRenderTargets];
int renderTargetIdx = 0;
SpriteBatch spriteBatch;
SpriteFont font;
KeyboardInput keyboardInput = new KeyboardInput();
@ -29,10 +32,12 @@ namespace Jumpy {
display = (IDisplay) Services.GetService(typeof(IDisplay));
display.Initialize(Window, graphics);
display.SetFullScreen(fullScreen);
renderTarget = new RenderTarget2D(
GraphicsDevice, Camera.Width, Camera.Height, false /* mipmap */,
GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
for (int i = 0; i < renderTargets.Length; i++) {
renderTargets[i] = new RenderTarget2D(
GraphicsDevice, Camera.Width, Camera.Height, false /* mipmap */,
GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
}
base.Initialize();
}
@ -77,8 +82,9 @@ namespace Jumpy {
fpsCounter.Update();
// Draw scene to RenderTarget.
RenderTarget2D renderTarget = renderTargets[renderTargetIdx];
renderTargetIdx = (renderTargetIdx + 1) % renderTargets.Length;
GraphicsDevice.SetRenderTarget(renderTarget);
// GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true };
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
player.Draw(gameTime, spriteBatch);