# Viewport Structure (Microsoft.Xna.Framework.Graphics)

Describes the view bounds for render-target surface.

**Namespace:**Microsoft.Xna.Framework.Graphics

**Assembly:**MonoGame.Framework (MonoGame.Framework.dll 3.8.0.1082)

- C#
- VB
- F#

[DataContractAttribute] [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = -1, Size = -1)] public struct Viewport

Syntax for VB is not yet implemented.

Syntax for F# is not yet implemented.

The Viewport type exposes the following members.

Platforms | Name | Description | |
---|---|---|---|

Viewport(int, int, int, int) | Constructs a viewport from the given values. The MinDepth will be 0.0 and MaxDepth will be 1.0. | ||

Viewport(int, int, int, int, float, float) | Constructs a viewport from the given values. | ||

Viewport(Rectangle) | Creates a new instance of Viewport struct. |

Platforms | Name | Description | |
---|---|---|---|

AspectRatio | Gets the aspect ratio of this Viewport, which is width / height. |
||

Bounds | Gets or sets a boundary of this Viewport. |
||

Height | The height of the bounds in pixels. | ||

MaxDepth | The upper limit of depth of this viewport. | ||

MinDepth | The lower limit of depth of this viewport. | ||

TitleSafeArea | Returns the subset of the viewport that is guaranteed to be visible on a lower quality display. | ||

Width | The width of the bounds in pixels. | ||

X | The x coordinate of the beginning of this viewport. | ||

Y | The y coordinate of the beginning of this viewport. |

Platforms | Name | Description | |
---|---|---|---|

Project | Projects a Vector3 from model space into screen space. The source point is transformed from model space to world space by the world matrix, then from world space to view space by the view matrix, and finally from view space to screen space by the projection matrix. | ||

ToString | Returns a System.String representation of this Viewport in the format:
{X:[X] Y:[Y] Width:[Width] Height:[Height] MinDepth:[MinDepth] MaxDepth:[MaxDepth]} (Overrides ValueType.ToString().) |
||

Unproject | Unprojects a Vector3 from screen space into model space. The source point is transformed from screen space to view space by the inverse of the projection matrix, then from view space to world space by the inverse of the view matrix, and finally from world space to model space by the inverse of the world matrix. Note source.Z must be less than or equal to MaxDepth. |

Supported in:

Windows DirectX Desktop

Linux Desktop

Windows OpenGL Desktop

Web

Windows DirectX Desktop

Linux Desktop

Windows OpenGL Desktop

Web