mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 12:38:24 +01:00
Add samples/, a collection of single-file .NET 10 apps run with `dotnet run <file>.cs`. Hello/ has one minimal sample per package that has a public API, many of them headless; Demo/ has fuller programs that combine packages into a more interesting application. samples/README.md indexes every sample and covers the layout, error handling and per-OS requirements.
49 lines
1,023 B
C#
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.4
|
|
#:package Ahwoo.Brutal.Numerics@2026.10.1
|
|
|
|
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();
|
|
}
|