glm::perspective 与 gluPerspective

glm::perspective vs gluPerspective

我正在用 glm 替换我在项目中对 glu 方法的使用,我似乎 运行 出现了一个我无法解释的奇怪差异。当我使用这段代码使用 gluPerspective 设置投影矩阵时,我得到了这样的显示:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70.0f, (GLfloat)w / (GLfloat)h, 0.0001f, 1000.0f);

如果我切换到 glm::perspective,我会得到:

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

很明显,我正在渲染的对象现在使用 glm 版本占用了更多的显示空间。除了将 gluPerspective 换成 glm::perspective.

之外,这两个版本没有其他变化

我猜我可能做错了什么,因为我的理解是 glm::perspective 应该是 gluPerspective 的替代品。但我现在还不知道那是什么。

此外,方向的不同是因为物体在场景中被旋转了。我刚刚在动画中的不同时间截取了屏幕截图。

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

glm::perspective(glm::radians(70.0f), ...);

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