Exemplo n.º 1
0
        /// <summary>
        /// Queries GLFW to get the client area of the monitor.
        /// </summary>
        private unsafe void GetClientArea()
        {
            GLFW.GetMonitorPos(_handle, out int x, out int y);
            var videoMode = GLFW.GetVideoMode(_handle);

            ClientArea = new Rectangle(x, y, videoMode->Width, videoMode->Height);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            GameWindowSettings gameWinSettings = new GameWindowSettings();
            var nativeWindowSettings           = new NativeWindowSettings()
            {
                Size       = new Vector2i(800, 600),
                Title      = "Habi",
                APIVersion = new System.Version(4, 5),
                API        = ContextAPI.OpenGL,
                Flags      = ContextFlags.ForwardCompatible,
                Profile    = ContextProfile.Core,
            };

            int width, height, xpos, ypos;

            unsafe
            {
                var monitor = GLFW.GetPrimaryMonitor();
                var vidmode = GLFW.GetVideoMode(monitor);
                width  = vidmode->Width - 200;
                height = vidmode->Height - 100;
                xpos   = (vidmode->Width - width) / 2;
                ypos   = (vidmode->Height - height) / 2;
            }

            nativeWindowSettings.Size     = new Vector2i(width, height);
            nativeWindowSettings.Location = new Vector2i(xpos, ypos);

            using (var game = new Draw2DGame(gameWinSettings, nativeWindowSettings))
            {
                game.Run();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Queries GLFW to get the client area of the monitor.
        /// </summary>
        private unsafe void GetClientArea()
        {
            GLFW.GetMonitorPos(HandleAsPtr, out int x, out int y);
            var videoMode = GLFW.GetVideoMode(HandleAsPtr);

            ClientArea = new Box2i(x, y, x + videoMode->Width, y + videoMode->Height);
        }
Exemplo n.º 4
0
        private void InitWindow()
        {
            GLFW.WindowHint(WindowHintBool.SrgbCapable, true);
            GLFW.WindowHint(WindowHintInt.ContextVersionMajor, MinimumOpenGLVersion.Major);
            GLFW.WindowHint(WindowHintInt.ContextVersionMinor, MinimumOpenGLVersion.Minor);
            GLFW.WindowHint(WindowHintBool.OpenGLForwardCompat, true);
            GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core);
#if DEBUG
            GLFW.WindowHint(WindowHintBool.OpenGLDebugContext, true);
#endif
            GLFW.WindowHint(WindowHintString.X11ClassName, "SS14");
            GLFW.WindowHint(WindowHintString.X11InstanceName, "SS14");

            var width  = _configurationManager.GetCVar <int>("display.width");
            var height = _configurationManager.GetCVar <int>("display.height");

            Monitor *monitor = null;

            if (WindowMode == WindowMode.Fullscreen)
            {
                monitor = GLFW.GetPrimaryMonitor();
                var mode = GLFW.GetVideoMode(monitor);
                width  = mode->Width;
                height = mode->Height;
            }

            _glfwWindow = GLFW.CreateWindow(width, height, string.Empty, monitor, null);

            LoadWindowIcon();

            GLFW.SetCharCallback(_glfwWindow, _charCallback);
            GLFW.SetKeyCallback(_glfwWindow, _keyCallback);
            GLFW.SetWindowCloseCallback(_glfwWindow, _windowCloseCallback);
            GLFW.SetCursorPosCallback(_glfwWindow, _cursorPosCallback);
            GLFW.SetWindowSizeCallback(_glfwWindow, _windowSizeCallback);
            GLFW.SetScrollCallback(_glfwWindow, _scrollCallback);
            GLFW.SetMouseButtonCallback(_glfwWindow, _mouseButtonCallback);
            GLFW.SetWindowContentScaleCallback(_glfwWindow, _windowContentScaleCallback);

            GLFW.MakeContextCurrent(_glfwWindow);

            VSyncChanged();

            GLFW.GetFramebufferSize(_glfwWindow, out var fbW, out var fbH);
            _screenSize = (fbW, fbH);

            GLFW.GetWindowContentScale(_glfwWindow, out var scaleX, out var scaleY);
            _windowScale = (scaleX, scaleY);

            InitGLContext();

            // Initializing OTK 3 seems to mess with the current context, so ensure it's still set.
            // This took me f*****g *forever* to debug because this manifested differently on nvidia drivers vs intel mesa.
            // So I thought it was a calling convention issue with the calli OpenTK emits.
            // Because, in my tests, I had InitGLContext() AFTER the test with a delegate-based invoke of the proc.
            GLFW.MakeContextCurrent(_glfwWindow);

            InitOpenGL();
        }
Exemplo n.º 5
0
        private static void SetUpMonitorData()
        {
            ImGuiPlatformIOPtr platformIO = ImGui.GetPlatformIO();

            var platformMonitors = new List <ImGuiPlatformMonitor>();

            {
                Monitor *[] monitors = GLFW.GetMonitors();

                for (int i = 0; i < monitors.Length; i++)
                {
                    Monitor *            monitor = monitors[i];
                    ImGuiPlatformMonitor m       = new ImGuiPlatformMonitor();

                    var vidMode = GLFW.GetVideoMode(monitor);
                    GLFW.GetMonitorPos(monitor, out int x, out int y);
                    m.MainPos  = m.WorkPos = new Vector2(x, y);
                    m.MainSize = m.WorkSize = new Vector2(vidMode->Width, vidMode->Height);
                    GLFW.GetMonitorContentScale(monitor, out float xScale, out float yScale);
                    m.DpiScale = xScale;

                    platformMonitors.Add(m);
                }
            }

            _monitorData    = platformMonitors.ToArray();
            _monitorDataPin = GCHandle.Alloc(_monitorData, GCHandleType.Pinned);

            var platformMonitorsPtrs = new ImGuiPlatformMonitorPtr[_monitorData.Length];

            for (int i = 0; i < _monitorData.Length; i++)
            {
                fixed(ImGuiPlatformMonitor *ptr = &_monitorData[i])
                {
                    platformMonitorsPtrs[i] = new ImGuiPlatformMonitorPtr(ptr);
                }
            }

            _monitorPtrData    = platformMonitorsPtrs;
            _monitorPtrDataPin = GCHandle.Alloc(_monitorPtrData, GCHandleType.Pinned);
            _monitorsPtrVector = new ImVector <ImGuiPlatformMonitor>(_monitorPtrData.Length,
                                                                     _monitorPtrData.Length,
                                                                     _monitorDataPin.AddrOfPinnedObject());

            {
                ImGuiPlatformIO *ptr = platformIO;
                ImVector         v   = Unsafe.As <ImVector <ImGuiPlatformMonitor>, ImVector>(ref _monitorsPtrVector);
                ptr->Monitors = v;
            }
        }
Exemplo n.º 6
0
            private void WinThreadWinSetFullscreen(CmdWinSetFullscreen cmd)
            {
                var ptr = (Window *)cmd.Window;
                //GLFW.GetWindowSize(ptr, out var w, out var h);
                //GLFW.GetWindowPos(ptr, out var x, out var y);

                var monitor = MonitorForWindow(ptr);
                var mode    = GLFW.GetVideoMode(monitor);

                GLFW.SetWindowMonitor(
                    ptr,
                    monitor,
                    0, 0,
                    mode->Width, mode->Height,
                    mode->RefreshRate);
            }
Exemplo n.º 7
0
        protected override void WindowModeChanged()
        {
            if (_glfwWindow == null)
            {
                return;
            }

            if (WindowMode == WindowMode.Fullscreen)
            {
                var monitor = GLFW.GetPrimaryMonitor();
                var mode    = GLFW.GetVideoMode(monitor);
                GLFW.SetWindowMonitor(_glfwWindow, GLFW.GetPrimaryMonitor(), 0, 0, mode->Width, mode->Height,
                                      mode->RefreshRate);
            }
            else
            {
                GLFW.SetWindowMonitor(_glfwWindow, null, 0, 0, 1280, 720, 0);
            }
        }
Exemplo n.º 8
0
        public Window(GameWindowSettings settings1, NativeWindowSettings settings2) : base(settings1, settings2)
        {
            current       = this;
            CursorVisible = false;

            // Initialize values
            unsafe
            {
                var mode = GLFW.GetVideoMode(CurrentMonitor.ToUnsafePtr <Monitor>());
                ScreenInfo.ScreenWidth       = mode->Width;
                ScreenInfo.ScreenHeight      = mode->Height;
                ScreenInfo.ScreenRefreshRate = mode->RefreshRate;
            }

            setScreen();
            setVSync();

            timer = Timer.Start();
            timer.Stop();
        }
Exemplo n.º 9
0
        protected override unsafe void GetAvailableModes( )
        {
            var availableResolutions = GLFW.GetVideoModes(this.OpenTKDevice);
            var tmp = new List <VideoMode>(availableResolutions.Length);

            foreach (var res in availableResolutions)
            {
                if (res.RedBits + res.GreenBits + res.BlueBits <= 8)
                {
                    continue;
                }

                Predicate <VideoMode> SameMode = delegate(VideoMode m)
                {
                    return(m.Width == res.Width && m.Height == res.Height && m.BitsPerPixel == res.RedBits + res.GreenBits + res.BlueBits);
                };

                if (tmp.Exists(SameMode))
                {
                    continue;
                }

                var mode = new VideoMode( );
                mode.Width        = res.Width;
                mode.Height       = res.Height;
                mode.BitsPerPixel = res.RedBits + res.GreenBits + res.BlueBits;
                mode.RefreshRate  = res.RefreshRate;
                tmp.Add(mode);
            }

            this.AvailableModes = tmp.ToArray( );

            var current = *GLFW.GetVideoMode(this.OpenTKDevice);

            this.FirstAvailableMode              = new();
            this.FirstAvailableMode.Width        = current.Width;
            this.FirstAvailableMode.Height       = current.Height;
            this.FirstAvailableMode.BitsPerPixel = current.RedBits + current.GreenBits + current.BlueBits;
            this.FirstAvailableMode.RefreshRate  = current.RefreshRate;
            this.FirstAvailableMode.FullScreen   = true;
        }
Exemplo n.º 10
0
            // glfwGetWindowMonitor only works for fullscreen windows.
            // Picks the monitor with the top-left corner of the window.
            private Monitor *MonitorForWindow(Window *window)
            {
                GLFW.GetWindowPos(window, out var winPosX, out var winPosY);
                var monitors = GLFW.GetMonitorsRaw(out var count);

                for (var i = 0; i < count; i++)
                {
                    var monitor = monitors[i];
                    GLFW.GetMonitorPos(monitor, out var monPosX, out var monPosY);
                    var videoMode = GLFW.GetVideoMode(monitor);

                    var box = Box2i.FromDimensions(monPosX, monPosY, videoMode->Width, videoMode->Height);
                    if (box.Contains(winPosX, winPosY))
                    {
                        return(monitor);
                    }
                }

                // Fallback
                return(GLFW.GetPrimaryMonitor());
            }
Exemplo n.º 11
0
        /// <summary>
        /// Initialize the graph window. This calls a base constructor in OpenTK which handles window creation for us.
        /// </summary>
        public GraphWindow(GameWindowSettings gameSettings, NativeWindowSettings nativeSettings) : base(gameSettings, nativeSettings)
        {
            watch = new Stopwatch();

            // Initialize values
            int maxWidth, maxHeight;

            unsafe
            {
                var mode = GLFW.GetVideoMode(CurrentMonitor.ToUnsafePtr <Monitor>());
                maxWidth  = mode->Width;
                maxHeight = mode->Height;
            }

            if (Settings.GraphWidth > maxWidth)
            {
                Settings.GraphWidth = maxWidth;
            }
            if (Settings.GraphHeight > maxHeight)
            {
                Settings.GraphHeight = maxHeight;
            }
        }
Exemplo n.º 12
0
        public unsafe int setMode(Size dim, int mode, bool fullscreen)
        {
            var windowSize = new Size();

            VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\n");
            VID.Printf(Defines.PRINT_ALL, $"...setting mode {mode}:");

            if (this.oldDisplayMode == null)
            {
                GLFW.Init();
                var videoMode = GLFW.GetVideoMode(GLFW.GetPrimaryMonitor())[0];

                this.oldDisplayMode =
                    new(videoMode.Width, videoMode.Height, videoMode.RefreshRate, videoMode.RedBits + videoMode.GreenBits + videoMode.BlueBits);
            }

            if (!VID.GetModeInfo(ref windowSize, mode))
            {
                VID.Printf(Defines.PRINT_ALL, " invalid mode\n");

                return(Base.rserr_invalid_mode);
            }

            VID.Printf(Defines.PRINT_ALL, $" {windowSize.Width} {windowSize.Height}{'\n'}");

            if (this.window != null)
            {
                this.shutdown();
            }

            if (fullscreen)
            {
                var displayMode =
                    this.getModeList().FirstOrDefault(displayMode => displayMode.Width == windowSize.Width && displayMode.Height == windowSize.Height)
                    ?? this.oldDisplayMode;

                this.window = new(GameWindowSettings.Default, new()
                {
                    Profile = ContextProfile.Compatability, Size = new(displayMode.Width, displayMode.Height), IsFullscreen = true
                });

                VID.Printf(
                    Defines.PRINT_ALL,
                    $"...setting fullscreen {displayMode.Width}x{displayMode.Height}x{displayMode.BitDepth}@{displayMode.RefreshRate}Hz\n"
                    );
            }
            else
            {
                this.window = new(GameWindowSettings.Default, new()
                {
                    Profile = ContextProfile.Compatability, Size = new(windowSize.Width, windowSize.Height)
                });

                VID.Printf(Defines.PRINT_ALL, $"...setting window {windowSize.Width}x{windowSize.Height}\n");
            }

            this.window.Focus();
            this.window.Closed += OpenTkDriver.QuitOnClose;

            OpenTkKBD.Window        = this.window;
            this.window.KeyDown    += OpenTkKBD.Listener.KeyDown;
            this.window.KeyUp      += OpenTkKBD.Listener.KeyUp;
            this.window.MouseDown  += OpenTkKBD.Listener.MouseDown;
            this.window.MouseUp    += OpenTkKBD.Listener.MouseUp;
            this.window.MouseMove  += OpenTkKBD.Listener.MouseMove;
            this.window.MouseWheel += OpenTkKBD.Listener.MouseWheel;

            Program.UpdateLoop = _ => this.window.Run();

            var initialized = false;

            var updateAccumulator = 0.0;
            var renderAccumulator = 0.0;

            this.window.UpdateFrame += args =>
            {
                updateAccumulator += args.Time * 1000;

                var elapsed = (int)updateAccumulator;

                if (elapsed <= 0)
                {
                    return;
                }

                Qcommon.FrameUpdate(elapsed);
                updateAccumulator -= elapsed;
            };

            this.window.RenderFrame += args =>
            {
                if (!initialized)
                {
                    this.init(0, 0);
                    initialized = true;
                }

                renderAccumulator += args.Time * 1000;

                var elapsed = (int)renderAccumulator;

                if (elapsed <= 0)
                {
                    return;
                }

                Qcommon.FrameRender(elapsed);
                renderAccumulator -= elapsed;
            };

            this.window.Resize += args =>
            {
                Base.setVid(this.window.ClientSize.X, this.window.ClientSize.Y);
                VID.NewWindow(this.window.ClientSize.X, this.window.ClientSize.Y);
            };

            return(Base.rserr_ok);
        }
Exemplo n.º 13
0
        public virtual int SetMode(Size dim, int mode, bool fullscreen)
        {
            VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\\n");
            VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":");

            unsafe {
                Monitor *device = GLFW.GetPrimaryMonitor();
                if (oldDisplayMode == null)
                {
                    oldDisplayMode = GLFW.GetVideoMode(device)[0];
                }
            }

            if (!VID.GetModeInfo(out var newDim, mode))
            {
                VID.Printf(Defines.PRINT_ALL, " invalid mode\\n");
                return(Base.rserr_invalid_mode);
            }

            VID.Printf(Defines.PRINT_ALL, " " + newDim.Width + " " + newDim.Height + '\\');
            Shutdown();

            var newInstance = (window == null);

            if (!newInstance)
            {
                window.Dispose();
            }

            window = new GameWindow(new GameWindowSettings(), new NativeWindowSettings
            {
                Title        = "Q2Sharp (jogl)",
                Size         = new OpenTK.Mathematics.Vector2i(newDim.Width, newDim.Height),
                StartVisible = false,
                WindowBorder = OpenTK.Windowing.Common.WindowBorder.Fixed,
                IsFullscreen = false
                               //Icon = new OpenTK.Windowing.Common.Input.WindowIcon(new OpenTK.Windowing.Common.Input.Image(32,32,null)),
            });

            window.RenderFrame += (t) => Program.Frame();
            Program.RunWindow  += () => window.Run();

            //ImageIcon icon = new ImageIcon(GetType().GetResource("/icon-small.png"));
            Bitmap bitmap = (Bitmap)Bitmap.FromStream(GetType().Assembly.GetManifestResourceStream("/icon-small.png"));

            byte[] pixels = new byte[bitmap.Width * bitmap.Height];

            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    var color = bitmap.GetPixel(x, y);
                    Array.Copy(new byte[] { color.R, color.G, color.B, color.A }, 0, pixels, (y * bitmap.Width + x) * 4, 4);
                }
            }

            Image icon = new Image(bitmap.Width, bitmap.Height, pixels);

            window.Icon = new WindowIcon(icon);

            window.Minimized += (e) => JOGLKBD.listener.ComponentHidden(e);
            window.Maximized += (e) =>
            {
                JOGLKBD.c = window;
                JOGLKBD.listener.ComponentShown(e);
            };
            window.Move       += (e) => JOGLKBD.listener.ComponentMoved(e);
            window.Closing    += (e) => Cbuf.ExecuteText(Defines.EXEC_APPEND, "quit");
            window.Resize     += (e) => JOGLKBD.listener.ComponentResized(e);
            window.KeyDown    += (e) => JOGLKBD.listener.KeyPressed(e);
            window.KeyUp      += (e) => JOGLKBD.listener.KeyReleased(e);
            window.TextInput  += (e) => JOGLKBD.listener.KeyTyped(e);
            window.MouseEnter += () => JOGLKBD.listener.MouseEntered();
            window.MouseLeave += () => JOGLKBD.listener.MouseExited();
            window.MouseMove  += (e) => JOGLKBD.listener.MouseMoved(e);
            window.MouseDown  += (e) => JOGLKBD.listener.MousePressed(e);
            window.MouseUp    += (e) => JOGLKBD.listener.MouseReleased(e);
            window.MouseWheel += (e) => JOGLKBD.listener.MouseWheelMoved(e);
            //window.drag += ( e ) => JOGLKBD.listener.MouseDragged( e );

            if (fullscreen)
            {
                window.WindowState = OpenTK.Windowing.Common.WindowState.Fullscreen;
                VideoMode VideoMode = FindDisplayMode(newDim);
                newDim.Width       = VideoMode.Width;
                newDim.Height      = VideoMode.Height;
                window.WindowState = WindowState.Fullscreen;
                if (window.IsFullscreen)
                {
                    unsafe
                    {
                        GLFW.SetWindowSize(window.WindowPtr, VideoMode.Width, VideoMode.Height);
                    }
                }
                window.Location = new OpenTK.Mathematics.Vector2i();
                window.Size     = new OpenTK.Mathematics.Vector2i(VideoMode.Width, VideoMode.Height);
                VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " + GetModeString(VideoMode) + '\\');
                window.IsVisible = true;
            }
            else
            {
                window.Location  = new OpenTK.Mathematics.Vector2i(window_xpos, window_ypos);
                window.IsVisible = true;
            }

            Base.SetVid(newDim.Width, newDim.Height);
            VID.NewWindow(newDim.Width, newDim.Height);

            return(Base.rserr_ok);
        }
