To resize a window in SDL, first set it with the flag SDL_WINDOW_RESIZABLE
, then detect the resizing window event in a switch and finally call glViewport(0, 0, windowWidth, windowHeight)
.
In the switch
, use the flag SDL_WINDOWEVENT_RESIZED
if you want only the final size of the window or SDL_WINDOWEVENT_SIZE_CHANGED
if you want all the sizes between the first and the final.
To finish, update your own camera with the new window width and height.
m_window = SDL_CreateWindow("INCEPTION",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
m_windowWidth, m_windowHeight,
SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
switch (m_event.type) {
case SDL_WINDOWEVENT:
if (m_event.window.event == SDL_WINDOWEVENT_RESIZED) {
logFileStderr("MESSAGE:Resizing window...\n");
resizeWindow(m_event.window.data1, m_event.window.data2);
}
break;
default:
break;
}
void InceptionServices::resizeWindow(int windowWidth, int windowHeight) {
logFileStderr("MESSAGE: Window width, height ... %d, %d\n", windowWidth, windowHeight);
m_camera->resizeWindow(windowWidth, windowHeight);
glViewport(0, 0, windowWidth, windowHeight);
}
SDL_SetWindowSize
with the current size of your window? – Pyrethrin