2

Using Monogame OpenGL with VS 2019, and I've applied the following code as per the usual to set the constraints of the size.

graphics = new GraphicsDeviceManager(this);
       
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;

I thought this was not working and have been scouring the net for a while trying to solve the problem, but every solution I found told me that this was the correct way to get what I wanted.

I then tested it but using the buffer width/height to set new Vector2's on drawn objects, and they appear offscreen, so it is not that it isn't working, it is that the debug window that is displaying is not resizing properly to show the entirety of the new window. I'm sure it's something simple here, but what am i missing? How can I get the window to show the entirety of the graphics device?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    As an additional comment, I've seen that with Monogame 3.8, setting this inside Initialize() will work, but I've also seen multiple sources here stating that it is against best practices to set this inside Initialize. Has this case changed with the release of 3.8? – OedipusRexed Aug 24 '20 at 18:39

2 Answers2

4

I had the same issue. Overriding the Initialize method and setting it there instead of in the constructor worked for me:

protected override void Initialize()
{
    _graphics.PreferredBackBufferWidth = 100;
    _graphics.PreferredBackBufferHeight = 100;
    _graphics.ApplyChanges();

    base.Initialize();
}
distractedhamster
  • 689
  • 2
  • 8
  • 22
0

You need to Apply changes to the graphicsDevice:

graphics.ApplyChanges();

And if you want it to be full screen (of course, do it before applying changes so that this is applied):

graphics.IsFullScreen = true;

Hope it helped!

Tommy
  • 349
  • 4
  • 13