protected override void WindowModeChanged() { if (_glfwWindow == null) { return; } if (WindowMode == WindowMode.Fullscreen) { GLFW.GetWindowSize(_glfwWindow, out var w, out var h); _prevWindowSize = (w, h); GLFW.GetWindowPos(_glfwWindow, out var x, out var y); _prevWindowPos = (x, y); 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, _prevWindowPos.X, _prevWindowPos.Y, _prevWindowSize.X, _prevWindowSize.Y, 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.SetWindowIconifyCallback(_glfwWindow, _windowIconifyCallback); GLFW.MakeContextCurrent(_glfwWindow); VSyncChanged(); GLFW.GetFramebufferSize(_glfwWindow, out var fbW, out var fbH); _framebufferSize = (fbW, fbH); UpdateWindowLoadedRtSize(); GLFW.GetWindowContentScale(_glfwWindow, out var scaleX, out var scaleY); _windowScale = (scaleX, scaleY); GLFW.GetWindowSize(_glfwWindow, out var w, out var h); _prevWindowSize = _windowSize = (w, h); GLFW.GetWindowPos(_glfwWindow, out var x, out var y); _prevWindowPos = (x, y); _pixelRatio = _framebufferSize / _windowSize; 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(); }
private bool InitWindow() { 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; } #if DEBUG GLFW.WindowHint(WindowHintBool.OpenGLDebugContext, true); #endif GLFW.WindowHint(WindowHintString.X11ClassName, "SS14"); GLFW.WindowHint(WindowHintString.X11InstanceName, "SS14"); GLFW.WindowHint(WindowHintBool.SrgbCapable, true); var renderer = (Renderer)_configurationManager.GetCVar <int>("display.renderer"); if (renderer == Renderer.Default) { // Try OpenGL Core 3.3 GLFW.WindowHint(WindowHintInt.ContextVersionMajor, 3); GLFW.WindowHint(WindowHintInt.ContextVersionMinor, 3); GLFW.WindowHint(WindowHintBool.OpenGLForwardCompat, true); GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core); _glfwWindow = GLFW.CreateWindow(width, height, string.Empty, monitor, null); if (_glfwWindow == null) { // Window failed to init due to error. var err = GLFW.GetErrorRaw(out _); if (err == ErrorCode.VersionUnavailable) { Logger.DebugS("clyde.win", "OpenGL Core 3.3 unsupported, trying OpenGL 3.1"); CreateWindowGl31(); } } } else if (renderer == Renderer.OpenGL31) { CreateWindowGl31(); } if (_glfwWindow == null) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { var code = GLFW.GetError(out string desc); var errorContent = "Failed to create the game window. " + "This probably means your GPU is too old to play the game. " + "That or update your graphic drivers\n" + $"The exact error is: [{code}]\n {desc}"; MessageBoxW(null, errorContent, "Space Station 14: Failed to create window", MB_OK | MB_ICONERROR); } Logger.FatalS("clyde.win", "Failed to create GLFW window! " + "This probably means your GPU is too old to run the game. " + "That or update your graphics drivers."); return(false); } 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.SetWindowIconifyCallback(_glfwWindow, _windowIconifyCallback); GLFW.MakeContextCurrent(_glfwWindow); VSyncChanged(); GLFW.GetFramebufferSize(_glfwWindow, out var fbW, out var fbH); _framebufferSize = (fbW, fbH); UpdateWindowLoadedRtSize(); GLFW.GetWindowContentScale(_glfwWindow, out var scaleX, out var scaleY); _windowScale = (scaleX, scaleY); GLFW.GetWindowSize(_glfwWindow, out var w, out var h); _prevWindowSize = _windowSize = (w, h); GLFW.GetWindowPos(_glfwWindow, out var x, out var y); _prevWindowPos = (x, y); _pixelRatio = _framebufferSize / _windowSize; 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(); return(true); void CreateWindowGl31() { GLFW.WindowHint(WindowHintInt.ContextVersionMajor, 3); GLFW.WindowHint(WindowHintInt.ContextVersionMinor, 1); GLFW.WindowHint(WindowHintBool.OpenGLForwardCompat, false); GLFW.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Any); _glfwWindow = GLFW.CreateWindow(width, height, string.Empty, monitor, null); } }