using SDL2; namespace KumiScript.Renderer { public class SDLTexture : IDisposable { 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 SDLTexture(nint surface, SDLRenderer renderer) { nint texture = SDL.SDL_CreateTextureFromSurface(renderer.id, surface); if (texture == 0) throw new Exception(SDL.SDL_GetError()); _id = texture; } public void Draw(SDLRenderer renderer, SDL.SDL_Rect sourceRect, SDL.SDL_Rect destRect) { SDL.SDL_RenderCopy(renderer.id, _id, ref sourceRect, ref destRect); return; } public void Dispose() { SDL.SDL_DestroyTexture(_id); return; } public void QueryTexture(out uint format, out int access, out int width, out int height) { SDL.SDL_QueryTexture(_id, out format, out access, out width, out height); return; } public void SetAlpha(byte alpha) { SDL.SDL_SetTextureAlphaMod(_id, alpha); } } }