mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 12:38:24 +01:00
samples: add Hello/Demo samples for most BRUTAL packages
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.
This commit is contained in:
parent
a25cdf80b2
commit
b0c9fd9cdc
1 changed files with 4599 additions and 1 deletions
49
samples/Hello/HelloGlfw.cs
Normal file
49
samples/Hello/HelloGlfw.cs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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();
|
||||
}
|
||||
Loading…
Reference in a new issue