GraphicsDevice.Viewport Property
Gets or sets a viewport identifying the portion of the render target to receive draw calls.
Namespace: Microsoft.Xna.Framework.Graphics
Assembly: Microsoft.Xna.Framework.Graphics (in microsoft.xna.framework.graphics.dll)
This code sample demonstrates how to use the Viewport property to display different scenes to different parts of the screen.
Viewport defaultViewport; Viewport leftViewport; Viewport rightViewport; Matrix projectionMatrix; Matrix halfprojectionMatrix; protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); defaultViewport = GraphicsDevice.Viewport; leftViewport = defaultViewport; rightViewport = defaultViewport; leftViewport.Width = leftViewport.Width / 2; rightViewport.Width = rightViewport.Width / 2; rightViewport.X = leftViewport.Width; // rightViewport.X = leftViewport.Width + 1; Ring = Content.Load<Model>("redtorus"); projectionMatrix = Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, 4.0f / 3.0f, 1.0f, 10000f); halfprojectionMatrix = Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, 2.0f / 3.0f, 1.0f, 10000f); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Viewport = defaultViewport; GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.Viewport = leftViewport; DrawScene(gameTime, Camera1.ViewMatrix, halfprojectionMatrix); GraphicsDevice.Viewport = rightViewport; DrawScene(gameTime, Camera2.ViewMatrix, halfprojectionMatrix); base.Draw(gameTime); }