From 98a16148cca2d00f4597ac3539bfb3326797694a Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 25 Oct 2025 11:42:29 +0200 Subject: [PATCH] modificada la logica per a fullscreen y window (tecla F3) --- src/main.cpp | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7750d81..cfca0ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,6 +35,10 @@ static SDL_Window* window_ = nullptr; // Constante por defecto del fragment shader static constexpr const char* DEFAULT_FRAG = "shaders/test.frag.glsl"; +// Tamaño de ventana por defecto +static constexpr int WINDOW_WIDTH = 800; +static constexpr int WINDOW_HEIGHT = 800; + // Vertex shader embebido static const char* vertexShaderSrc = R"glsl( #version 330 core @@ -120,28 +124,22 @@ void getDisplayInfo() { } void setFullscreenMode() { - // SDL3: la API acepta un bool para fullscreen (true = fullscreen desktop / exclusive depending on param) - // En tu repos tienes Options::video.fullscreen (bool), así lo usamos: if (!window_) return; - // Si se pide fullscreen = true, preferimos fullscreen exclusivo si se puede ajustar tamaño if (Options_video.fullscreen) { - // Si conocemos la resolución nativa, forzamos tamaño de ventana y pedimos fullscreen exclusivo - if (display_monitor_.width > 0 && display_monitor_.height > 0) { - SDL_SetWindowSize(window_, display_monitor_.width, display_monitor_.height); - // SDL3 acepta SDL_SetWindowFullscreen(window, true) para fullscreen; algunos drivers pueden ofrecer exclusive/fullscreen desktop. - if (SDL_SetWindowFullscreen(window_, true) != 0) { - // fallback: intentar fullscreen desktop (true funciona como desktop fullscreen en muchas implementaciones) - Logger::info("SDL_SetWindowFullscreen(exclusive) failed, fallback to fullscreen desktop"); - SDL_SetWindowFullscreen(window_, true); // ya es el mismo en SDL3; dejamos registro - } - } else { - // desconocemos resolución, pedimos fullscreen desktop - SDL_SetWindowFullscreen(window_, true); + // Intentar fullscreen + if (!SDL_SetWindowFullscreen(window_, true)) { + // Fallback: volver a modo ventana si falla + Logger::error(std::string("Failed to set fullscreen: ") + SDL_GetError()); + Logger::info("Fallback to windowed mode 800x800"); + SDL_SetWindowFullscreen(window_, false); + SDL_SetWindowSize(window_, WINDOW_WIDTH, WINDOW_HEIGHT); + Options_video.fullscreen = false; } } else { - // volver a ventana + // Volver a modo ventana 800x800 SDL_SetWindowFullscreen(window_, false); + SDL_SetWindowSize(window_, WINDOW_WIDTH, WINDOW_HEIGHT); } } @@ -150,22 +148,12 @@ void toggleFullscreen() { setFullscreenMode(); } -// Manejo de teclas de debug (adaptado a tu estilo) +// Manejo de teclas void handleDebugEvents(const SDL_Event& event) { // evitar repetición de teclas: event.key.repeat disponible en SDL3 if (event.type == SDL_EVENT_KEY_DOWN && static_cast(event.key.repeat) == 0) { switch (event.key.key) { - case SDLK_1: { - Logger::info("Key 1 pressed (action placeholder)"); - break; - } - case SDLK_2: { - static bool deploy_balloons_ = true; - deploy_balloons_ = !deploy_balloons_; - Logger::info(std::string("Toggle balloons: ") + (deploy_balloons_ ? "on" : "off")); - break; - } - case SDLK_F11: { + case SDLK_F3: { toggleFullscreen(); break; } @@ -204,8 +192,7 @@ int main(int argc, char** argv) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); // Crear ventana - int winW = 800, winH = 800; - window_ = SDL_CreateWindow("Shadertoy SDL3 + OpenGL", winW, winH, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); + window_ = SDL_CreateWindow("Shadertoy SDL3 + OpenGL", WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); if (!window_) { Logger::error(std::string("SDL_CreateWindow error: ") + SDL_GetError()); SDL_Quit(); return -1; } // Aplicar fullscreen si el flag estaba activado