modificada la logica per a fullscreen y window (tecla F3)

This commit is contained in:
2025-10-25 11:42:29 +02:00
parent f86da327ff
commit 98a16148cc

View File

@@ -35,6 +35,10 @@ static SDL_Window* window_ = nullptr;
// Constante por defecto del fragment shader // Constante por defecto del fragment shader
static constexpr const char* DEFAULT_FRAG = "shaders/test.frag.glsl"; 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 // Vertex shader embebido
static const char* vertexShaderSrc = R"glsl( static const char* vertexShaderSrc = R"glsl(
#version 330 core #version 330 core
@@ -120,28 +124,22 @@ void getDisplayInfo() {
} }
void setFullscreenMode() { 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; if (!window_) return;
// Si se pide fullscreen = true, preferimos fullscreen exclusivo si se puede ajustar tamaño
if (Options_video.fullscreen) { if (Options_video.fullscreen) {
// Si conocemos la resolución nativa, forzamos tamaño de ventana y pedimos fullscreen exclusivo // Intentar fullscreen
if (display_monitor_.width > 0 && display_monitor_.height > 0) { if (!SDL_SetWindowFullscreen(window_, true)) {
SDL_SetWindowSize(window_, display_monitor_.width, display_monitor_.height); // Fallback: volver a modo ventana si falla
// SDL3 acepta SDL_SetWindowFullscreen(window, true) para fullscreen; algunos drivers pueden ofrecer exclusive/fullscreen desktop. Logger::error(std::string("Failed to set fullscreen: ") + SDL_GetError());
if (SDL_SetWindowFullscreen(window_, true) != 0) { Logger::info("Fallback to windowed mode 800x800");
// fallback: intentar fullscreen desktop (true funciona como desktop fullscreen en muchas implementaciones) SDL_SetWindowFullscreen(window_, false);
Logger::info("SDL_SetWindowFullscreen(exclusive) failed, fallback to fullscreen desktop"); SDL_SetWindowSize(window_, WINDOW_WIDTH, WINDOW_HEIGHT);
SDL_SetWindowFullscreen(window_, true); // ya es el mismo en SDL3; dejamos registro Options_video.fullscreen = false;
}
} else {
// desconocemos resolución, pedimos fullscreen desktop
SDL_SetWindowFullscreen(window_, true);
} }
} else { } else {
// volver a ventana // Volver a modo ventana 800x800
SDL_SetWindowFullscreen(window_, false); SDL_SetWindowFullscreen(window_, false);
SDL_SetWindowSize(window_, WINDOW_WIDTH, WINDOW_HEIGHT);
} }
} }
@@ -150,22 +148,12 @@ void toggleFullscreen() {
setFullscreenMode(); setFullscreenMode();
} }
// Manejo de teclas de debug (adaptado a tu estilo) // Manejo de teclas
void handleDebugEvents(const SDL_Event& event) { void handleDebugEvents(const SDL_Event& event) {
// evitar repetición de teclas: event.key.repeat disponible en SDL3 // evitar repetición de teclas: event.key.repeat disponible en SDL3
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 0) { if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 0) {
switch (event.key.key) { switch (event.key.key) {
case SDLK_1: { case SDLK_F3: {
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: {
toggleFullscreen(); toggleFullscreen();
break; break;
} }
@@ -204,8 +192,7 @@ int main(int argc, char** argv) {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
// Crear ventana // Crear ventana
int winW = 800, winH = 800; window_ = SDL_CreateWindow("Shadertoy SDL3 + OpenGL", WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
window_ = SDL_CreateWindow("Shadertoy SDL3 + OpenGL", winW, winH, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
if (!window_) { Logger::error(std::string("SDL_CreateWindow error: ") + SDL_GetError()); SDL_Quit(); return -1; } if (!window_) { Logger::error(std::string("SDL_CreateWindow error: ") + SDL_GetError()); SDL_Quit(); return -1; }
// Aplicar fullscreen si el flag estaba activado // Aplicar fullscreen si el flag estaba activado