using System.IO;
using SlatedGameToolkit.Framework.Graphics.OpenGL;
using SlatedGameToolkit.Framework.Graphics.Textures;
using StbImageSharp;
namespace SlatedGameToolkit.Commons.Loaders
{
public static class TextureLoader
{
///
/// Loads a texture using StbImage library.
/// Any format supported by StbImage is therefore supported.
///
/// The path of the texture to load.
/// The OpenGL context to associate the texture with.
/// A texture.
public static Texture Load2DTexture(string path, GLContext glContext = null)
{
using (Stream stream = File.OpenRead(path))
{
ImageResult image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha);
TextureData textureData = new TextureData(image.Width, image.Height, image.Data);
return new Texture(textureData, glContext);
}
}
}
}