LWJGL Forum

Programming => LWJGL Documentation => Topic started by: Evan407 on April 14, 2016, 11:12:22

Title: Quick example - how to make a resizable window
Post by: Evan407 on April 14, 2016, 11:12:22
You probably know this code that makes the window resizable
Code: [Select]
GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE,GLFW.GLFW_TRUE);// the window will be resizablebut that doesn't do the whole job because opengl is still using the old window size.

Here is how you can make opengl work with resizing the window.
Make a callback like so
Code: [Select]
  /* for resizing window */
  private static GLFWFramebufferSizeCallback resizeWindow = new GLFWFramebufferSizeCallback(){
@Override
public void invoke(long window, int width, int height){
  GL11.glViewport(0,0,width,height);
  //update any other window vars you might have (aspect ratio, MVP matrices, etc)
}
  };

register the callback during init code

Code: [Select]
GLFW.glfwSetFramebufferSizeCallback(windowHandle, resizeWindow);
And that's it! Now you can resize the window properly.
Title: Re: Quick example - how to make a resizable window
Post by: kappa on April 14, 2016, 11:54:14
Do keep in mind that on some platforms the window size is not always the same as the framebuffer size (such as retina macs).
Title: Re: Quick example - how to make a resizable window
Post by: Kai on April 14, 2016, 13:53:07
It is pretty obvious that you have to reset the viewport when your window resizes.
Nothing new about that. And using the framebuffer resize event with its width/height is also fine under Retina.