public void Initialize() { _pMonitor = (Monitor *)Marshal.AllocHGlobal(sizeof(Monitor)); Interop.Kernel32.InitializeCriticalSection(&_pMonitor->_criticalSection); Interop.Kernel32.InitializeConditionVariable(&_pMonitor->_conditionVariable); }
private bool InitWindow() { var width = _configurationManager.GetCVar(CVars.DisplayWidth); var height = _configurationManager.GetCVar(CVars.DisplayHeight); 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"); var renderer = (Renderer)_configurationManager.GetCVar <int>(CVars.DisplayRenderer); Span <Renderer> renderers = (renderer == Renderer.Default) ? stackalloc Renderer[] { Renderer.OpenGL33, Renderer.OpenGL31, Renderer.OpenGLES2 } : stackalloc Renderer[] { renderer };
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(); }
private void OnGlfwMonitor(Monitor *monitor, ConnectedState state) { if (state == ConnectedState.Connected) { WinThreadSetupMonitor(monitor); } else { WinThreadDestroyMonitor(monitor); } }
private void DisposeCore() { if (_pMonitor == null) { return; } Interop.Kernel32.DeleteCriticalSection(&_pMonitor->_criticalSection); Marshal.FreeHGlobal((IntPtr)_pMonitor); _pMonitor = null; }
/// <summary> /// Gets the raw dpi of the monitor pointed to. /// </summary> /// <param name="monitor">The monitor in question.</param> /// <param name="horizontalDpi">Horizontal dpi.</param> /// <param name="verticalDpi">Vertical dpi.</param> /// <returns><c>true</c>, if monitor's raw dpi was gotten correctly, <c>false</c> otherwise.</returns> /// <remarks> /// This method calculates dpi by retrieving monitor dimensions and resolution. /// However on certain platforms (such as Windows) these values may not /// be scaled correctly. /// </remarks> public static unsafe bool TryGetMonitorDpiRaw(Monitor *monitor, out float horizontalDpi, out float verticalDpi) { if (TryGetFromCache((IntPtr)monitor, out var info)) { horizontalDpi = info.HorizontalRawDpi; verticalDpi = info.VerticalRawDpi; return(true); } horizontalDpi = verticalDpi = GetPlatformDefaultDpi(); return(false); }
public static Monitor[] GetMonitors(out int count) { int lenght; Monitor *monitors = Imports.glfwGetMonitors(out lenght); Monitor[] result = new Monitor[lenght]; for (int i = 0; i < lenght; i++) { result[i] = monitors[i]; } count = lenght; return(result); }
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; } }
/// <summary> /// Gets the current monitor scale. /// </summary> /// <param name="monitor">The monitor in question.</param> /// <param name="horizontalScale">Horizontal scale.</param> /// <param name="verticalScale">Vertical scale.</param> /// <returns><c>true</c>, if current monitor scale was gotten correctly, <c>false</c> otherwise.</returns> public static unsafe bool TryGetMonitorScale( Monitor *monitor, out float horizontalScale, out float verticalScale ) { if (TryGetFromCache((IntPtr)monitor, out var info)) { horizontalScale = info.HorizontalScale; verticalScale = info.VerticalScale; return(true); } horizontalScale = 1f; verticalScale = 1f; return(false); }
/// <summary> /// Initializes a new instance of the <see cref="DpiInfo"/> class. /// </summary> /// <remarks> /// <paramref pref="handle"/> must be a valid pointer to a monitor. /// </remarks> /// <param name="handle">An opaque handle to a monitor.</param> public DpiInfo(Monitor *handle) { if (!GLFWProvider.IsOnMainThread) { throw new NotSupportedException("Only the GLFW thread can construct this object."); } if (handle == null) { throw new ArgumentNullException(nameof(handle)); } _handle = handle; GetClientArea(); GetPhysicalSize(); GetScale(); // DO NOT call these methods before the above Get* methods. CalculateMonitorDpi(); CalculateMonitorRawDpi(); }
public static extern void glfwSetGamma(Monitor *monitor, float gamma);
public static extern void *glfwGetMonitorUserPointer(Monitor *monitor);
public static extern VideoMode *glfwGetVideoModes(Monitor *monitor, int *count);
public static extern byte *glfwGetMonitorName(Monitor *monitor);
public static extern void glfwSetMonitorUserPointer(Monitor *monitor, void *pointer);
/// <inheritdoc /> public abstract unsafe string GetMonitorName(Monitor *monitor);
/// <inheritdoc /> public abstract unsafe GammaRamp *GetGammaRamp(Monitor *monitor);
public static extern void glfwSetWindowMonitor(Window *window, Monitor *monitor, int x, int y, int width, int height, int refreshRate);
public static extern void glfwGetMonitorPos(Monitor *monitor, int *x, int *y);
/// <inheritdoc /> public abstract unsafe void SetMonitorUserPointer(Monitor *monitor, IntPtr pointer);
public static extern VideoMode *glfwGetVideoMode(Monitor *monitor);
/// <inheritdoc /> public abstract unsafe IntPtr GetMonitorUserPointer(Monitor *monitor);
/// <inheritdoc /> public abstract unsafe VideoMode *GetVideoModes(Monitor *monitor, out int count);
private static unsafe void DpiMonitorCallback(Monitor *monitor, ConnectedState state) { // Normally, adding or removing from the cache would be nice, but this breaks // getting the info from an index, thus the cache must be built from scratch. BuildMonitorCache(); }
public static extern GammaRamp *glfwGetGammaRamp(Monitor *monitor);
public static extern void glfwGetMonitorPhysicalSize(Monitor *monitor, int *width, int *height);
public static extern void glfwSetGammaRamp(Monitor *monitor, GammaRamp *ramp);
public static extern void glfwGetMonitorContentScale(Monitor *monitor, float *xscale, float *yscale);
public static extern Window *glfwCreateWindow(int width, int height, byte *title, Monitor *monitor, Window *share);
/// <inheritdoc /> public abstract unsafe void SetGamma(Monitor *monitor, float gamma);