OpenGL glMatrixMode(GL_PROJECTION)和glMatrixMode(GL_MODELVIEW) [英] OpenGL glMatrixMode(GL_PROJECTION) vs glMatrixMode(GL_MODELVIEW)

查看:117
本文介绍了OpenGL glMatrixMode(GL_PROJECTION)和glMatrixMode(GL_MODELVIEW)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

glRotatef()放在 glMatrixMode(GL_PROJECTION);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glRotatef(red, green, blue);

并将 glRotatef()放在 glMatrixMode(GL_MODELVIEW);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(red, green, blue);

推荐答案

来自文档:

glMatrixMode()指定哪个矩阵是当前矩阵.

glMatrixMode() specifies which matrix is the current matrix.

GL_MODELVIEW - Applies subsequent matrix operations to the modelview matrix stack.

GL_PROJECTION - Applies subsequent matrix operations to the projection matrix stack.

它们是什么意思?

如果将当前矩阵模式设置为投影(例如glMatrixMode(GL_PROJECTION)),则应更改投影矩阵.当然,其中之一有望成为下一行:

If you set current matrix mode as projection (e.g glMatrixMode(GL_PROJECTION)), you are expected to change your projection matrix. Naturally, one of them are expected to be next line :

对于正投影:

  • glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);
  • gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top);
  • glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);
  • gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top);

对于透视投影:

  • void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);
  • void gluPerspective(GLdouble fov, GLdouble aspect, GLdouble near, GLdouble far);
  • void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);
  • void gluPerspective(GLdouble fov, GLdouble aspect, GLdouble near, GLdouble far);

如果您将当前矩阵模式设置为modelView(例如glMatrixMode(GL_MODELVIEW)),则表示我在modelview矩阵中,并且我可以应用基本操作来转换对象,例如:

If you set current matrix mode as modelView(e.g glMatrixMode(GL_MODELVIEW)), you are saying that I am in the modelview matrix and I can apply basic operations to transform my objects like :

  • glRotatef();
  • glTranslatef();
  • glScalef();
  • glRotatef();
  • glTranslatef();
  • glScalef();

在您的问题中,如果在gl_projection之后而不是gl_modelview之后使用rotatef,则会旋转投影矩阵,这会破坏投影矩阵.

In your question if you use rotatef after gl_projection instead of gl_modelview, you rotate your projection matrix which would corrupt your projection matrix.

`

这篇关于OpenGL glMatrixMode(GL_PROJECTION)和glMatrixMode(GL_MODELVIEW)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