brutal/samples/Hello/HelloGlfw.cs
Rian Drake c4c62f5528
samples: bump every package pin to the latest release (#39)
Fixes #38

Co-authored-by: LesoDeVaren <268139647+LesoDeVaren@users.noreply.github.com>
2026-11-12 14:15:04 +13:00

49 lines
1,023 B
C#

/*
* HelloGlfw
*
* Opens an empty GLFW window with no graphics API. Press Escape to close it.
*/
#:package Ahwoo.Brutal.Glfw@2026.10.5
#:package Ahwoo.Brutal.Numerics@2026.10.2
using Brutal.GlfwApi;
using Brutal.Numerics;
if (!Glfw.Init())
{
var errorCode = Glfw.GetError(out var errorMessage);
throw new InvalidOperationException($"Failed to initialize GLFW: {errorCode}, {errorMessage}");
}
try
{
Run();
}
finally
{
Glfw.Terminate();
}
static void Run()
{
// Destroyed when Run returns, before GLFW is terminated.
using var window = Glfw.CreateWindow(
new GlfwWindow.CreateInfo
{
Title = "Hello Glfw",
Size = new int2(640, 480),
Monitor = GlfwMonitor.Null, // Windowed mode.
Share = null, // No shared context.
}
);
window.OnKey += (handle, key, _, _, _) =>
{
if (key == GlfwKey.Escape)
handle.ShouldClose = true;
};
while (!window.ShouldClose)
Glfw.PollEvents();
}