pmatyja / StbDxtSharp

C# port of stb_dxt.h

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StbDxtSharp

NuGet Build status Chat

C# port of stb_dxt.h

Adding Reference

There are two ways of referencing StbDxtSharp in the project:

  1. Through nuget: https://www.nuget.org/packages/StbDxtSharp/

  2. As source code. There are two options:

    a. Add src/StbDxtSharp.csproj to the solution

    b. Include *.cs from folder "src" directly in the project. In this case, it might make sense to add STBSHARP_INTERNAL build compilation symbol to the project, so StbDxtSharp classes would become internal.

FNA/MonoGame Sample Code

using (var stream = TitleContainer.OpenStream("image.png"))
{
    // Load the image using StbImageSharp(https://github.com/StbSharp/StbImageSharp)
    var ir = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);

    // Compress it using StbDxtSharp
    var compressedData = StbDxt.CompressDxt5(ir.Width, ir.Height, ir.Data);

    // Create texture from the compressed data
    _texture = new Texture2D(GraphicsDevice, ir.Width, ir.Height, false, SurfaceFormat.Dxt5);
    _texture.SetData(compressedData);
}

License

Public Domain

About

C# port of stb_dxt.h


Languages

Language:C# 94.0%Language:C++ 5.7%Language:Batchfile 0.4%