diff --git a/src/AcDream.App/Program.cs b/src/AcDream.App/Program.cs index f7c3234..dae3ff3 100644 --- a/src/AcDream.App/Program.cs +++ b/src/AcDream.App/Program.cs @@ -1,3 +1,5 @@ -// src/AcDream.App/Program.cs -Console.WriteLine("acdream app — phase 1 skeleton"); +using AcDream.App.Rendering; + +var window = new GameWindow(); +window.Run(); return 0; diff --git a/src/AcDream.App/Rendering/GameWindow.cs b/src/AcDream.App/Rendering/GameWindow.cs new file mode 100644 index 0000000..9a52fb5 --- /dev/null +++ b/src/AcDream.App/Rendering/GameWindow.cs @@ -0,0 +1,62 @@ +using Silk.NET.Input; +using Silk.NET.Maths; +using Silk.NET.OpenGL; +using Silk.NET.Windowing; + +namespace AcDream.App.Rendering; + +public sealed class GameWindow : IDisposable +{ + private IWindow? _window; + private GL? _gl; + private IInputContext? _input; + + public void Run() + { + var options = WindowOptions.Default with + { + Size = new Vector2D(1280, 720), + Title = "acdream — phase 1", + API = new GraphicsAPI( + ContextAPI.OpenGL, + ContextProfile.Core, + ContextFlags.ForwardCompatible, + new APIVersion(4, 3)), + VSync = true, + }; + + _window = Window.Create(options); + _window.Load += OnLoad; + _window.Render += OnRender; + _window.Closing += OnClosing; + + _window.Run(); + } + + private void OnLoad() + { + _gl = GL.GetApi(_window!); + _input = _window!.CreateInput(); + foreach (var kb in _input.Keyboards) + kb.KeyDown += (_, key, _) => + { + if (key == Key.Escape) + _window!.Close(); + }; + + _gl.ClearColor(0.05f, 0.10f, 0.18f, 1.0f); + } + + private void OnRender(double deltaSeconds) + { + _gl!.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); + } + + private void OnClosing() + { + _input?.Dispose(); + _gl?.Dispose(); + } + + public void Dispose() => _window?.Dispose(); +}