static Glfw.Window OpenWindow(int width, int height, Glfw.Monitor monitor) { double b; Glfw.Window window; b = Glfw.GetTime(); window = Glfw.CreateWindow(width, height, "Window Re-opener", monitor, Glfw.Window.None); if (!window) { return(Glfw.Window.None); } Glfw.MakeContextCurrent(window); Glfw.SwapInterval(1); Glfw.SetFramebufferSizeCallback(window, FramebufferSizeCallback); Glfw.SetWindowCloseCallback(window, WindowCloseCallback); Glfw.SetKeyCallback(window, KeyCallback); if (monitor) { Log("Opening full screen window on monitor {0} took {1} seconds", Glfw.GetMonitorName(monitor), Glfw.GetTime() - b); } else { Log("Opening regular window took {0} seconds", Glfw.GetTime() - b); } return(window); }
static void ListModes(Glfw.Monitor monitor) { int x, y, widthMM, heightMM; var mode = Glfw.GetVideoMode(monitor); var modes = Glfw.GetVideoModes(monitor); Glfw.GetMonitorPos(monitor, out x, out y); Glfw.GetMonitorPhysicalSize(monitor, out widthMM, out heightMM); Log("Name: {0} ({1})", Glfw.GetMonitorName(monitor), Glfw.GetPrimaryMonitor() == monitor ? "primary" : "secondary"); Log("Current mode: {0}", FormatMode(mode)); Log("Virtual position: {0} {1}", x, y); Log("Physical size: {0} x {1} mm ({2} dpi)", widthMM, heightMM, mode.Width * 25.4f / widthMM); Log("Modes:"); for (int i = 0; i < modes.Length; i++) { string currentMode = modes[i] == mode ? "(current mode)" : ""; Log("{0}: {1} {2}", i, FormatMode(modes[i]), currentMode); } }
static void MonitorCallback(Glfw.Monitor monitor, Glfw.ConnectionEvent evt) { if (evt == Glfw.ConnectionEvent.Connected) { int x, y, widthMM, heightMM; var mode = Glfw.GetVideoMode(monitor); Glfw.GetMonitorPos(monitor, out x, out y); Glfw.GetMonitorPhysicalSize(monitor, out widthMM, out heightMM); Log("{0} at {1}: Monitor {2} ({3}x{4} at {5}x{6}, {7}x{8} mm) was connected", m_Counter++, Glfw.GetTime(), Glfw.GetMonitorName(monitor), mode.Width, mode.Height, x, y, widthMM, heightMM); } else if (evt == Glfw.ConnectionEvent.Disconnected) { Log("{0} at {1}: Monitor {2} was disconnected", m_Counter++, Glfw.GetTime(), Glfw.GetMonitorName(monitor)); } }
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; } } }
static void TestModes(Glfw.Monitor monitor) { Glfw.Window window; var modes = Glfw.GetVideoModes(monitor); for (int i = 0; i < modes.Length; i++) { var mode = modes[i]; Glfw.VideoMode current; Glfw.WindowHint(Glfw.Hint.RedBits, mode.RedBits); Glfw.WindowHint(Glfw.Hint.GreenBits, mode.GreenBits); Glfw.WindowHint(Glfw.Hint.BlueBits, mode.BlueBits); Glfw.WindowHint(Glfw.Hint.RefreshRate, mode.RefreshRate); Log("Testing mode {0} on monitor {1}: {2}", i, Glfw.GetMonitorName(monitor), FormatMode(mode)); window = Glfw.CreateWindow(mode.Width, mode.Height, "Video Mode Test", Glfw.GetPrimaryMonitor(), Glfw.Window.None); if (!window) { Log("Failed to enter mode {0}: {1}", i, FormatMode(mode)); continue; } Glfw.SetFramebufferSizeCallback(window, FramebufferSizeCallback); Glfw.SetKeyCallback(window, KeyCallback); Glfw.MakeContextCurrent(window); Glfw.SwapInterval(1); Glfw.SetTime(0.0); while (Glfw.GetTime() < 5.0) { Gl.Clear(ClearBufferMask.ColorBufferBit); Glfw.SwapBuffers(window); Glfw.PollEvents(); if (Glfw.WindowShouldClose(window)) { Log("User terminated program"); Glfw.Terminate(); Environment.Exit(0); } } Gl.Get(GetPName.RedBits, out current.RedBits); Gl.Get(GetPName.GreenBits, out current.GreenBits); Gl.Get(GetPName.BlueBits, out current.BlueBits); Glfw.GetWindowSize(window, out current.Width, out current.Height); if (current.RedBits != mode.RedBits || current.GreenBits != mode.GreenBits || current.BlueBits != mode.BlueBits) { Log("*** Color bit mismatch: ({0} {1} {2}) instead of ({3} {4} {5})\n", current.RedBits, current.GreenBits, current.BlueBits, mode.RedBits, mode.GreenBits, mode.BlueBits); } if (current.Width != mode.Width || current.Height != mode.Height) { Log("*** Size mismatch: %ix%i instead of %ix%i\n", current.Width, current.Height, mode.Width, mode.Height); } Log("Closing window"); Glfw.DestroyWindow(window); Glfw.PollEvents(); } }
static void Main(string[] args) { Init(); var monitor = Glfw.Monitor.None; int width, height, count = 1; if (!Glfw.Init()) { Environment.Exit(1); } Log("Library initialized"); Glfw.SetMonitorCallback(MonitorCallback); Glfw.SetJoystickCallback(JoystickCallback); var options = new Options(); if (Parser.Default.ParseArguments(args, options)) { if (options.Fullscreen) { Glfw.GetPrimaryMonitor(); } else { count = options.WindowCount; } } if (monitor) { var mode = Glfw.GetVideoMode(monitor); Glfw.WindowHint(Glfw.Hint.RefreshRate, mode.RefreshRate); Glfw.WindowHint(Glfw.Hint.RedBits, mode.RedBits); Glfw.WindowHint(Glfw.Hint.GreenBits, mode.GreenBits); Glfw.WindowHint(Glfw.Hint.BlueBits, mode.BlueBits); width = mode.Width; height = mode.Height; } else { width = 640; height = 480; } if (count <= 0) { Log("Invalid user"); Environment.Exit(1); } m_Slots = new Dictionary <Glfw.Window, Slot>(count); for (int i = 0; i < count; i++) { var slot = new Slot(); slot.Closeable = true; slot.Number = i + 1; string title = string.Format("Event Linter (Window {0})", slot.Number); if (monitor) { Log("Creating full screen window {0} ({1}x{2} on {3})\n", slot.Number, width, height, Glfw.GetMonitorName(monitor)); } else { Log("Creating windowed mode window {0} ({1}x{2})\n", slot.Number, width, height); } slot.window = Glfw.CreateWindow(width, height, title, monitor, Glfw.Window.None); if (!slot.window) { Glfw.Terminate(); Environment.Exit(1); } m_Slots.Add(slot.window, slot); Glfw.SetWindowPosCallback(slot.window, WindowPosCallback); Glfw.SetWindowSizeCallback(slot.window, WindowSizeCallback); Glfw.SetFramebufferSizeCallback(slot.window, FramebufferSizeCallback); Glfw.SetWindowCloseCallback(slot.window, WindowCloseCallback); Glfw.SetWindowRefreshCallback(slot.window, WindowRefreshCallback); Glfw.SetWindowFocusCallback(slot.window, WindowFocusCallback); Glfw.SetWindowIconifyCallback(slot.window, WindowIconifyCallback); Glfw.SetMouseButtonCallback(slot.window, MouseButtonCallback); Glfw.SetCursorPosCallback(slot.window, CursorPositionCallback); Glfw.SetCursorEnterCallback(slot.window, CursorEnterCallback); Glfw.SetScrollCallback(slot.window, ScrollCallback); Glfw.SetKeyCallback(slot.window, KeyCallback); Glfw.SetCharCallback(slot.window, CharCallback); Glfw.SetCharModsCallback(slot.window, CharModsCallback); Glfw.SetDropCallback(slot.window, DropCallback); Glfw.MakeContextCurrent(slot.window); Glfw.SwapInterval(1); } Log("Main loop starting"); for (;;) { int i = 0; foreach (var slot in m_Slots.Values) { i++; if (Glfw.WindowShouldClose(slot.window)) { break; } } if (i < count) { break; } Glfw.WaitEvents(); } Glfw.Terminate(); }