KumiScript/renderer/sdl/SDLTexture.cs

26 lines
704 B
C#
Raw Normal View History

2024-01-26 05:37:51 +00:00
using SDL2;
namespace KumiScript.Renderer
{
public class SDLTexture : IDisposable
{
internal readonly nint id;
public SDLTexture(string path, SDLRenderer renderer)
{
nint surface = SDL_image.IMG_Load(path);
if (surface == 0)
throw new Exception(SDL_image.IMG_GetError());
nint texture = SDL.SDL_CreateTextureFromSurface(renderer.id, surface);
if (texture == 0)
throw new Exception(SDL.SDL_GetError());
SDL.SDL_FreeSurface(surface);
id = texture;
}
public void Dispose()
{
SDL.SDL_DestroyTexture(id);
}
}
}