Search code examples
c++openglprojectionperspectiveorthogonal

Orthogonal & Perspective Projection OpenGL


I am using the code snippet below to switch between orthogonal and perspective projections based on the user's selection. However, irrespective of the user's choice the rendered model is always in orthogonal projection. Could you please let me know what am I missing here.

Orthogonal

Perspective

As seen above, the perspective projection obtained currently is just a zoomed in version of the orthogonal projection.

Thank you.

float fov = 10.0;
float Oleft = -1.0, Oright = 1.0, Obottom = -1.0, Otop = 1.0;

 glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    if(proj_type==0)
        gluPerspective(fov, 1, 0.1, 200);
    else
        glOrtho(Oleft, Oright, Obottom, Otop,0.1,50);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(10, 7, 10, 0, 0, 0, 0, 1, 0);

Solution

  • Orthogonal projection in fact is perspective with FoV = 0.0f. Lowering FoV in perspective makes it looks similar to orthogonal.

    Just move camera close and increase FoV to 45-60 degrees. https://www.packtpub.com/graphics/9781849691727/graphics/1727_04_24.jpg https://drive.google.com/file/d/0B2jjLSK7_nvaVE9WUGZRenJ0bVE/view?usp=sharing