Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: maintaining perspective when window resized

  1. #1
    Guest

    maintaining perspective when window resized

    I am drawing an opengl object into a display window that can be resized. When the user resizes the window it messes up the perspective since the window may no longer be square. I was wondering what is the correct way to handle this problem. If I center the viewport and make sure it is square then there will be areas outside the viewport but still considered the display window that the model will not be able to get panned into.
    Is my only option to always make sure that when a user resizes the window that it maintains a square perspective?

    Thanks in advance,

    Joe

  2. #2
    Intern Contributor
    Join Date
    Mar 2000
    Posts
    94

    Re: maintaining perspective when window resized

    This is how I do it. It seems to work well for me.

    //Change the window size
    void ChangeSize(GLsizei w, GLsizei h) {
    //Prevent divide by zero
    if (h==0) { h = 1;}

    //Affects camera
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    //Set viewport
    glViewport(0,0,w,h);

    //Feild of view, ratio, start distance, end distance
    gluPerspective(45, w / h, 1, 1000);
    //Affects models
    glMatrixMode(GL_MODELVIEW);
    }

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,407

    Re: maintaining perspective when window resized

    better also watch out for the case where the window is higher than it is wide
    eg w/h | | h/w

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •