I’m having issues when resizing my window with glfwSetWindowSize(). When I create my window context with glfwCreateWindow(width, height, “MyWindow”, NULL, NULL) everything looks fine, but after calling glfwSetWindowSize(newWidth, newHeight) the window aspect ratio looks wrong, the image looks stretched. I’ve also tried using glfwSetWindowAspectRatio(newWidth, newHeight) after calling glfwSetWindowSize(newWidth, newHeight) but this seems to have no effect.
If instead of resizing the window context I delete it with glfwDestroyWindow() and then re-create it with glfwCreateWindow(newWidth, newHeight) the window looks correct, but this approach is far too slow, since the OpenGL state has to be re-initialized after calling glfwCreateWindow(), and the window is resized frequently during rendering.
For example, the following works but is far to slow…
void OnWindowResize() {
glfwDestroyWindow(m_window);
m_window = glfwCreateWindow(newWidth, newHeight, "MyWindow", NULL, NULL);
glfwMakeContextCurrent(m_window);
InitOpenglState();
}
This runs much faster, but the image aspect ratio looks wrong…
void OnWindowResize() {
glfwSetWindowSize(m_window, newWidth, newHeight);
glfwSetWindowAspectRatio(m_window, newWidth, newHeight);
}
Does anyone know what I am doing wrong here? How do I resize the window without messing up the aspect ratio? Thanks for the help!
I’m using GLFW version 3.2.1 on Windows 10 with a GeForce GTS 960M driver 417.35