Ja funciona correctament el canvi de tamany de finestra, el shaders, i la pantalla completa

This commit is contained in:
2025-03-13 22:51:51 +01:00
parent d1db4f253e
commit 9692d01b42
3 changed files with 23 additions and 19 deletions

View File

@@ -289,17 +289,6 @@ bool Director::initSDL()
} }
else 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 // Obtiene información sobre la pantalla
SDL_DisplayMode DM; SDL_DisplayMode DM;
SDL_GetCurrentDisplayMode(0, &DM); SDL_GetCurrentDisplayMode(0, &DM);

View File

@@ -41,6 +41,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
SDL_DisplayMode DM; SDL_DisplayMode DM;
SDL_GetCurrentDisplayMode(0, &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"; 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 // Inicializa los shaders
initShaders(); initShaders();
@@ -101,6 +102,8 @@ void Screen::setVideoMode(ScreenVideoMode video_mode)
{ {
SDL_SetWindowFullscreen(window_, static_cast<Uint32>(options.video.mode)); SDL_SetWindowFullscreen(window_, static_cast<Uint32>(options.video.mode));
} }
initShaders();
} }
// Camibia entre pantalla completa y ventana // 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<char>(f)), std::istreambuf_iterator<char>());
}
// Inicializa los shaders
void Screen::initShaders() 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"; loadShaders();
std::ifstream f(Asset::get()->get(GLSL_FILE).c_str());
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
shader::init(window_, game_canvas_, source.c_str());
} }
shader::init(window_, game_canvas_, shaderSource.c_str());
} }
// Calcula el tamaño de la ventana // 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_SetWindowPosition(window_, std::max(NEW_POS_X, WINDOWS_DECORATIONS_), std::max(NEW_POS_Y, 0));
SDL_SetWindowSize(window_, WIDTH, HEIGHT); SDL_SetWindowSize(window_, WIDTH, HEIGHT);
initShaders();
} }
} }

View File

@@ -44,6 +44,8 @@ private:
int fps_counter_ = 0; // Contador de frames por segundo int fps_counter_ = 0; // Contador de frames por segundo
int fps_ = 0; // Frames calculados en el último segundo int fps_ = 0; // Frames calculados en el último segundo
std::string info_resolution_; // Texto con la informacion de la pantalla std::string info_resolution_; // Texto con la informacion de la pantalla
std::string shaderSource; // Almacenar el contenido del archivo GLSL
#ifdef DEBUG #ifdef DEBUG
bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla bool show_debug_info_ = false; // Indica si ha de mostrar/ocultar la información de la pantalla
#else #else
@@ -113,7 +115,10 @@ private:
// Selecciona y ejecuta el método de renderizado adecuado basado en la configuración de shaders // Selecciona y ejecuta el método de renderizado adecuado basado en la configuración de shaders
void renderScreen(); void renderScreen();
// Reinicia los shaders // Carga el contenido del archivo GLSL
void loadShaders();
// Inicializa los shaders
void initShaders(); void initShaders();
// Calcula el tamaño de la ventana // Calcula el tamaño de la ventana