Commit pa que Mon arregle el codi mentre em dutxe
This commit is contained in:
@@ -12,36 +12,36 @@
|
||||
|
||||
// Constructor
|
||||
Texture::Texture(SDL_Renderer *renderer, std::string path)
|
||||
: renderer(renderer), path(path)
|
||||
: renderer_(renderer), path_(path)
|
||||
{
|
||||
// Inicializa
|
||||
surface = nullptr;
|
||||
texture = nullptr;
|
||||
width = 0;
|
||||
height = 0;
|
||||
paletteIndex = 0;
|
||||
palettes.clear();
|
||||
surface_ = nullptr;
|
||||
texture_ = nullptr;
|
||||
width_ = 0;
|
||||
height_ = 0;
|
||||
paletteIndex_ = 0;
|
||||
palettes_.clear();
|
||||
|
||||
// Carga el fichero en la textura
|
||||
if (path != "")
|
||||
if (path_ != "")
|
||||
{
|
||||
// Obtiene la extensión
|
||||
const std::string extension = path.substr(path.find_last_of(".") + 1);
|
||||
const std::string extension = path_.substr(path_.find_last_of(".") + 1);
|
||||
|
||||
// .png
|
||||
if (extension == "png")
|
||||
{
|
||||
loadFromFile(path);
|
||||
loadFromFile(path_);
|
||||
}
|
||||
|
||||
// .gif
|
||||
else if (extension == "gif")
|
||||
{
|
||||
surface = loadSurface(path.c_str());
|
||||
addPalette(path.c_str());
|
||||
surface_ = loadSurface(path_.c_str());
|
||||
addPalette(path_.c_str());
|
||||
setPaletteColor(0, 0, 0x00000000);
|
||||
createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING);
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
createBlank(width_, height_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING);
|
||||
SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND);
|
||||
flipSurface();
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ bool Texture::loadFromFile(std::string path)
|
||||
else
|
||||
{
|
||||
// Crea la textura desde los pixels de la surface
|
||||
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
|
||||
newTexture = SDL_CreateTextureFromSurface(renderer_, loadedSurface);
|
||||
if (newTexture == nullptr)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
@@ -116,8 +116,8 @@ bool Texture::loadFromFile(std::string path)
|
||||
else
|
||||
{
|
||||
// Obtiene las dimensiones de la imagen
|
||||
this->width = loadedSurface->w;
|
||||
this->height = loadedSurface->h;
|
||||
width_ = loadedSurface->w;
|
||||
height_ = loadedSurface->h;
|
||||
}
|
||||
|
||||
// Elimina la textura cargada
|
||||
@@ -126,71 +126,73 @@ bool Texture::loadFromFile(std::string path)
|
||||
|
||||
// Return success
|
||||
stbi_image_free(data);
|
||||
texture = newTexture;
|
||||
return texture != nullptr;
|
||||
texture_ = newTexture;
|
||||
return texture_ != nullptr;
|
||||
}
|
||||
|
||||
// Crea una textura en blanco
|
||||
bool Texture::createBlank(int width, int height, SDL_PixelFormatEnum format, SDL_TextureAccess access)
|
||||
{
|
||||
// Crea una textura sin inicializar
|
||||
texture = SDL_CreateTexture(renderer, format, access, width, height);
|
||||
if (texture == nullptr)
|
||||
texture_ = SDL_CreateTexture(renderer_, format, access, width, height);
|
||||
if (!texture_)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
}
|
||||
|
||||
return texture != nullptr;
|
||||
return texture_ != nullptr;
|
||||
}
|
||||
|
||||
// Libera la memoria de la textura
|
||||
void Texture::unload()
|
||||
{
|
||||
// Libera la textura
|
||||
if (texture != nullptr)
|
||||
if (texture_)
|
||||
{
|
||||
SDL_DestroyTexture(texture);
|
||||
texture = nullptr;
|
||||
width = 0;
|
||||
height = 0;
|
||||
SDL_DestroyTexture(texture_);
|
||||
texture_ = nullptr;
|
||||
width_ = 0;
|
||||
height_ = 0;
|
||||
}
|
||||
|
||||
// Libera la surface
|
||||
if (surface != nullptr)
|
||||
if (surface_)
|
||||
{
|
||||
deleteSurface(surface);
|
||||
surface = nullptr;
|
||||
deleteSurface(surface_);
|
||||
surface_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el color para la modulacion
|
||||
void Texture::setColor(Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
SDL_SetTextureColorMod(texture, red, green, blue);
|
||||
SDL_SetTextureColorMod(texture_, red, green, blue);
|
||||
}
|
||||
|
||||
// Establece el blending
|
||||
void Texture::setBlendMode(SDL_BlendMode blending)
|
||||
{
|
||||
SDL_SetTextureBlendMode(texture, blending);
|
||||
SDL_SetTextureBlendMode(texture_, blending);
|
||||
}
|
||||
|
||||
// Establece el alpha para la modulación
|
||||
void Texture::setAlpha(Uint8 alpha)
|
||||
{
|
||||
SDL_SetTextureAlphaMod(texture, alpha);
|
||||
SDL_SetTextureAlphaMod(texture_, alpha);
|
||||
}
|
||||
|
||||
// Renderiza la textura en un punto específico
|
||||
void Texture::render(int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
|
||||
{
|
||||
// Establece el destino de renderizado en la pantalla
|
||||
SDL_Rect renderQuad = {x, y, width, height};
|
||||
SDL_Rect renderQuad = {x, y, width_, height_};
|
||||
|
||||
// Obtiene las dimesiones del clip de renderizado
|
||||
if (clip != nullptr)
|
||||
@@ -203,37 +205,37 @@ void Texture::render(int x, int y, SDL_Rect *clip, float zoomW, float zoomH, dou
|
||||
renderQuad.h = renderQuad.h * zoomH;
|
||||
|
||||
// Renderiza a pantalla
|
||||
SDL_RenderCopyEx(renderer, texture, clip, &renderQuad, angle, center, flip);
|
||||
SDL_RenderCopyEx(renderer_, texture_, clip, &renderQuad, angle, center, flip);
|
||||
}
|
||||
|
||||
// Establece la textura como objetivo de renderizado
|
||||
void Texture::setAsRenderTarget(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_SetRenderTarget(renderer, texture);
|
||||
SDL_SetRenderTarget(renderer, texture_);
|
||||
}
|
||||
|
||||
// Obtiene el ancho de la imagen
|
||||
int Texture::getWidth()
|
||||
{
|
||||
return width;
|
||||
return width_;
|
||||
}
|
||||
|
||||
// Obtiene el alto de la imagen
|
||||
int Texture::getHeight()
|
||||
{
|
||||
return height;
|
||||
return height_;
|
||||
}
|
||||
|
||||
// Recarga la textura
|
||||
bool Texture::reLoad()
|
||||
{
|
||||
return loadFromFile(path);
|
||||
return loadFromFile(path_);
|
||||
}
|
||||
|
||||
// Obtiene la textura
|
||||
SDL_Texture *Texture::getSDLTexture()
|
||||
{
|
||||
return texture;
|
||||
return texture_;
|
||||
}
|
||||
|
||||
// Crea una nueva surface
|
||||
@@ -291,8 +293,8 @@ Surface Texture::loadSurface(const char *filename)
|
||||
surface->data = pixels;
|
||||
free(buffer);
|
||||
|
||||
this->width = w;
|
||||
this->height = h;
|
||||
width_ = w;
|
||||
height_ = h;
|
||||
|
||||
return surface;
|
||||
}
|
||||
@@ -301,27 +303,27 @@ Surface Texture::loadSurface(const char *filename)
|
||||
void Texture::flipSurface()
|
||||
{
|
||||
// Limpia la textura
|
||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, texture);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, texture_);
|
||||
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
|
||||
// Vuelca los datos
|
||||
Uint32 *pixels;
|
||||
int pitch;
|
||||
SDL_LockTexture(texture, nullptr, (void **)&pixels, &pitch);
|
||||
for (int i = 0; i < width * height; ++i)
|
||||
SDL_LockTexture(texture_, nullptr, (void **)&pixels, &pitch);
|
||||
for (int i = 0; i < width_ * height_; ++i)
|
||||
{
|
||||
pixels[i] = palettes[paletteIndex][surface->data[i]];
|
||||
pixels[i] = palettes_[paletteIndex_][surface_->data[i]];
|
||||
}
|
||||
SDL_UnlockTexture(texture);
|
||||
SDL_UnlockTexture(texture_);
|
||||
}
|
||||
|
||||
// Establece un color de la paleta
|
||||
void Texture::setPaletteColor(int palette, int index, Uint32 color)
|
||||
{
|
||||
palettes.at(palette)[index] = color;
|
||||
palettes_.at(palette)[index] = color;
|
||||
}
|
||||
|
||||
// Carga una paleta desde un fichero
|
||||
@@ -361,16 +363,16 @@ std::vector<Uint32> Texture::loadPal(const char *filename)
|
||||
// Añade una paleta a la lista
|
||||
void Texture::addPalette(std::string path)
|
||||
{
|
||||
palettes.push_back(loadPal(path.c_str()));
|
||||
setPaletteColor((int)palettes.size() - 1, 0, 0x00000000);
|
||||
palettes_.push_back(loadPal(path.c_str()));
|
||||
setPaletteColor((int)palettes_.size() - 1, 0, 0x00000000);
|
||||
}
|
||||
|
||||
// Cambia la paleta de la textura
|
||||
void Texture::setPalette(int palette)
|
||||
{
|
||||
if (palette < (int)palettes.size())
|
||||
if (palette < (int)palettes_.size())
|
||||
{
|
||||
paletteIndex = palette;
|
||||
paletteIndex_ = palette;
|
||||
flipSurface();
|
||||
}
|
||||
}
|
||||
@@ -378,5 +380,5 @@ void Texture::setPalette(int palette)
|
||||
// Obtiene el renderizador
|
||||
SDL_Renderer *Texture::getRenderer()
|
||||
{
|
||||
return renderer;
|
||||
return renderer_;
|
||||
}
|
||||
Reference in New Issue
Block a user