38 lines
1012 B
C++
38 lines
1012 B
C++
#include <renderer/texture.hpp>
|
|
|
|
Game::Renderer::Texture::Texture(const std::string& path, SDL_Renderer* renderer, std::string id)
|
|
: mTex(nullptr), mId(id) {
|
|
SDL_Surface* surf = IMG_Load(path.c_str());
|
|
if (!surf) {
|
|
ERROR("Failed to load image at " << path);
|
|
return;
|
|
}
|
|
|
|
mTex = SDL_CreateTextureFromSurface(renderer, surf);
|
|
SDL_DestroySurface(surf);
|
|
}
|
|
|
|
Game::Renderer::Texture::Texture(const Texture& other) {
|
|
// Copy the references, since copying memory would require re-initing a bunch of things - for now
|
|
this->mTex = other.mTex;
|
|
}
|
|
|
|
Game::Renderer::Texture& Game::Renderer::Texture::operator=(const Texture& other) {
|
|
// Same reasoning
|
|
this->mTex = other.mTex;
|
|
return *this;
|
|
}
|
|
|
|
Game::Renderer::Texture::~Texture() {
|
|
if (mTex)
|
|
SDL_DestroyTexture(mTex);
|
|
LOG("Destroyed texture '" << mId << "'")
|
|
}
|
|
|
|
SDL_Texture* Game::Renderer::Texture::getSDLTexture() {
|
|
return mTex;
|
|
}
|
|
|
|
std::string Game::Renderer::Texture::getId() {
|
|
return mId;
|
|
} |