Upgrade to Pro — share decks privately, control downloads, hide ads and more …

4. Window resize

4. Window resize

Tatsuya Yatagawa

April 12, 2021

More Decks by Tatsuya Yatagawa

Other Decks in Technology


  1. What happens after window resize? n Let us change the

    window size! Computer Graphics Course @Waseda University ?
  2. Why not shown correctly? n Size parameters in source code

    is not changed n WIN_WIDTH, WIN_HEIGHT are not automatically updated! → Detect window resize event, and update parameters. Computer Graphics Course @Waseda University
  3. Resize event in GLFW n Enable event detection n glfwSetWindowSizeCallback

    n 1st parameter: Window for which event is detected (GLFWwindow*) n 2nd parameter: Pointer to callback function n Code snippet Computer Graphics Course @Waseda University (Assume callback is named “resizeGL”)
  4. Define callback function n Code n Note n Arguments to

    callback is fixed for each event type. n For window resize, it receives window pointer, new window width, and new window height. n Substitute new width and height to globally visible parameters. n Update window size managed by GLFW, and viewport. Computer Graphics Course @Waseda University
  5. Advanced setting (for Apple Retina) n Window size is not

    always in pixels n Obtain pixel-level window size from GLFW Computer Graphics Course @Waseda University Red part gives pixel-level window width and height. → Objects shown up correctly in both Windows and Mac
  6. Practice n Practice 4-1 n Revise the program for window

    resizing such that the object is scaled property in both the cases where the window shape is landscape and portrait. n Hint: make your own routine of calculating projection matrix in such a case. Computer Graphics Course @Waseda University