Exemplo n.º 14
0
            private Window *CreateGlfwWindowForRenderer(
                GLContextSpec?spec,
                WindowCreateParameters parameters,
                Window *contextShare,
                Window *ownerWindow)
            {
                GLFW.WindowHint(WindowHintString.X11ClassName, "RobustToolbox");
                GLFW.WindowHint(WindowHintString.X11InstanceName, "RobustToolbox");
                GLFW.WindowHint(WindowHintBool.ScaleToMonitor, true);

                if (spec == null)
                {
                    // No OpenGL context requested.
                    GLFW.WindowHint(WindowHintClientApi.ClientApi, ClientApi.NoApi);
                }
                else
                {
                    var s = spec.Value;

#if DEBUG
                    GLFW.WindowHint(WindowHintBool.OpenGLDebugContext, true);
#endif

                    GLFW.WindowHint(WindowHintInt.ContextVersionMajor, s.Major);
                    GLFW.WindowHint(WindowHintInt.ContextVersionMinor, s.Minor);
                    GLFW.WindowHint(WindowHintBool.OpenGLForwardCompat, s.Profile != GLContextProfile.Compatibility);
                    GLFW.WindowHint(WindowHintBool.SrgbCapable, true);

                    switch (s.Profile)
                    {
                    case GLContextProfile.Compatibility:
                        GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Any);
                        GLFW.WindowHint(WindowHintClientApi.ClientApi, ClientApi.OpenGlApi);
                        break;

                    case GLContextProfile.Core:
                        GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core);
                        GLFW.WindowHint(WindowHintClientApi.ClientApi, ClientApi.OpenGlApi);
                        break;

                    case GLContextProfile.Es:
                        GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Any);
                        GLFW.WindowHint(WindowHintClientApi.ClientApi, ClientApi.OpenGlEsApi);
                        break;
                    }

                    GLFW.WindowHint(WindowHintContextApi.ContextCreationApi,
                                    s.CreationApi == GLContextCreationApi.Egl
                            ? ContextApi.EglContextApi
                            : ContextApi.NativeContextApi);

