Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacement for gluPerspective (with glFrustrum)

Tags:

c++

opengl

How would you convert a gluPerspective function to glFrustum? I have tried to use this equation, but have not had any luck as it did not generate the same image as it did with gluPerspective.

top = tan(fov*3.14159/360.0) * near bottom = -top

left = aspect * bottom right = aspect * top

I can't seem to convert my field of view correctly. Say, for example, if my FOV was 45, what would be the 'top' param in the Frustum call?

like image 879
DorkMonstuh Avatar asked Oct 17 '12 20:10

DorkMonstuh


1 Answers

Here we go - you can use the following method as a replacement of the gluPerspective:

void perspectiveGL( GLdouble fovY, GLdouble aspect, GLdouble zNear, GLdouble zFar )
{
    const GLdouble pi = 3.1415926535897932384626433832795;
    GLdouble fW, fH;

    //fH = tan( (fovY / 2) / 180 * pi ) * zNear;
    fH = tan( fovY / 360 * pi ) * zNear;
    fW = fH * aspect;

    glFrustum( -fW, fW, -fH, fH, zNear, zFar );
}

You can find some more explanation of the code on the nehe page.

like image 111
tiguero Avatar answered Sep 22 '22 09:09

tiguero