Forums

Window Resizing
Last Post 13 Jul 2016 01:12 PM by Filip Dušek. 5 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Вадим ПлетняковUser is Offline
New Member
New Member
Posts:6


--
11 Jul 2016 10:57 PM
    Hello, I'm sorry if the answer is already somewhere on forum, but I found only stuff like http://emptykeys.com/Community/aft/113 which didn't worked for me.
    Window always starts with resolution 800/480, Monogame viewport.Width = 800 and Height = 480.
    Code like:
    private void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
    {
    nativeScreenWidth = 1920;
    nativeScreenHeight = 1080;
    graphics.PreferredBackBufferWidth = 1920;
    graphics.PreferredBackBufferHeight = 1080;

    graphics.PreferMultiSampling = true;
    graphics.GraphicsProfile = GraphicsProfile.HiDef;
    graphics.SynchronizeWithVerticalRetrace = true;
    graphics.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8;
    e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = 16;
    }
    void graphics_DeviceCreated(object sender, EventArgs e)
    {
    Engine engine = new MonoGameEngine(GraphicsDevice, nativeScreenWidth, nativeScreenHeight);
    }
    Does nothing.

    I couldn't make resizing work also.
    I tried stuff like this:

    Window.ClientSizeChanged += graphics_HandleResizing;

    private void graphics_HandleResizing(object sender, EventArgs e)
    {
    viewport = GraphicsDevice.Viewport;
    basicUI.Resize(Window.ClientBounds.Width, Window.ClientBounds.Height);
    viewport.Width = Window.ClientBounds.Width;
    viewport.Height = Window.ClientBounds.Height;

    }
    But it does nothing.
    Then I tried to debug stuff.
    And discovered that if I place values i need in Renderer.Engine.NativeScreenWidt and Native ScreenHeight then everything works fine! I want so much something like:

    engine.Renderer.NativeScreenWidth = Window.ClientBounds.Width;
    engine.Renderer.NativeScreenHeight = Window.ClientBounds.Height;

    But the fields are private.

    So I've tried creating new Engine in my graphics_HandleResizing:

    Engine engine = new MonoGameEngine(GraphicsDevice, Window.ClientBounds.Width, Window.ClientBounds.Height);

    but engine still always has Renderer.Engine.NativeScreenWidth = 800 and Native ScreenHeight 480
    Debugger says stuff like

    public MonoGameEngine(GraphicsDevice graphicsDevice, int nativeScreenWidth, int nativeScreenHeight)
    {
    this.renderer = (Renderer) new MonoGameRenderer(graphicsDevice, nativeScreenWidth, nativeScreenHeight);
    }
    But what really happens, from where it takes 800 and 480?.. Lost 3 days now and I am beyond thinking that I'm stupid... Please help.
    Filip DušekUser is Offline
    Advanced Member
    Advanced Member
    Posts:669


    --
    12 Jul 2016 09:33 AM
    I added resizing code to MonoGame examples on GitHub - http://github.com/EmptyKeys/UI_Exam...I_MonoGame
    So check that out.
    Вадим ПлетняковUser is Offline
    New Member
    New Member
    Posts:6


    --
    12 Jul 2016 07:51 PM
    Thx, that's improved example. You just forgot

    Window.AllowUserResizing = true;

    but it still didn't worked for me. Which made me think maybe I'm crazy, because you think it works. Why, I thought.
    I have Win10 on my main PC, so I did some experiments.
    I went to another Win10 machine and it starts properly there, 1920/1080. Still didn't resized properly though. On Win7 machine example works perfectly fine, mouse position is recalculated.
    Game I develop on my main PC starts properly with graphics.PreferredBackBuffer values. Other Monogame projects worked well too.
    I'll implement your library in develop branch of my game. I'm hoping things will be ok.
    Filip DušekUser is Offline
    Advanced Member
    Advanced Member
    Posts:669


    --
    12 Jul 2016 10:21 PM
    I didn't use AllowUserResizing for reason. It's not used in 99% cases for games. Start example from GitHub and press CTRL-R, it will change resolution to 1920x1080.

    If you are creating application (not game) and you need AllowUserResizing, be sure to change back buffer sizes, apply changes on graphic device and then call resize method on your UI root instance.
    Вадим ПлетняковUser is Offline
    New Member
    New Member
    Posts:6


    --
    13 Jul 2016 01:03 PM
    What I'm trying to say, all this stuff with resolution does not work on my PC. When I press Ctrl-R, window changes to 1920*1080, but content turns to Cornflowerblue.
    I even made video https://youtu.be/hqaexl8fghk
    Filip DušekUser is Offline
    Advanced Member
    Advanced Member
    Posts:669


    --
    13 Jul 2016 01:12 PM
    If you are changing resolution by resizing window by mouse (AllowUserResizing is true) you have to manually change (in code) size of back buffer. MonoGame will not do it for you, see my previous post.

    No idea why CTRL-R is not working for you. It's standard implementation, so maybe some driver or another code issue.
    You are not authorized to post a reply.