He fet un "manolete" i he pasat a c++ i smartpointers la cárrega de surfaces desde gif. Sembla que no ha petat res
Precárrega i asignació de paletes a les textures Ara si algú toca una paleta, que siga conscient que la textura es compartida durant tot el joc
This commit is contained in:
@@ -1,51 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888, SDL_PixelF...
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_FLIP_NONE, SDL_TEX...
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint32, Uint16
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include <SDL2/SDL_blendmode.h> // for SDL_BlendMode
|
||||
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888, SDL_PixelF...
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Point, SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_FLIP_NONE, SDL_TEX...
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint8, Uint32, Uint16
|
||||
#include <string> // for string, basic_string
|
||||
#include <vector> // for vector
|
||||
#include <memory>
|
||||
|
||||
// Definiciones de tipos
|
||||
struct surface_s
|
||||
struct Surface
|
||||
{
|
||||
Uint8 *data;
|
||||
std::shared_ptr<Uint8[]> data;
|
||||
Uint16 w, h;
|
||||
};
|
||||
|
||||
typedef struct surface_s *Surface;
|
||||
// Constructor
|
||||
Surface(Uint16 width, Uint16 height, std::shared_ptr<Uint8[]> pixels)
|
||||
: data(pixels), w(width), h(height) {}
|
||||
};
|
||||
|
||||
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
|
||||
SDL_Texture *texture_; // La textura
|
||||
SDL_Renderer *renderer_; // Renderizador donde dibujar la textura
|
||||
std::shared_ptr<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);
|
||||
int current_palette_; // Indice de la paleta en uso
|
||||
|
||||
// Crea una surface desde un fichero .gif
|
||||
Surface loadSurface(const std::string &file_name);
|
||||
std::shared_ptr<Surface> loadSurface(const std::string &file_name);
|
||||
|
||||
// Vuelca la surface en la textura
|
||||
void flipSurface();
|
||||
void flipSurface();
|
||||
|
||||
// Carga una paleta desde un fichero
|
||||
std::vector<Uint32> loadPal(const std::string &file_name);
|
||||
std::vector<Uint32> loadPaletteFromFile(const std::string &file_name);
|
||||
|
||||
// Libera la memoria de la textura
|
||||
void unloadTexture();
|
||||
|
||||
// Desencadenar la superficie actual
|
||||
void unloadSurface();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
@@ -60,9 +63,6 @@ public:
|
||||
// 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);
|
||||
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
SDL_Texture *getSDLTexture();
|
||||
|
||||
// Añade una paleta a la lista
|
||||
void addPalette(const std::string &path);
|
||||
void addPaletteFromFile(const std::string &path);
|
||||
|
||||
// Establece un color de la paleta
|
||||
void setPaletteColor(int palette, int index, Uint32 color);
|
||||
|
||||
Reference in New Issue
Block a user