c - 为什么每次调用 glMatrixMode 后都必须调用 glLoadIdentity?

标签 c opengl

我正在阅读一本关于 OpenGL、SDL 的书,并且已经阅读了一些 OpenGL 文档。我也读过这篇文章:What does glLoadIdentity() do in OpenGL?

我正在掌握 glLoadIdentity() 的作用,以及为什么在一般意义上使用它(将当前矩阵返回到其原始状态)。我不知道的是为什么我要把它恢复到原来的状态。例如:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(0.0f, 640, 480, 0.0f, -1.0f, 1.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

我不太确定为什么每次调用 glMatrixMode 后都必须调用 glLoadIdentity()。

最佳答案

When to call glMatrixMode() -- 第一个答案试图解释:

glLoadIdentity() is typically called immediately after a matrix mode change so you are starting "fresh" if you will. Matrix transforms such as the gluPerspective(), glOrtho(), glFrustum(), glRotate(), glMultMatrix(), glTranslate() are cumulative operations because they aggregate to allow you to describe complex 3D world space transforms or to describe your OpenGL viewing volume. Example: if I want a cube translated in the +X direction then rotated around the Z axis I issue a glRotate() followed by a glTranslate().

glLoadIdentity() wipes out the matrix (of the current matrix mode) with the identity matrix so following a gluPerspective() by glLoadIdentity() is equivalent to a single call to glLoadIdentity(). In other words, that sequence is nonsensical.

关于c - 为什么每次调用 glMatrixMode 后都必须调用 glLoadIdentity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6949954/

相关文章:

c++ - OpenGL 将纹理应用于曲面 segmentation

C Socket,验证服务器

c - 这是指向数组开头的指针的指针吗?

c++ - ubuntu 上的“GLEWContext 没有命名类型”错误

python - 从 Python 调用 OpenGL 扩展

c++ - 检查一个点是否在 "gluPartialDisk"内(OpenGL 和 C++)

image - 任何图像文件格式是否支持负 float ?

c - 编译C和nasm时传递参数

c - 释放函数内部的指针,并在 main 中使用它

java - 从 C 代码调用 Java