const sdl = @import("./sdl.zig").c;
const log = sdl.SDL_Log;

pub fn loadTexture(renderer: *sdl.struct_SDL_Renderer, path: [*c]const u8) !*sdl.struct_SDL_Texture {
    const new_texture = sdl.IMG_LoadTexture(renderer, path) orelse {
        log("Unable to load texture from surface %s\n", sdl.SDL_GetError());
        return error.SDLLoadError;
    };

    return new_texture;
}

// fn loadSurface(path: [*c]const u8) !*sdl.struct_SDL_Surface {
//     // TODO check file exists
//     const loaded_surface: [*c]sdl.struct_SDL_Surface = sdl.IMG_Load(path);
//     if (loaded_surface == null) {
//         log("Unable to load media at path %s: %s\n", path, sdl.IMG_GetError());
//         return error.SDLLoadError;
//     }
//     defer sdl.SDL_FreeSurface(loaded_surface);
//     // Converting 24bit bmp to 32bit to match display
//     const optimized_surface = sdl.SDL_ConvertSurface(loaded_surface, screen_surface.format, 0);
//     if (optimized_surface == null) {
//         log("Unable to optimize media at path %s: %s\n", path, sdl.SDL_GetError());
//         return error.SDLLoadError;
//     }
//     return optimized_surface;
// }
