gluPerspective was removed in OpenGL 3.1, any replacements?

前端 未结 5 696
耶瑟儿~
耶瑟儿~ 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:26

    This is a modified version of Dan's function, with simplified calculations from Unspecified Behavior.

    void buildPerspProjMat(GLfloat *m, GLfloat fov, GLfloat aspect,
    GLfloat znear, GLfloat zfar){
    
      GLfloat h = tan(fov);
      GLfloat w = h / aspect;
      GLfloat depth = znear - zfar;
      GLfloat q = (zfar + znear) / depth;
      GLfloat qn = 2 * zfar * znear / depth;
    
      m[0]  = w;  m[1]  = 0;  m[2]  = 0;  m[3]  = 0;
    
      m[4]  = 0;  m[5]  = h;  m[6]  = 0;  m[7]  = 0;
    
      m[8]  = 0;  m[9]  = 0;  m[10] = q;  m[11] = -1;
    
      m[12] = 0;  m[13] = 0;  m[14] = qn;  m[15] = 0;
    }
    

提交回复
热议问题