How set the window size on startup (code only)

how does one set the (OS) window size/clientRect in an code only environment at startup?

what i tried, but didnt work:

  1. setting PreferredBackBufferWidth/Height of Game.GraphicsDeviceManager
  2. setting Game.Window.PreferredWindowedSize in the OnWindowCreatedEvent
    (in that event i can set the position of the window but the preferred size is ignored)
  3. both (1 & 2) :slight_smile:
1 Like

In StartupScript try this:

var game = (Game)Game; game.IsFixedTimeStep = true; game.GraphicsDeviceManager.PreferredBackBufferWidth = 1920; game.GraphicsDeviceManager.PreferredBackBufferHeight = 1080; game.GraphicsDeviceManager.IsFullScreen = true; game.GraphicsDeviceManager.ApplyChanges();

Hi thanks for your answer!
that was the method i tried in point 1.
but it didnt work, now i know why :slight_smile:

when creating the game device i tried to use feature level GraphicsProfile.Level_11_2.
this only worked with using AutoLoadDefaultSettings = true
but this somehow prevents the usage of my preferred settings.
using AutoLoadDefaultSettings = false now let me set the size

example:

            strideGameInstance = new CustomGameClass
            {
                GraphicsDeviceManager =
                {
                    PreferredGraphicsProfile = new[] {GraphicsProfile.Level_11_1},
                    PreferredBackBufferWidth = OsWindow.ClientRectSize.X,
                    PreferredBackBufferHeight = OsWindow.ClientRectSize.Y
                    
                },
                AutoLoadDefaultSettings = false
                
            };

then one can set the windowsize by adding an event to Game.WindowCreated:

strideGame.WindowCreated += OnStrideEngineGameWindowCreated;

like this:

    private void OnStrideEngineGameWindowCreated(object sender, EventArgs e)
    {
        strideGame.Window.Title = OsWindow.Title;
        strideGame.Window.Position = new Int2(OsWindow.Position.X, OsWindow.Position.Y);

    }

strideGame is the stride game class β€œGame”.