gluPerspective was removed in OpenGL 3.1, any replacements?

前端 未结 5 722
耶瑟儿~
耶瑟儿~ 2020-12-23 11:50

I\'m trying to read some OpenGL tutorials on the net. the problem is that I found some old ones that use gluPerspective(). gluPerspective was deprecated in Open

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-23 12:22

    Copied from one of my older projects:

    // The following code is a fancy bit of math that is eqivilant to calling:
    // gluPerspective( fieldOfView/2.0f, width/height , 0.1f, 255.0f )
    // We do it this way simply to avoid requiring glu.h
    GLfloat zNear = 0.1f;
    GLfloat zFar = 255.0f;
    GLfloat aspect = float(width)/float(height);
    GLfloat fH = tan( float(fieldOfView / 360.0f * 3.14159f) ) * zNear;
    GLfloat fW = fH * aspect;
    glFrustum( -fW, fW, -fH, fH, zNear, zFar );
    

提交回复
热议问题