gluPerspective was removed in OpenGL 3.1, any replacements?

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

    Use GLM.

    glm::mat4 projection = glm::perspective(
      // FOV & aspect
      60.0f, 16.0f / 10.0f, 
      // Near and far planes
      0.001f, 1000f);
    
    // If you're using the now deprecated matrix stacks
    glMatrixMode(GL_PROJECTION);
    glLoadMatrixf(glm::value_ptr(projection));
    
    // if you're using the new shader based pipelines
    GLint projectionUniformLocation = ...;
    glUniformMatrix4fv(projectionUniformLocation, 1, GL_FALSE, 
      glm::value_ptr(projection));
    

    Note, if you have GLM_FORCE_RADIANS defined then you should use radians in the perspective function, not degrees...

    glm::mat4 projection = glm::perspective(
      // FOV & aspect
      PI / 3.0f, 16.0f / 10.0f, 
      // Near and far planes
      0.001f, 1000f);
    

提交回复
热议问题