Viewport viewport = GraphicsDevice.Viewport; int screenWidth = viewport.Width; int screenHeight = viewport.Height;
Viewport customViewport = new Viewport(x, y, width, height); GraphicsDevice.Viewport = customViewport;
Viewport splitViewport = new Viewport(GraphicsDevice.Viewport.Width / 2, 0, GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height); GraphicsDevice.Viewport = splitViewport; spriteBatch.Begin(); spriteBatch.Draw(texture, new Vector2(0, 0), Color.White); spriteBatch.End();This code creates a split viewport that only renders to the right half of the screen, and draws a texture to that area using a SpriteBatch. These examples use the Microsoft.Xna.Framework.Graphics package library.