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/HelloGli.cs
Normal file
49
samples/Hello/HelloGli.cs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* HelloGli
|
||||
*
|
||||
* Creates a texture with a full mip chain using GLI, saves it as a .dds and loads it back.
|
||||
*/
|
||||
|
||||
#:property AllowUnsafeBlocks=true
|
||||
#:package Ahwoo.Brutal.Gli@2026.10.1
|
||||
#:package Ahwoo.Brutal.Numerics@2026.10.1
|
||||
|
||||
// RIAN: This package may be deprecated in the future, as the extensions it supports may be covered by better packages.
|
||||
|
||||
using Brutal.GliApi;
|
||||
using Brutal.Numerics;
|
||||
|
||||
Run();
|
||||
|
||||
static void Run()
|
||||
{
|
||||
var extent = new int3(64, 64, 1);
|
||||
|
||||
// A 2D RGBA texture with a full mip chain (64x64 down to 1x1).
|
||||
using var texture = new Gli.Texture(
|
||||
Gli.Target._2D,
|
||||
Gli.Format.RGBA8_UNorm_Pack8,
|
||||
extent,
|
||||
1,
|
||||
1,
|
||||
7,
|
||||
Gli.Swizzles.Identity
|
||||
);
|
||||
|
||||
unsafe
|
||||
{
|
||||
// Only the top mip level is filled; the smaller levels are left empty.
|
||||
new Span<byte4>(texture.ImageData(0), extent.X * extent.Y).Fill(new byte4(255, 128, 0, 255));
|
||||
}
|
||||
|
||||
var path = Path.Combine(Path.GetTempPath(), "HelloGli.dds");
|
||||
texture.Save(path);
|
||||
Console.WriteLine($"Wrote {path}");
|
||||
|
||||
using var loaded = new Gli.Texture(path);
|
||||
Console.WriteLine($"Loaded {loaded.Target} {loaded.Format}, {loaded.Levels} levels, {loaded.Size} bytes");
|
||||
for (var level = 0; level < loaded.Levels; level++)
|
||||
Console.WriteLine(
|
||||
$" Level {level}: {loaded.ImageExtent(level).X}x{loaded.ImageExtent(level).Y}, {loaded.ImageSize(level)} bytes"
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue