public Window(WindowConfig config) { _config = config; var opts = WindowOptions.DefaultVulkan; opts.WindowBorder = WindowBorder.Resizable; opts.Size = new Silk.NET.Maths.Vector2D <int>((int)config.Width, (int)config.Height); opts.Title = config.Title; opts.WindowState = config.Fullscreen ? WindowState.Fullscreen : WindowState.Normal; _window = Silk.NET.Windowing.Window.Create(opts); _window.Render += (time) => DrawFrame?.Invoke(time); _window.Initialize(); _input = _window.CreateInput(); var primaryKeyboard = _input.Keyboards.FirstOrDefault(); if (primaryKeyboard != null) { primaryKeyboard.KeyDown += (keyboard, key, code) => OnKeyDown?.Invoke(key); primaryKeyboard.KeyUp += (keyboard, key, code) => OnKeyUp?.Invoke(key); } for (int i = 0; i < _input.Mice.Count; i++) { _input.Mice[i].Cursor.CursorMode = config.CursorDisabled ? CursorMode.Disabled : CursorMode.Normal; _input.Mice[i].MouseMove += (mouse, pos) => OnCursorPosition?.Invoke(pos.X, pos.Y); _input.Mice[i].Scroll += (mouse, wheel) => OnScroll?.Invoke(wheel.X, wheel.Y); _input.Mice[i].MouseDown += (mouse, button) => OnMouseDown?.Invoke(button); _input.Mice[i].MouseUp += (mouse, button) => OnMouseUp?.Invoke(button); } }
private void InitRenderer() { bool second = _renderer != null; if (_window != null) { _window.DrawFrame -= DrawFrame; _window.OnKeyDown -= OnKeyDown; _window.OnKeyUp -= OnKeyUp; _window.OnCursorPosition -= OnCursorPosition; _window.OnMouseDown -= OnMouseButtonDown; _window.OnMouseUp -= OnMouseButtonUp; _window.OnScroll -= OnScroll; _window.Close(); _window.Dispose(); } _renderer?.Dispose(); var windowConfig = new WindowConfig() { Title = "Ray Tracing in Dot Net", Width = _options.Width, Height = _options.Height, CursorDisabled = false, Fullscreen = _userSettings.Fullscreen, Resizable = !_userSettings.Fullscreen, }; _window = new Window(windowConfig); _scene = Scenes.MetaData[_userSettings.SceneIndex].Instantiate(); // Select the renderer to use _renderer = new VulkanRenderer(_userSettings, _window, _scene, _cameraInitialState, _logger, _options.DebugLogging); _renderer.DrawGui += () => { //ImGuiNET.ImGui.ShowStyleEditor(); //ImGuiNET.ImGui.ShowDemoWindow(); //ImGuiNET.ImGui.ShowFontSelector("Font"); //ImGuiNET.ImGui.ShowMetricsWindow(); //ImGuiNET.ImGui.ShowStyleSelector("Style"); //ImGuiNET.ImGui.ShowUserGuide(); DrawSettings(); DrawOverlay(); }; _window.DrawFrame += DrawFrame; _window.OnKeyDown += OnKeyDown; _window.OnKeyUp += OnKeyUp; _window.OnCursorPosition += OnCursorPosition; _window.OnMouseDown += OnMouseButtonDown; _window.OnMouseUp += OnMouseButtonUp; _window.OnScroll += OnScroll; _window.Run(); }