#if !FULL_RELEASE
                    if (s.CreationApi == GLContextCreationApi.Egl && !_eglLoaded && OperatingSystem.IsWindows())
                    {
                        // On non-published builds (so, development), GLFW can't find libEGL.dll
                        // because it'll be in runtimes/<rid>/native/ instead of next to the actual executable.
                        // We manually preload the library here so that GLFW will find it when it does its thing.
                        NativeLibrary.TryLoad(
                            "libEGL.dll",
                            typeof(Clyde).Assembly,
                            DllImportSearchPath.SafeDirectories,
                            out _);

                        _eglLoaded = true;
                    }
#endif
                }

                Monitor *monitor = null;
                if (parameters.Monitor != null &&
                    _winThreadMonitors.TryGetValue(parameters.Monitor.Id, out var monitorReg))
                {
                    monitor = monitorReg.Ptr;
                    var mode = GLFW.GetVideoMode(monitor);
                    // Set refresh rate to monitor's so that GLFW doesn't manually select one.
                    GLFW.WindowHint(WindowHintInt.RefreshRate, mode->RefreshRate);
                }
                else
                {
                    GLFW.WindowHint(WindowHintInt.RefreshRate, -1);
                }

                GLFW.WindowHint(WindowHintBool.Visible, false);

                GLFW.WindowHint(WindowHintInt.RedBits, 8);
                GLFW.WindowHint(WindowHintInt.GreenBits, 8);
                GLFW.WindowHint(WindowHintInt.BlueBits, 8);
                GLFW.WindowHint(WindowHintInt.AlphaBits, 8);
                GLFW.WindowHint(WindowHintInt.StencilBits, 8);

                var window = GLFW.CreateWindow(
                    parameters.Width, parameters.Height,
                    parameters.Title,
                    parameters.Fullscreen ? monitor : null,
                    contextShare);

                // Check if window failed to create.
                if (window == null)
                {
                    return(null);
                }

                if (parameters.Maximized)
                {
                    GLFW.GetMonitorPos(monitor, out var x, out var y);
                    GLFW.SetWindowPos(window, x, y);
                    GLFW.MaximizeWindow(window);
                }

                if ((parameters.Styles & OSWindowStyles.NoTitleOptions) != 0)
                {
                    if (OperatingSystem.IsWindows())
                    {
                        var hWnd = (HWND)GLFW.GetWin32Window(window);
                        DebugTools.Assert(hWnd != HWND.NULL);

                        Windows.SetWindowLongPtrW(
                            hWnd,
                            GWL.GWL_STYLE,
                            // Cast to long here to work around a bug in rider with nint bitwise operators.
                            (nint)((long)Windows.GetWindowLongPtrW(hWnd, GWL.GWL_STYLE) & ~WS.WS_SYSMENU));
                    }
                    else
                    {
                        _sawmill.Warning("OSWindowStyles.NoTitleOptions not implemented on this platform");
                    }
                }

                if (ownerWindow != null)
                {
                    if (OperatingSystem.IsWindows())
                    {
                        var hWnd      = (HWND)GLFW.GetWin32Window(window);
                        var ownerHWnd = (HWND)GLFW.GetWin32Window(ownerWindow);
                        DebugTools.Assert(hWnd != HWND.NULL);

                        Windows.SetWindowLongPtrW(
                            hWnd,
                            GWLP.GWLP_HWNDPARENT,
                            ownerHWnd);
                    }
                    else
                    {
                        _sawmill.Warning("owner windows not implemented on this platform");
                    }


                    if (parameters.StartupLocation == WindowStartupLocation.CenterOwner)
                    {
                        // TODO: Maybe include window frames in size calculations here?
                        // Figure out frame sizes of both windows.
                        GLFW.GetWindowPos(ownerWindow, out var ownerX, out var ownerY);
                        GLFW.GetWindowSize(ownerWindow, out var ownerW, out var ownerH);

                        // Re-fetch this in case DPI scaling is changing it I guess.
                        GLFW.GetWindowSize(window, out var thisW, out var thisH);

                        GLFW.SetWindowPos(window, ownerX + (ownerW - thisW) / 2, ownerY + (ownerH - thisH) / 2);
                    }
                }

                if (parameters.Visible)
                {
                    GLFW.ShowWindow(window);
                }

                return(window);
            }