mirror of
https://github.com/MichaelFisher1997/opengl-cpp.git
synced 2025-04-27 22:23:10 +00:00
make the window re-sizeable
This commit is contained in:
parent
438e9cd03a
commit
4cd0930d2f
19
src/sdl.cpp
19
src/sdl.cpp
@ -21,7 +21,7 @@ SdlWindow::SdlWindow(const char* title, int width, int height)
|
|||||||
SDL_WINDOWPOS_CENTERED,
|
SDL_WINDOWPOS_CENTERED,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
|
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN| SDL_WINDOW_RESIZABLE);
|
||||||
|
|
||||||
if (!m_window) {
|
if (!m_window) {
|
||||||
std::cerr << "Failed to create window: " << SDL_GetError() << std::endl;
|
std::cerr << "Failed to create window: " << SDL_GetError() << std::endl;
|
||||||
@ -102,6 +102,23 @@ SDL_Event event;
|
|||||||
m_isRunning = false; //exit application
|
m_isRunning = false; //exit application
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (event.type == SDL_WINDOWEVENT) {
|
||||||
|
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||||
|
// SDL gives the new width/height in event.window.data1/data2
|
||||||
|
int newWidth = event.window.data1;
|
||||||
|
int newHeight = event.window.data2;
|
||||||
|
|
||||||
|
// Update your internal width/height (if you keep track)
|
||||||
|
m_width = newWidth;
|
||||||
|
m_height = newHeight;
|
||||||
|
|
||||||
|
// Update the OpenGL viewport
|
||||||
|
glViewport(0, 0, newWidth, newHeight);
|
||||||
|
|
||||||
|
// (Optional) If you have a projection matrix, update it here as well
|
||||||
|
// e.g., recalc the aspect ratio for a perspective projection
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user