From 9692d01b425201869e7049a4092a8b15e7ccc6a8 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 13 Mar 2025 22:51:51 +0100 Subject: [PATCH] Ja funciona correctament el canvi de tamany de finestra, el shaders, i la pantalla completa --- source/director.cpp | 11 ----------- source/screen.cpp | 24 +++++++++++++++++------- source/screen.h | 7 ++++++- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 74b96ec..375bd49 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -289,17 +289,6 @@ bool Director::initSDL() } else { - /* - // Muestra información de la pantalla - std::cout << "\nDisplay modes list:" << std::endl; - for (int i = 0; i < SDL_GetNumDisplayModes(0); ++i) - { - SDL_DisplayMode DM; - SDL_GetDisplayMode(0,i,&DM); - std::cout << " - " << DM.w << "x" << DM.h << " @ " << DM.refresh_rate << "Hz" << std::endl; - } - */ - // Obtiene información sobre la pantalla SDL_DisplayMode DM; SDL_GetCurrentDisplayMode(0, &DM); diff --git a/source/screen.cpp b/source/screen.cpp index d41bbf5..6658ebc 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -41,6 +41,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) 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"; + adjustRenderLogicalSize(); // Inicializa los shaders initShaders(); @@ -101,6 +102,8 @@ void Screen::setVideoMode(ScreenVideoMode video_mode) { SDL_SetWindowFullscreen(window_, static_cast(options.video.mode)); } + + initShaders(); } // Camibia entre pantalla completa y ventana @@ -312,17 +315,22 @@ void Screen::renderInfo() } } -// Reinicia los shaders +// Carga el contenido del archivo GLSL +void Screen::loadShaders() +{ + const std::string GLSL_FILE = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl"; + std::ifstream f(Asset::get()->get(GLSL_FILE).c_str()); + shaderSource = std::string((std::istreambuf_iterator(f)), std::istreambuf_iterator()); +} + +// Inicializa los shaders void Screen::initShaders() { - if (options.video.shaders) + if (shaderSource.empty()) { - const std::string GLSL_FILE = param.game.game_area.rect.h == 256 ? "crtpi_256.glsl" : "crtpi_240.glsl"; - std::ifstream f(Asset::get()->get(GLSL_FILE).c_str()); - std::string source((std::istreambuf_iterator(f)), std::istreambuf_iterator()); - - shader::init(window_, game_canvas_, source.c_str()); + loadShaders(); } + shader::init(window_, game_canvas_, shaderSource.c_str()); } // Calcula el tamaño de la ventana @@ -350,6 +358,8 @@ void Screen::adjustWindowSize() SDL_SetWindowPosition(window_, std::max(NEW_POS_X, WINDOWS_DECORATIONS_), std::max(NEW_POS_Y, 0)); SDL_SetWindowSize(window_, WIDTH, HEIGHT); + + initShaders(); } } diff --git a/source/screen.h b/source/screen.h index 1d6f085..3bdfb51 100644 --- a/source/screen.h +++ b/source/screen.h @@ -44,6 +44,8 @@ private: int fps_counter_ = 0; // Contador de frames por segundo int fps_ = 0; // Frames calculados en el último segundo std::string info_resolution_; // Texto con la informacion de la pantalla + std::string shaderSource; // Almacenar el contenido del archivo GLSL + #ifdef DEBUG bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla #else @@ -113,7 +115,10 @@ private: // Selecciona y ejecuta el método de renderizado adecuado basado en la configuración de shaders void renderScreen(); - // Reinicia los shaders + // Carga el contenido del archivo GLSL + void loadShaders(); + + // Inicializa los shaders void initShaders(); // Calcula el tamaño de la ventana