Add stbimage tutorial.
This commit is contained in:
parent
37f5c3b09c
commit
73d396d6c6
48
docs/ReFuel.StbImage.md
Normal file
48
docs/ReFuel.StbImage.md
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# ReFuel.StbImage
|
||||||
|
StbImage is a very common library that has been developed mainly by Sean Barett.
|
||||||
|
It is one of the easiest to use image loading libraries on the planet
|
||||||
|
especially for C and C++ users. It is relatively simple to load up and use in
|
||||||
|
C#, however the C# build system makes it a bit difficult to manage native
|
||||||
|
dependencies. Therefore this package makes it easy for you and everyone else
|
||||||
|
who needs a cross platform way to load images.
|
||||||
|
|
||||||
|
Intended OS targets are:
|
||||||
|
* Windows (x86 and x64)
|
||||||
|
* Linux (arm32, arm64, x86 and x64)
|
||||||
|
* MacOS (arm64, x64)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
```cs
|
||||||
|
using ReFuel.Stb;
|
||||||
|
|
||||||
|
// Simply load an image from a Stream or Span<T> (T: unmanaged) source.
|
||||||
|
using StbImage image = StbImage.Load(source);
|
||||||
|
|
||||||
|
Console.WriteLine("{0}x{1}", image.Width, image.Height);
|
||||||
|
// StbImage.ImagePointer is a pointer to the image data.
|
||||||
|
// Pass the image to an unsafe library as is (e.g. OpenGL), or cast it to a span. Currently there is no "safe" way to do this.
|
||||||
|
|
||||||
|
// OpenGL example
|
||||||
|
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, image.Width, image.Height, 0, StbiFormatToGLFormat(image.Format, image.IsFloat ? PixelFormat.Float : PixelFormat.UnsignedByte), image.ImagePointer);
|
||||||
|
|
||||||
|
// C# example
|
||||||
|
struct Pixel
|
||||||
|
{
|
||||||
|
int R, G, B, A;
|
||||||
|
}
|
||||||
|
|
||||||
|
Span<Pixel> pixels;
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
pixels = new Span<Pixel>(image.ImagePointer, image.Width * image.Height);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Global Options
|
||||||
|
| Option | Description |
|
||||||
|
|--------|-------------|
|
||||||
|
| `bool StbImage.FlipVerticallyOnLoad` | Flips the image vertically after loading. Practical for uses where a right handed coordinate system is used (e.g. OpenGL) |
|
||||||
|
| `bool UnpremultiplyOnLoad` | Applies to Apple iPhone PNG images, where the image is sometimes encoded with premultiplied alpha. Reverses this premultiplication. |
|
||||||
|
|
||||||
|
## Calling Stbi directly.
|
||||||
|
If you wish to call the native Stbi library, call functions in the static class `Stbi`. See `stb_image.h` documentation [online](https://github.com/nothings/stb/blob/master/stb_image.h).
|
@ -1 +0,0 @@
|
|||||||
# Getting Started
|
|
@ -1 +0,0 @@
|
|||||||
# Introduction
|
|
@ -1,4 +1,2 @@
|
|||||||
- name: Introduction
|
- name: ReFuel.StbImage Guide
|
||||||
href: introduction.md
|
href: ReFuel.StbImage.md
|
||||||
- name: Getting Started
|
|
||||||
href: getting-started.md
|
|
Loading…
Reference in New Issue
Block a user