Cambiando printf por std::cout
This commit is contained in:
@@ -2,9 +2,10 @@
|
||||
#include "texture.h"
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
#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;
|
||||
@@ -18,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +31,9 @@ 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);
|
||||
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
|
||||
int req_format = STBI_rgb_alpha;
|
||||
int width, height, orig_format;
|
||||
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
|
||||
@@ -43,7 +44,10 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Image loaded: %s\n", filename.c_str());
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Image loaded: " << filename.c_str() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int depth, pitch;
|
||||
@@ -71,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)
|
||||
{
|
||||
printf("Unable to load image %s!\n", path.c_str());
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Unable to load image " << path.c_str() << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -79,7 +86,10 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
|
||||
if (newTexture == nullptr)
|
||||
{
|
||||
printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError());
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Unable to create texture from " << path.c_str() << "! SDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -92,7 +102,7 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||
SDL_FreeSurface(loadedSurface);
|
||||
}
|
||||
|
||||
// Devuelve el resultado
|
||||
// Return success
|
||||
stbi_image_free(data);
|
||||
texture = newTexture;
|
||||
return texture != nullptr;
|
||||
@@ -105,7 +115,7 @@ bool Texture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_Tex
|
||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
||||
if (texture == nullptr)
|
||||
{
|
||||
printf("Unable to create blank texture! SDL Error: %s\n", SDL_GetError());
|
||||
std::cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -189,4 +199,10 @@ int Texture::getHeight()
|
||||
bool Texture::reLoad()
|
||||
{
|
||||
return loadFromFile(path, renderer);
|
||||
}
|
||||
|
||||
// Obtiene la textura
|
||||
SDL_Texture *Texture::getSDLTexture()
|
||||
{
|
||||
return texture;
|
||||
}
|
||||
@@ -21,13 +21,13 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Texture(SDL_Renderer *renderer, std::string path = "");
|
||||
Texture(SDL_Renderer *renderer, std::string path = "", bool verbose = false);
|
||||
|
||||
// Destructor
|
||||
~Texture();
|
||||
|
||||
// Carga una imagen desde un fichero
|
||||
bool loadFromFile(std::string path, SDL_Renderer *renderer);
|
||||
bool loadFromFile(std::string path, SDL_Renderer *renderer, bool verbose = false);
|
||||
|
||||
// Crea una textura en blanco
|
||||
bool createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
||||
@@ -58,6 +58,9 @@ public:
|
||||
|
||||
// Recarga la textura
|
||||
bool reLoad();
|
||||
|
||||
// Obtiene la textura
|
||||
SDL_Texture *getSDLTexture();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user