Reballats tots els .h i .cpp en la mateixa carpeta
This commit is contained in:
101
source/texture.h
Normal file
101
source/texture.h
Normal file
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Definiciones de tipos
|
||||
struct surface_s
|
||||
{
|
||||
Uint8 *data;
|
||||
Uint16 w, h;
|
||||
};
|
||||
|
||||
typedef struct surface_s *Surface;
|
||||
|
||||
class Texture
|
||||
{
|
||||
private:
|
||||
// Objetos y punteros
|
||||
SDL_Texture *texture; // La textura
|
||||
SDL_Renderer *renderer; // Renderizador donde dibujar la textura
|
||||
Surface surface; // Surface para usar imagenes en formato gif con paleta
|
||||
|
||||
// Variables
|
||||
int width; // Ancho de la imagen
|
||||
int height; // Alto de la imagen
|
||||
std::string path; // Ruta de la imagen de la textura
|
||||
std::vector<std::vector<Uint32>> palettes; // Vector con las diferentes paletas
|
||||
int paletteIndex; // Indice de la paleta en uso
|
||||
|
||||
// Crea una nueva surface
|
||||
Surface newSurface(int w, int h);
|
||||
|
||||
// Elimina una surface
|
||||
void deleteSurface(Surface surface);
|
||||
|
||||
// Crea una surface desde un fichero .gif
|
||||
Surface loadSurface(const char *filename);
|
||||
|
||||
// Vuelca la surface en la textura
|
||||
void flipSurface();
|
||||
|
||||
// Carga una paleta desde un fichero
|
||||
std::vector<Uint32> loadPal(const char *filename);
|
||||
|
||||
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, bool verbose = false);
|
||||
|
||||
// Crea una textura en blanco
|
||||
bool createBlank(int width, int height, SDL_PixelFormatEnum format = SDL_PIXELFORMAT_RGBA8888, 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(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();
|
||||
|
||||
// Añade una paleta a la lista
|
||||
void addPalette(std::string path);
|
||||
|
||||
// Establece un color de la paleta
|
||||
void setPaletteColor(int palette, int index, Uint32 color);
|
||||
|
||||
// Cambia la paleta de la textura
|
||||
void setPalette(int palette);
|
||||
|
||||
// Obtiene el renderizador
|
||||
SDL_Renderer *getRenderer();
|
||||
};
|
||||
Reference in New Issue
Block a user