diff --git a/source/texture.cpp b/source/texture.cpp index 78aed7f..b2b54d8 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -16,6 +16,7 @@ #include "external/gif.h" // Para Gif #include "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_alpha #include "utils.h" +#include "resource_helper.h" // Para ResourceHelper // Constructor Texture::Texture(SDL_Renderer *renderer, std::string path) @@ -64,7 +65,19 @@ auto Texture::loadFromFile(const std::string &file_path) -> bool { int width; int height; int orig_format; - unsigned char *data = stbi_load(file_path.c_str(), &width, &height, &orig_format, req_format); + unsigned char *data = nullptr; + + // Intentar cargar desde ResourceHelper primero + auto resource_data = ResourceHelper::loadFile(file_path); + if (!resource_data.empty()) { + data = stbi_load_from_memory(resource_data.data(), resource_data.size(), &width, &height, &orig_format, req_format); + } + + // Fallback a filesystem directo + if (data == nullptr) { + data = stbi_load(file_path.c_str(), &width, &height, &orig_format, req_format); + } + if (data == nullptr) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", getFileName(file_path).c_str()); throw std::runtime_error("Fichero no encontrado: " + getFileName(file_path));