From c6d451c7532c4a6bcc436724215104590c15a82c Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 1 Jan 2025 21:36:01 +0100 Subject: [PATCH] Recast: implement editor window resizing Small UX improvement. --- src/naveditor/main.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/naveditor/main.cpp b/src/naveditor/main.cpp index 64d67f3b..1f5ac7f8 100644 --- a/src/naveditor/main.cpp +++ b/src/naveditor/main.cpp @@ -277,7 +277,7 @@ bool sdl_init(SDL_Window*& window, SDL_Renderer*& renderer, int &width, int &hei SDL_DisplayMode displayMode; SDL_GetCurrentDisplayMode(0, &displayMode); - Uint32 flags = SDL_WINDOW_OPENGL | SDL_RENDERER_PRESENTVSYNC; + Uint32 flags = SDL_WINDOW_OPENGL | SDL_RENDERER_PRESENTVSYNC | SDL_WINDOW_RESIZABLE; if (presentationMode) { // Create a fullscreen window at the native resolution. @@ -752,6 +752,24 @@ int not_main(int argc, char** argv) } break; + case SDL_WINDOWEVENT: + { + if (event.window.event == SDL_WINDOWEVENT_RESIZED) + { + // Get the new window size + width = event.window.data1; + height = event.window.data2; + + // Update OpenGL viewport + glViewport(0, 0, width, height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(50.0f, (float)width / (float)height, 1.0f, camr); + } + } + break; + case SDL_QUIT: done = true; break;