XNA Split screen on 4 Viewports


private Viewport[] _viewports = new Viewport[5];

private void SetupViewports()
{
int HalfWidth = this._GraphicsDeviceManager.PreferredBackBufferWidth / 2;
int HalfHeight = this._GraphicsDeviceManager.PreferredBackBufferHeight / 2;

// full screen viewport for full screen text:
_viewports[0] = new Viewport();
_viewports[0].X = 0;
_viewports[0].Y = 0;
_viewports[0].Width = 2 * HalfWidth;
_viewports[0].Height = 2 * HalfHeight;

// 1/4 screen viewports:
_viewports[1] = new Viewport();
_viewports[1].X = 0;
_viewports[1].Y = 0;
_viewports[1].Width = HalfWidth;
_viewports[1].Height = HalfHeight;

_viewports[2] = new Viewport();
_viewports[2].X = HalfWidth;
_viewports[2].Y = 0;
_viewports[2].Width = HalfWidth;
_viewports[2].Height = HalfHeight;

_viewports[3] = new Viewport();
_viewports[3].X = 0;
_viewports[3].Y = HalfHeight;
_viewports[3].Width = HalfWidth;
_viewports[3].Height = HalfHeight;

_viewports[4] = new Viewport();
_viewports[4].X = HalfWidth;
_viewports[4].Y = HalfHeight;
_viewports[4].Width = HalfWidth;
_viewports[4].Height = HalfHeight;
}

public void DrawScene()
{
for (int i = 0; i < 4; ++i)
{
_GraphicsDevice.Viewport = _viewports[i + 1];
// TODO: set view and projection matrix
// TODO: draw viewport
}

_GraphicsDevice.Viewport = _viewports[0];
// TODO: set view and projection matrix
// TODO: draw full screen text
}