Advertisement
SilverTES

MonoGame : Split screen on 4 Viewports

Mar 13th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. private Viewport[] _viewports = new Viewport[5];
  2.  
  3. private void SetupViewports()
  4. {
  5.  int HalfWidth = this._GraphicsDeviceManager.PreferredBackBufferWidth / 2;
  6.  int HalfHeight = this._GraphicsDeviceManager.PreferredBackBufferHeight / 2;
  7.  
  8.  // full screen viewport for full screen text:
  9.  _viewports[0] = new Viewport();
  10.  _viewports[0].X = 0;
  11.  _viewports[0].Y = 0;
  12.  _viewports[0].Width = 2 * HalfWidth;
  13.  _viewports[0].Height = 2 * HalfHeight;
  14.  
  15.  // 1/4 screen viewports:
  16.  _viewports[1] = new Viewport();
  17.  _viewports[1].X = 0;
  18.  _viewports[1].Y = 0;
  19.  _viewports[1].Width = HalfWidth;
  20.  _viewports[1].Height = HalfHeight;
  21.  
  22.  _viewports[2] = new Viewport();
  23.  _viewports[2].X = HalfWidth;
  24.  _viewports[2].Y = 0;
  25.  _viewports[2].Width = HalfWidth;
  26.  _viewports[2].Height = HalfHeight;
  27.  
  28.  _viewports[3] = new Viewport();
  29.  _viewports[3].X = 0;
  30.  _viewports[3].Y = HalfHeight;
  31.  _viewports[3].Width = HalfWidth;
  32.  _viewports[3].Height = HalfHeight;
  33.  
  34.  _viewports[4] = new Viewport();
  35.  _viewports[4].X = HalfWidth;
  36.  _viewports[4].Y = HalfHeight;
  37.  _viewports[4].Width = HalfWidth;
  38.  _viewports[4].Height = HalfHeight;
  39. }
  40.  
  41. public void DrawScene()
  42. {
  43.  for (int i = 0; i < 4; ++i)
  44.  {
  45.   _GraphicsDevice.Viewport = _viewports[i + 1];
  46.   // TODO: set view and projection matrix
  47.   // TODO: draw viewport
  48.  }
  49.  
  50.  _GraphicsDevice.Viewport = _viewports[0];
  51.  // TODO: set view and projection matrix
  52.  // TODO: draw full screen text
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement