Skip to content

Commit

Permalink
feat: add window resizing support (recastnavigation#746)
Browse files Browse the repository at this point in the history
- Add SDL_WINDOW_RESIZABLE flag to enable window resizing
- Handle SDL_WINDOWEVENT_RESIZED event to update window dimensions
- Update OpenGL viewport and projection matrix when window is resized

This change allows users to resize the application window while maintaining
proper aspect ratio and rendering.
  • Loading branch information
vbirds authored Dec 31, 2024
1 parent 03c1101 commit 1f0ce60
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions RecastDemo/Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int main(int /*argc*/, char** /*argv*/)
SDL_GetCurrentDisplayMode(0, &displayMode);

bool presentationMode = false;
Uint32 flags = SDL_WINDOW_OPENGL;
Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
int width;
int height;
if (presentationMode)
Expand Down Expand Up @@ -333,7 +333,22 @@ int 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;
Expand Down

0 comments on commit 1f0ce60

Please sign in to comment.