cppcheck
This commit is contained in:
@@ -15,30 +15,25 @@ void Texture::setGlobalScaleMode(SDL_ScaleMode mode) {
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose) {
|
||||
// Copia punteros
|
||||
this->renderer = renderer;
|
||||
this->path = path;
|
||||
|
||||
// Inicializa
|
||||
texture = nullptr;
|
||||
width = 0;
|
||||
height = 0;
|
||||
|
||||
Texture::Texture(SDL_Renderer *renderer, const std::string &path, bool verbose)
|
||||
: texture(nullptr),
|
||||
renderer(renderer),
|
||||
width(0),
|
||||
height(0),
|
||||
path(path) {
|
||||
// Carga el fichero en la textura
|
||||
if (path != "") {
|
||||
if (!path.empty()) {
|
||||
loadFromFile(path, renderer, verbose);
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor desde bytes
|
||||
Texture::Texture(SDL_Renderer *renderer, const std::vector<uint8_t> &bytes, bool verbose) {
|
||||
this->renderer = renderer;
|
||||
this->path = "";
|
||||
texture = nullptr;
|
||||
width = 0;
|
||||
height = 0;
|
||||
|
||||
Texture::Texture(SDL_Renderer *renderer, const std::vector<uint8_t> &bytes, bool verbose)
|
||||
: texture(nullptr),
|
||||
renderer(renderer),
|
||||
width(0),
|
||||
height(0),
|
||||
path("") {
|
||||
if (!bytes.empty()) {
|
||||
loadFromMemory(bytes.data(), bytes.size(), renderer, verbose);
|
||||
}
|
||||
@@ -53,7 +48,7 @@ Texture::~Texture() {
|
||||
// Helper: convierte píxeles RGBA decodificados por stbi en SDL_Texture
|
||||
static SDL_Texture *createTextureFromPixels(SDL_Renderer *renderer, unsigned char *data, int w, int h, int *out_w, int *out_h) {
|
||||
const int pitch = 4 * w;
|
||||
SDL_Surface *loadedSurface = SDL_CreateSurfaceFrom(w, h, SDL_PIXELFORMAT_RGBA32, (void *)data, pitch);
|
||||
SDL_Surface *loadedSurface = SDL_CreateSurfaceFrom(w, h, SDL_PIXELFORMAT_RGBA32, static_cast<void *>(data), pitch);
|
||||
if (loadedSurface == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -68,7 +63,7 @@ static SDL_Texture *createTextureFromPixels(SDL_Renderer *renderer, unsigned cha
|
||||
}
|
||||
|
||||
// Carga una imagen desde un fichero
|
||||
bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbose) {
|
||||
bool Texture::loadFromFile(const std::string &path, SDL_Renderer *renderer, bool verbose) {
|
||||
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
|
||||
int req_format = STBI_rgb_alpha;
|
||||
int w, h, orig_format;
|
||||
|
||||
Reference in New Issue
Block a user