module utils.texture; import ecs.std; import bindbc.sdl; import bindbc.sdl.image; import ecs_utils.math.vector; struct Texture { void create() { data = Mallocator.make!Data; } bool load(SDL_Renderer* renderer, const char[] path) { char[] cpath = (cast(char*)alloca(path.length+1))[0..path.length+1]; //cpath[0..$-1] = path[0..$]; memcpy(cpath.ptr, path.ptr, path.length); cpath[$-1] = 0; SDL_Surface* surf = IMG_Load(cpath.ptr); if(!surf)return false; data.size = ivec2(surf.w,surf.h); data.texture = SDL_CreateTextureFromSurface(renderer,surf); SDL_FreeSurface(surf); if(!data.texture)return false; return true; } struct Data { ubyte[] data; ivec2 size; uint bpp; SDL_Texture* texture; } Data* data; }