samples: add Hello/Demo samples for most BRUTAL packages (#19)

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:
Rian Drake 2026-10-27 09:10:25 +13:00 • committed by GitHub
commit 7a3b72d843
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,67 @@
/*
* HelloRenderDocImGui
*
* Draws the RenderDoc ImGui window headlessly and prints how much geometry it produced. The window
* adds View > RenderDoc to the main menu bar. When the app was launched from RenderDoc (Windows or
* Linux) the window shows the overlay, capture options, a TriggerCapture button and the list of
* captures; otherwise (always on macOS) its title reads "RenderDoc (loading failed)" and it only
* has a Help link and a load/unload button. See Demo/DemoRenderDoc.cs for capturing frames.
*/
#:package Ahwoo.Brutal.ImGui@2026.10.2
#:package Ahwoo.Brutal.RenderDoc@2026.10.2
#:package Ahwoo.Brutal.RenderDoc.ImGui@2026.10.2
#:package Ahwoo.Brutal.Core@2026.10.1
#:package Ahwoo.Brutal.Numerics@2026.10.1
using Brutal.ImGuiApi;
using Brutal.Numerics;
using Brutal.RenderDocApi;
// Call as early as possible, before any graphics API is initialized.
RenderDoc.Initialize();
var context = ImGui.CreateContext();
try
{
Run();
}
finally
{
ImGui.DestroyContext(context);
}
static void Run()
{
var io = ImGui.GetIO();
io.IniFilename = null; // Don't write imgui.ini.
io.DisplaySize = new float2(800, 600); // No window, so tell ImGui how big the screen is.
io.DeltaTime = 1f / 60f;
// Claim a renderer that handles texture requests so ImGui builds the font atlas during the frame.
// Nothing uploads it here, which is fine for a headless frame.
io.BackendFlags |= ImGuiBackendFlags.RendererHasTextures;
// The window starts hidden; View > RenderDoc toggles it. Show it straight away.
RenderDocWindow.Instance.Visible = true;
// The window sizes itself to fit, and ImGui hides auto-sized windows on their first frame while
// it measures them, so run two frames to see it drawn.
for (var frame = 0; frame < 2; frame++)
{
ImGui.NewFrame();
RenderDocWindow.Instance.OnImGui(); // Call once per frame, between NewFrame and Render.
ImGui.Render();
}
// A renderer would draw these; here we just count them.
var drawData = ImGui.GetDrawData();
var commands = 0;
for (var i = 0; i < drawData.CmdListsCount; i++)
commands += drawData.CmdLists[i].CmdBuffer.Count;
Console.WriteLine($"RenderDoc available: {RenderDoc.IsAvailable}, state: {RenderDoc.State}");
Console.WriteLine(
$"Draw data: {drawData.CmdListsCount} lists, {drawData.TotalVtxCount} vertices, {drawData.TotalIdxCount} indices, {commands} commands"
);
}