migracio a SDL3

This commit is contained in:
2026-04-03 10:04:49 +02:00
parent 1e73a3159f
commit 7e570e2814
44 changed files with 826 additions and 801 deletions

View File

@@ -1,8 +1,5 @@
#include "screen.h"
#include <SDL2/SDL_error.h> // for SDL_GetError
#include <SDL2/SDL_events.h> // for SDL_DISABLE, SDL_ENABLE
#include <SDL2/SDL_mouse.h> // for SDL_ShowCursor
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <SDL3/SDL.h>
#include <algorithm> // for max, min
#include <iostream> // for basic_ostream, operator<<, cout, endl
#include <string> // for basic_string, char_traits, string
@@ -77,7 +74,8 @@ void Screen::blit()
SDL_RenderClear(renderer);
// Copia la textura de juego en el renderizador en la posición adecuada
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
SDL_FRect fdest = {(float)dest.x, (float)dest.y, (float)dest.w, (float)dest.h};
SDL_RenderTexture(renderer, gameCanvas, nullptr, &fdest);
// Muestra por pantalla el renderizador
SDL_RenderPresent(renderer);
@@ -87,13 +85,13 @@ void Screen::blit()
void Screen::setVideoMode(int videoMode)
{
// Aplica el modo de video
SDL_SetWindowFullscreen(window, videoMode);
SDL_SetWindowFullscreen(window, videoMode != 0);
// Si está activo el modo ventana quita el borde
if (videoMode == 0)
{
// Muestra el puntero
SDL_ShowCursor(SDL_ENABLE);
SDL_ShowCursor();
// Esconde la ventana
//SDL_HideWindow(window);
@@ -121,10 +119,10 @@ void Screen::setVideoMode(int videoMode)
}
// Si está activo el modo de pantalla completa añade el borde
else if (videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
else if (videoMode == SDL_WINDOW_FULLSCREEN)
{
// Oculta el puntero
SDL_ShowCursor(SDL_DISABLE);
SDL_HideCursor();
// Obten el alto y el ancho de la ventana
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
@@ -171,7 +169,7 @@ void Screen::setVideoMode(int videoMode)
}
// Modifica el tamaño del renderizador
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
SDL_SetRenderLogicalPresentation(renderer, windowWidth, windowHeight, SDL_LOGICAL_PRESENTATION_LETTERBOX);
// Actualiza las opciones
options->videoMode = videoMode;
@@ -182,7 +180,7 @@ void Screen::setVideoMode(int videoMode)
// Camibia entre pantalla completa y ventana
void Screen::switchVideoMode()
{
options->videoMode = (options->videoMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
options->videoMode = (options->videoMode == 0) ? SDL_WINDOW_FULLSCREEN : 0;
setVideoMode(options->videoMode);
}
@@ -311,7 +309,7 @@ void Screen::renderFade()
return;
}
const SDL_Rect rect = {0, 0, gameCanvasWidth, gameCanvasHeight};
const SDL_FRect rect = {0, 0, (float)gameCanvasWidth, (float)gameCanvasHeight};
color_t color = {0, 0, 0};
const float step = (float)fadeCounter / (float)fadeLenght;
const int alpha = 0 + (255 - 0) * step;