glm :: perspective vs gluPerspective

Den*_*sie 3 opengl glm-math

我正在用glm替换我在项目中使用glu方法,我似乎遇到了一个我无法解释的奇怪差异.当我使用此代码使用gluPerspective设置投影矩阵时,我显示:

gluPerspective版本

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70.0f, (GLfloat)w / (GLfloat)h, 0.0001f, 1000.0f);
Run Code Online (Sandbox Code Playgroud)

如果我切换到glm :: perspective,我得到这个:

glm :: perspective版本

glMatrixMode(GL_PROJECTION);
glm::mat4 projectionMatrix = glm::perspective(70.0f, (GLfloat)w / (GLfloat)h, 0.0001f, 1000.0f);
glLoadMatrixf(&projectionMatrix[0][0]);
Run Code Online (Sandbox Code Playgroud)

很明显,我正在渲染的对象现在使用glm版本占用了更多的显示.除了交换glm :: perspective的gluPerspective之外,这两个版本没有其他变化.

我猜我可能做错了什么,因为我的理解是glm :: perspective应该是gluPerspective的替代品.但我不知道到底是什么.

此外,方向的差异是因为对象在场景中旋转.我刚刚在动画中的不同时间截取屏幕截图.

der*_*ass 5

glm现在默认使用弧度,而gluPerspective()使用度数,所以你必须使用

glm::perspective(glm::radians(70.0f), ...);
Run Code Online (Sandbox Code Playgroud)

得到相同的结果gluPerspective(70.0f, ...).