Window size

I tried to follow the EmptyKeys UI tutorial to make a sample GUI.

In the process, I created the following event handler for graphics.PreparingDeviceSettings:

private void Graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
{
    this.nativeScreenWidth = this.graphics.PreferredBackBufferWidth;
    this.nativeScreenHeight = this.graphics.PreferredBackBufferHeight;

    this.graphics.PreferredBackBufferWidth = WINDOW_WIDTH; // const int = 1280
    this.graphics.PreferredBackBufferHeight = WINDOW_HEIGHT; // const int = 720
    this.graphics.PreferMultiSampling = true;
    this.graphics.GraphicsProfile = GraphicsProfile.HiDef;
    this.graphics.SynchronizeWithVerticalRetrace = true;
    this.graphics.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8;

    e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = 16;
}

which is assigned like:

public WSOnlineGame()
{
    this.graphics = new GraphicsDeviceManager(this);
    this.graphics.DeviceCreated += Graphics_DeviceCreated;
    this.graphics.PreparingDeviceSettings += Graphics_PreparingDeviceSettings;
    this.Content.RootDirectory = "Content";
}

This is the other event handler:

private void Graphics_DeviceCreated(object sender, EventArgs e)
{
    //Ermöglicht Engine-Singleton
    Engine engine = new MonoGameEngine(this.GraphicsDevice, nativeScreenWidth, nativeScreenHeight);
}

From my understanding, setting the Width and Height should make the window the assigned size (1280 x 720). But when I start the program, it still runs on the default size of 800x480.
I verified that the code is called by setting a breakpoint in Visual Studio.

Google said to use ApplyChanges(), but apparently that causes an infinite loop when called inside PreparingDeviceSettings-Handler.

So why does the code not set my window size correctly? Is it not supported by my graphics card or something? Or am I overlooking something that also sets the size?

Did you try https://github.com/EmptyKeys/UI_Examples/tree/master/Empty_Example ? Do you have the same problem with that code?

Not sure if that’s related to your problem here, but there are some implementation issues in MG itself too. I know that this at least does not work exactly the same as it does in XNA.

I got to try it out today and the window was the same size as in my other project, definitely not 1280x720.
It worked fine, displaying the “Hello World”, but it was 800x480 big, the default size.

To get the demo project working, I had to re-install all the EmptyKeys NuGet packages because the packages didn’t work correctly out-of-the-box, but I don’t think this has an impact on this matter.

The following works and shows both the window and the EmptyKeys GUI in the correct size:

    public WSOnlineGame()
    {
        this.graphics = new GraphicsDeviceManager(this);
        this.graphics.DeviceCreated += Graphics_DeviceCreated;
        this.graphics.PreparingDeviceSettings += Graphics_PreparingDeviceSettings;

        this.graphics.PreferredBackBufferWidth = WINDOW_WIDTH;
        this.graphics.PreferredBackBufferHeight = WINDOW_HEIGHT;

        this.Content.RootDirectory = "Content";
    }

    private void Graphics_DeviceCreated(object sender, EventArgs e)
    {
        //Ermöglicht Engine-Singleton
        Engine engine = new MonoGameEngine(this.GraphicsDevice, WINDOW_WIDTH, WINDOW_HEIGHT);
    }

    private void Graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
    {
        this.graphics.PreferMultiSampling = true;
        this.graphics.GraphicsProfile = GraphicsProfile.HiDef;
        this.graphics.SynchronizeWithVerticalRetrace = true;
        this.graphics.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8;

        e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = 16;
    }

But if I set the Height in the PreparingDeviceSettings, it gets ignored.
@filcon May I ask why the nativeScreenHeight/Width from your example is needed to create the monogame engine?
It seems to work just fine when creating the Engine with the 1280/720.

That’s because you can have diff backbuffer from native resolution in full screen mode so you need to know native for mouse inputs.

Ok, that means if I don’t plan on doing the thing with the different backbuffers in full-screen mode (or full-screen mode in general), I can omit those, right?

If so, I’m just going to set it in the constructor and not worry about it not working in PreparingDeviceSettings.

I took this from a different question, but this will solve your issue.

Use

graphics.PreferredBackBufferWidth = your integer number

and

graphics.PreferredBackBufferHeight = your integer number

For more on making resizing by the user to work, read here: https://gamedev.stackexchange.com/questions/68914/issue-with-monogame-resizing