mono/MonoGame — Issue #345: RenderTarget gets cut off
Author: degborta
Created: 2012-03-02 07:36:17+00:00
State: open

I have an example where I basically load a texture that is 1024x768 and also create a RenderTarget that is 1024x768. I set the backbuffer to 768x1024 (iPad portrait) and then try to render the texture to the RenderTarget and rotating it to show.

This should display the complete texture, but it is cutoff at 768px width. So it seems the rendertarget cant be larger than the viewport.

///

/// This is the main type for your game
///

public class Game : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

int ScreenWidth = 768;
int ScreenHeight = 1024;

Texture2D debugTexture;
Texture2D screenTexture;
RenderTarget2D renderTarget;

public Game ()
{
graphics = new GraphicsDeviceManager (this);
Content.RootDirectory = "Content";

// setting the backbuffer to 768 x 1024 (iPad Portrait)
graphics.PreferredBackBufferWidth = ScreenWidth;
graphics.PreferredBackBufferHeight = ScreenHeight;

graphics.SupportedOrientations = DisplayOrientation.Portrait;
}

protected override void Initialize() {
// TODO: Add your initialization logic here
base.Initialize();
}

protected override void LoadContent ()
{

spriteBatch = new SpriteBatch (GraphicsDevice);

// loading a texture that is 1024x768 with marked corners
debugTexture = Content.Load ("debug");

// Setting the rendertarget to 1024x768 (iPad Landscape)
renderTarget = new RenderTarget2D (GraphicsDevice, ScreenHeight, ScreenWidth);
}

protected override void UnloadContent() {

}

protected override void Update(GameTime gameTime) {
base.Update(gameTime);
}

protected override void Draw (GameTime gameTime)
{
// Setting the rendertarget to our 1024x768
GraphicsDevice.SetRenderTarget (renderTarget);
GraphicsDevice.Clear (Color.Green);

spriteBatch.Begin ();

// Drawing our texture to the rendertarget (1024x768)
spriteBatch.Draw (debugTexture, renderTarget.Bounds, Color.White);
spriteBatch.End ();

// Clearing the backbuffer
GraphicsDevice.SetRenderTarget (null);
GraphicsDevice.Clear (Color.Green);

// Setting our temporary texture to the newly drawn rendertarget (1024x768)
screenTexture = (Texture2D)renderTarget;

spriteBatch.Begin ();

// drawing the texture to screen and rotating it to show that it is cut off
// this should show the complete texture when rotating, instead it only shows 768px of it
spriteBatch.Draw (screenTexture, Vector2.Zero, null, Color.White, MathHelper.ToRadians ((float)gameTime.TotalGameTime.TotalSeconds), Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);

spriteBatch.End ();

base.Draw (gameTime);
}
}