migrant a SDL3

This commit is contained in:
2025-03-27 08:14:37 +01:00
parent a9c869baf6
commit d2286905dc
83 changed files with 570 additions and 541 deletions

View File

@@ -75,11 +75,10 @@ bool Texture::loadFromFile(const std::string &file_path)
printWithDots("Image : ", getFileName(file_path), "[ LOADED ]");
}
int depth, pitch;
Uint32 pixel_format;
int pitch;
SDL_PixelFormat pixel_format;
// STBI_rgb_alpha (RGBA)
depth = 32;
pitch = 4 * width;
pixel_format = SDL_PIXELFORMAT_RGBA32;
@@ -87,41 +86,42 @@ bool Texture::loadFromFile(const std::string &file_path)
unloadTexture();
// La textura final
SDL_Texture *newTexture = nullptr;
SDL_Texture *new_texture = nullptr;
// Carga la imagen desde una ruta específica
auto loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom(static_cast<void *>(data), width, height, depth, pitch, pixel_format);
if (loadedSurface == nullptr)
/*auto loaded_surface = SDL_CreateRGBSurfaceWithFormatFrom(static_cast<void *>(data), width, height, depth, pitch, pixel_format);*/
auto loaded_surface = SDL_CreateSurfaceFrom(width, height, pixel_format, static_cast<void *>(data), pitch);
if (loaded_surface == nullptr)
{
std::cout << "Unable to load image " << file_path << std::endl;
}
else
{
// Crea la textura desde los pixels de la surface
newTexture = SDL_CreateTextureFromSurface(renderer_, loadedSurface);
if (newTexture == nullptr)
new_texture = SDL_CreateTextureFromSurface(renderer_, loaded_surface);
if (new_texture == nullptr)
{
std::cout << "Unable to create texture from " << file_path << "! SDL Error: " << SDL_GetError() << std::endl;
}
else
{
// Obtiene las dimensiones de la imagen
width_ = loadedSurface->w;
height_ = loadedSurface->h;
width_ = loaded_surface->w;
height_ = loaded_surface->h;
}
// Elimina la textura cargada
SDL_FreeSurface(loadedSurface);
SDL_DestroySurface(loaded_surface);
}
// Return success
stbi_image_free(data);
texture_ = newTexture;
texture_ = new_texture;
return texture_ != nullptr;
}
// Crea una textura en blanco
bool Texture::createBlank(int width, int height, SDL_PixelFormatEnum format, SDL_TextureAccess access)
bool Texture::createBlank(int width, int height, SDL_PixelFormat format, SDL_TextureAccess access)
{
// Crea una textura sin inicializar
texture_ = SDL_CreateTexture(renderer_, format, access, width, height);
@@ -174,10 +174,10 @@ void Texture::setAlpha(Uint8 alpha)
}
// Renderiza la textura en un punto específico
void Texture::render(int x, int y, SDL_FRect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
void Texture::render(int x, int y, SDL_FRect *clip, float zoomW, float zoomH, double angle, SDL_FPoint *center, SDL_FlipMode flip)
{
// Establece el destino de renderizado en la pantalla
SDL_FRect renderQuad = {x, y, width_, height_};
SDL_FRect renderQuad = {static_cast<float>(x), static_cast<float>(y), static_cast<float>(width_), static_cast<float>(height_)};
// Obtiene las dimesiones del clip de renderizado
if (clip != nullptr)
@@ -198,7 +198,7 @@ void Texture::render(int x, int y, SDL_FRect *clip, float zoomW, float zoomH, do
}
// Renderiza a pantalla
SDL_RenderCopyEx(renderer_, texture_, clip, &renderQuad, angle, center, flip);
SDL_RenderTextureRotated(renderer_, texture_, clip, &renderQuad, angle, center, flip);
}
// Establece la textura como objetivo de renderizado