Mensajes de consola opcionales

This commit is contained in:
2022-11-02 09:52:06 +01:00
parent 8232055d22
commit 88f419e963
14 changed files with 96 additions and 268 deletions

View File

@@ -5,7 +5,7 @@
#include <iostream>
// Constructor
Texture::Texture(SDL_Renderer *renderer, std::string path)
Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose)
{
// Copia punteros
this->renderer = renderer;
@@ -19,7 +19,7 @@ Texture::Texture(SDL_Renderer *renderer, std::string path)
// Carga el fichero en la textura
if (path != "")
{
loadFromFile(path, renderer);
loadFromFile(path, renderer, verbose);
}
}
@@ -31,7 +31,7 @@ Texture::~Texture()
}
// Carga una imagen desde un fichero
bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer)
bool Texture::loadFromFile(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;
@@ -44,7 +44,10 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer)
}
else
{
std::cout << "Image loaded: " << filename.c_str() << std::endl;
if (verbose)
{
std::cout << "Image loaded: " << filename.c_str() << std::endl;
}
}
int depth, pitch;
@@ -72,7 +75,10 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer)
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
if (loadedSurface == nullptr)
{
std::cout << "Unable to load image " << path.c_str() << std::endl;
if (verbose)
{
std::cout << "Unable to load image " << path.c_str() << std::endl;
}
}
else
{
@@ -80,7 +86,10 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer)
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
if (newTexture == nullptr)
{
std::cout << "Unable to create texture from " << path.c_str() << "! SDL Error: " << SDL_GetError() << std::endl;
if (verbose)
{
std::cout << "Unable to create texture from " << path.c_str() << "! SDL Error: " << SDL_GetError() << std::endl;
}
}
else
{