2 #include <unordered_map>
7 #include <SDL2/SDL_mixer.h>
27 if (SDL_LoadBMP(path.c_str()) == NULL)
29 std::cout <<
"Error loading image: " << path << std::endl;
33 SDL_Surface* surface = SDL_LoadBMP(path.c_str());
34 SDL_Texture* texture = SDL_CreateTextureFromSurface(
m_renderer, surface);
35 SDL_FreeSurface(surface);
44 TTF_Font* font = NULL;
45 std::string textKey = text + std::to_string(font_size);
53 font = TTF_OpenFont(font_path.c_str(), font_size);
56 std::cout <<
"Error loading font: " << font_path << std::endl;
62 SDL_Surface* surface = TTF_RenderText_Solid(font, text.c_str(), color);
63 SDL_Texture* texture = SDL_CreateTextureFromSurface(
m_renderer, surface);
64 SDL_FreeSurface(surface);
void setRenderer(SDL_Renderer *renderer)
Sets the renderer for resource management.
SDL_Renderer * m_renderer
Renderer used to render game objects.
SDL_Texture * loadText(std::string font_path, std::string text, SDL_Color color, int font_size=20)
Loads a text as a texture using a specified TTF font.
SDL_Renderer * getRenderer()
Gets the current renderer.
std::unordered_map< std::string, SDL_Texture * > m_imageResourceMap
Cache of texture resources.
SDL_Texture * loadTexture(std::string path)
Loads a texture from a specified file path.
std::unordered_map< std::string, TTF_Font * > m_fontMap
Cache of font resources.
Manages resources such as textures, fonts, and potentially sounds for a game engine.