gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:00:47 24 4
gpt4 key购买 nike

我正在阅读一本关于 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com