63 lines
1.9 KiB
C++
63 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <SDL2/SDL_blendmode.h> // Para SDL_BlendMode
|
|
#include <SDL2/SDL_rect.h> // Para SDL_Point, SDL_Rect
|
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_FLIP_NONE, SDL_TEX...
|
|
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
|
#include <string> // Para basic_string, string
|
|
|
|
class Texture
|
|
{
|
|
private:
|
|
// Objetos y punteros
|
|
SDL_Texture *texture; // La textura
|
|
SDL_Renderer *renderer; // Renderizador donde dibujar la textura
|
|
|
|
// Variables
|
|
int width; // Ancho de la imagen
|
|
int height; // Alto de la imagen
|
|
std::string path; // Ruta de la imagen de la textura
|
|
|
|
public:
|
|
// Constructor
|
|
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 verbose = false);
|
|
|
|
// Crea una textura en blanco
|
|
bool createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
|
|
|
// Libera la memoria de la textura
|
|
void unload();
|
|
|
|
// Establece el color para la modulacion
|
|
void setColor(Uint8 red, Uint8 green, Uint8 blue);
|
|
|
|
// Establece el blending
|
|
void setBlendMode(SDL_BlendMode blending);
|
|
|
|
// Establece el alpha para la modulación
|
|
void setAlpha(Uint8 alpha);
|
|
|
|
// Renderiza la textura en un punto específico
|
|
void render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip = nullptr, float zoomW = 1, float zoomH = 1, double angle = 0.0, SDL_Point *center = nullptr, SDL_RendererFlip flip = SDL_FLIP_NONE);
|
|
|
|
// Establece la textura como objetivo de renderizado
|
|
void setAsRenderTarget(SDL_Renderer *renderer);
|
|
|
|
// Obtiene el ancho de la imagen
|
|
int getWidth();
|
|
|
|
// Obtiene el alto de la imagen
|
|
int getHeight();
|
|
|
|
// Recarga la textura
|
|
bool reLoad();
|
|
|
|
// Obtiene la textura
|
|
SDL_Texture *getSDLTexture();
|
|
}; |