migrant a SDL3
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "screen.h"
|
||||
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <SDL3/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
|
||||
#include <algorithm> // Para max, min
|
||||
#include <fstream> // Para basic_ifstream, ifstream
|
||||
#include <iterator> // Para istreambuf_iterator, operator==
|
||||
@@ -32,13 +32,12 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
: window_(window),
|
||||
renderer_(renderer),
|
||||
game_canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
src_rect_({0, 0, param.game.width, param.game.height}),
|
||||
dst_rect_({0, 0, param.game.width, param.game.height})
|
||||
src_rect_(SDL_FRect{0, 0, static_cast<float>(param.game.width), static_cast<float>(param.game.height)}),
|
||||
dst_rect_(SDL_FRect{0, 0, static_cast<float>(param.game.width), static_cast<float>(param.game.height)})
|
||||
{
|
||||
// Inicializa variables
|
||||
SDL_DisplayMode DM;
|
||||
SDL_GetCurrentDisplayMode(0, &DM);
|
||||
info_resolution_ = std::to_string(DM.w) + " X " + std::to_string(DM.h) + " AT " + std::to_string(DM.refresh_rate) + " HZ";
|
||||
auto DM = SDL_GetCurrentDisplayMode(0);
|
||||
info_resolution_ = std::to_string(DM->w) + " X " + std::to_string(DM->h) + " AT " + std::to_string(DM->refresh_rate) + " HZ";
|
||||
adjustRenderLogicalSize();
|
||||
|
||||
// Muestra la ventana
|
||||
@@ -85,7 +84,7 @@ void Screen::renderScreen()
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
|
||||
SDL_RenderTexture(renderer_, game_canvas_, nullptr, nullptr);
|
||||
SDL_RenderPresent(renderer_);
|
||||
}
|
||||
}
|
||||
@@ -100,7 +99,7 @@ void Screen::setVideoMode(ScreenVideoMode mode)
|
||||
Uint32 flags = SDL_GetWindowFlags(window_);
|
||||
if (flags != static_cast<Uint32>(options.video.mode))
|
||||
{
|
||||
SDL_SetWindowFullscreen(window_, static_cast<Uint32>(options.video.mode));
|
||||
SDL_SetWindowFullscreen(window_, static_cast<bool>(options.video.mode));
|
||||
}
|
||||
|
||||
initShaders();
|
||||
@@ -192,11 +191,11 @@ void Screen::renderShake()
|
||||
|
||||
// Vuelca game_canvas_ a la textura temporal
|
||||
SDL_SetRenderTarget(renderer_, temp_texture);
|
||||
SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr);
|
||||
SDL_RenderTexture(renderer_, game_canvas_, nullptr, nullptr);
|
||||
|
||||
// Vuelca textura temporal a game_canvas_
|
||||
SDL_SetRenderTarget(renderer_, game_canvas_);
|
||||
SDL_RenderCopy(renderer_, temp_texture, &src_rect_, &dst_rect_);
|
||||
SDL_RenderTexture(renderer_, temp_texture, &src_rect_, &dst_rect_);
|
||||
|
||||
// Elimina la textura temporal
|
||||
SDL_DestroyTexture(temp_texture);
|
||||
@@ -261,7 +260,7 @@ void Screen::adjustWindowSize()
|
||||
const int NEW_POS_Y = old_pos_y + (old_height - HEIGHT) / 2;
|
||||
|
||||
SDL_Rect viewport = {0, 0, WIDTH, HEIGHT};
|
||||
SDL_RenderSetViewport(renderer_, &viewport);
|
||||
SDL_SetRenderViewport(renderer_, &viewport);
|
||||
|
||||
SDL_SetWindowPosition(window_, std::max(NEW_POS_X, WINDOWS_DECORATIONS_), std::max(NEW_POS_Y, 0));
|
||||
SDL_SetWindowSize(window_, WIDTH, HEIGHT);
|
||||
@@ -274,11 +273,10 @@ void Screen::adjustWindowSize()
|
||||
int Screen::getMaxZoom()
|
||||
{
|
||||
// Obtiene información sobre la pantalla
|
||||
SDL_DisplayMode DM;
|
||||
SDL_GetCurrentDisplayMode(0, &DM);
|
||||
auto DM = SDL_GetCurrentDisplayMode(0);
|
||||
|
||||
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
|
||||
const int MAX_ZOOM = std::min(DM.w / param.game.width, (DM.h - WINDOWS_DECORATIONS_) / param.game.height);
|
||||
const int MAX_ZOOM = std::min(DM->w / param.game.width, (DM->h - WINDOWS_DECORATIONS_) / param.game.height);
|
||||
|
||||
// Normaliza los valores de zoom
|
||||
options.video.window.zoom = std::min(options.video.window.zoom, MAX_ZOOM);
|
||||
|
||||
Reference in New Issue
Block a user