protected override void UpdateDisplayMode() { Glfw.Monitor monitor = Glfw.GetWindowMonitor(_win); if (monitor.Ptr == IntPtr.Zero) { monitor = Glfw.GetPrimaryMonitor(); } Glfw.GetMonitorPos(monitor, out int mX, out int mY); Glfw.VideoMode vidMode = Glfw.GetVideoMode(monitor); switch (DisplayMode) { case DisplayMode.Fullscreen: // This is not actually borderless windowed :( Glfw.SetWindowMonitor(_win, monitor, 0, 0, vidMode.Width, vidMode.Height, vidMode.RefreshRate); break; case DisplayMode.Windowed: Vector2 size = _windowModeSize ?? GetSize(); _windowModeSize = null; Vector2 pos = new Vector2(mX, mY) + (new Vector2(vidMode.Width, vidMode.Height) / 2 - size / 2); Glfw.SetWindowMonitor(_win, new Glfw.Monitor(IntPtr.Zero), (int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y, Glfw.DontCare); break; } }
/// <summary> /// Sets the size of the window /// </summary> /// <param name="width">the width in pixels</param> /// <param name="height">the height in pixels</param> internal void SetSize(bool fullscreen, int width = 0, int height = 0) { // Get monitor settings Glfw.VideoMode mode = Glfw.GetVideoMode(monitor); if (fullscreen) { Glfw.SetWindowMonitor(window, monitor, 0, 0, mode.Width, mode.Height, mode.RefreshRate); } else { Glfw.SetWindowMonitor(window, Glfw.Monitor.None, 0, 0, width, height, Glfw.DontCare); } // Check and see if window should be specific size if (width == 0 || height == 0) { this.width = mode.Width; this.height = mode.Height; } else { this.width = width; this.height = height; } this.fullScreen = fullscreen; // Sets the window size and the position in center Glfw.SetWindowSize(window, this.width, this.height); Glfw.SetWindowPos(window, (mode.Width / 2) - this.width / 2, (mode.Height / 2) - this.height / 2); Debug.Log("Window Size: " + width + " " + height, Debug.DebugLayer.Application); }
static string FormatMode(Glfw.VideoMode mode) { return(string.Format("{0} x {1} x {2} ({3} {4} {5}) {6} Hz", mode.Width, mode.Height, mode.RedBits + mode.GreenBits + mode.BlueBits, mode.RedBits, mode.GreenBits, mode.BlueBits, mode.RefreshRate )); }
private GlfwMonitor(Glfw.Monitor handle) { Handle = handle; int i = 0; // - Name set Name = Glfw.GetMonitorName(handle); // - Position set Vector2i position; Glfw.GetMonitorPos(handle, out position.X, out position.Y); Position = position; // - Supported resolutions Glfw.VideoMode[] modes = Glfw.GetVideoModes(handle); Glfw.VideoMode current = Glfw.GetVideoMode(handle); supportedResolutions = new Resolution[modes.Length]; foreach (Glfw.VideoMode mode in modes) { Resolution r = new Resolution { ResolutionSize = new Vector2i(mode.Width, mode.Height), RefreshRate = mode.RefreshRate, RedBits = mode.RedBits, BlueBits = mode.BlueBits, GreenBits = mode.GreenBits }; supportedResolutions[i++] = r; if (current == mode) { CurrentResolution = r; } } }
protected override void SetupInternal(Configurator config) { bool initSuccess = Glfw.Init(); if (!initSuccess) { Engine.Log.Error("Couldn't initialize glfw.", MessageSource.Glfw); return; } _errorCallback = ErrorCallback; Glfw.SetErrorCallback(_errorCallback); #if ANGLE LoadLibrary("libEGL"); LoadLibrary("libGLESv2"); Glfw.WindowHint(Glfw.Hint.ClientApi, Glfw.ClientApi.OpenGLES); Glfw.WindowHint(Glfw.Hint.ContextCreationApi, Glfw.ContextApi.EGL); Glfw.WindowHint(Glfw.Hint.ContextVersionMajor, 3); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Kernel32Methods.GetModuleHandle("renderdoc.dll") != IntPtr.Zero) { Glfw.WindowHint(Glfw.Hint.ContextVersionMinor, 1); } #endif if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { // Macs need a very specific context to be requested. Glfw.WindowHint(Glfw.Hint.ContextVersionMajor, 3); Glfw.WindowHint(Glfw.Hint.ContextVersionMinor, 2); Glfw.WindowHint(Glfw.Hint.OpenglForwardCompat, true); Glfw.WindowHint(Glfw.Hint.OpenglProfile, Glfw.OpenGLProfile.Core); } else { // Version set by the angle ifdef shouldn't be overwritten. #if !ANGLE Glfw.WindowHint(Glfw.Hint.ContextVersionMajor, 3); Glfw.WindowHint(Glfw.Hint.ContextVersionMinor, 3); Glfw.WindowHint(Glfw.Hint.OpenglForwardCompat, true); Glfw.WindowHint(Glfw.Hint.OpenglProfile, Glfw.OpenGLProfile.Core); #endif } Glfw.Window?win = Glfw.CreateWindow((int)config.HostSize.X, (int)config.HostSize.Y, config.HostTitle); if (win == null || win.Value.Ptr == IntPtr.Zero) { Engine.Log.Error("Couldn't create window.", MessageSource.Glfw); return; } _win = win.Value; Glfw.SetWindowSizeLimits(_win, (int)config.RenderSize.X, (int)config.RenderSize.Y, -1, -1); _focusCallback = FocusCallback; Glfw.SetWindowFocusCallback(_win, _focusCallback); _resizeCallback = ResizeCallback; Glfw.SetFramebufferSizeCallback(_win, _resizeCallback); Context = new GlfwGraphicsContext(_win); Context.MakeCurrent(); _keyInputCallback = KeyInput; Glfw.SetKeyCallback(_win, _keyInputCallback); _mouseButtonFunc = MouseButtonKeyInput; Glfw.SetMouseButtonCallback(_win, _mouseButtonFunc); _mouseScrollFunc = MouseScrollInput; Glfw.SetScrollCallback(_win, _mouseScrollFunc); void TextInputRedirect(Glfw.Window _, uint codePoint) { UpdateTextInput((char)codePoint); } _textInputCallback = TextInputRedirect; Glfw.SetCharCallback(_win, _textInputCallback); Glfw.Monitor[] monitors = Glfw.GetMonitors(); for (var i = 0; i < monitors.Length; i++) { Glfw.GetMonitorPos(monitors[i], out int x, out int y); Glfw.VideoMode videoMode = Glfw.GetVideoMode(monitors[i]); var mon = new GlfwMonitor(new Vector2(x, y), new Vector2(videoMode.Width, videoMode.Height)); UpdateMonitor(mon, true, i == 0); } FocusChanged(true); Glfw.FocusWindow(_win); #if OpenAL Audio = OpenALAudioAdapter.TryCreate(this) ?? (AudioContext) new NullAudioContext(); #else Audio = new NullAudioContext(); #endif }