当调用glMatrixMode() [英] When to call glMatrixMode()

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

问题描述

大多数的OpenGL ES教程为Android,我跟着有onSurfaceChanged()函数是这样的:

Most OpenGL ES tutorials for Android I've followed has its onSurfaceChanged() function like this:

public void onSurfaceChanged( GL10 gl, int width, int height ) {
    gl.glViewport( 0, 0, width, height );
    gl.glMatrixMode( GL10.GL_PROJECTION );
    gl.glLoadIdentity();
    GLU.gluPerspective( gl, 45.0f, ( ( float )width / ( float )height ), 0.1f, 100.0f );
    gl.glMatrixMode( GL10.GL_MODELVIEW );
    gl.glLoadIdentity();
}

然而,什么是分组在这里?必须glMatrixMode()glViewport后叫什么名字?而且必须在glLoadIdentity()被调用后右glMatrixMode()?

However, what is the grouping here? Must glMatrixMode() be called after glViewport? And must a glLoadIdentity() be called right after glMatrixMode()?

我已经编码为满之前OpengGL,并在我的老codeS我第一次叫glMatrixMode(),然后gluPerspective和最后一个glLoadIdentity()。仿佛一组第一组什么矩阵应该用于gluPerspective()和最后一组glIdentity()来完成它。

I've been coding for "full" OpengGL before, and in my old codes I first called glMatrixMode(), then gluPerspective and last glLoadIdentity(). As if one first set what matrix should be used for gluPerspective() and last set glIdentity() to finish it.

什么是调用glMatrixMode(),glIdentity()和gluPerspective()以正确的顺序 - 为什么?是否有设置glMatrixMode的OpenGL和OpenGL ES之间的差异()?

What is the correct order for calling glMatrixMode(), glIdentity() and gluPerspective() - and why? Are there differences between OpenGL and OpenGL ES for setting up glMatrixMode()?

推荐答案

glViewport()是完全独立于矩阵的变换栈和可以在任何时间被调用。

glViewport() is completely independent of the matrix transform stacks and can be called at any time.

glLoadIdentity()通常立即矩阵模式改变后,所以你开始新鲜如果你愿意叫。矩阵变换如gluPerspective(),glOrtho(),glFrustum(),glRotate(),glMultMatrix(),glTranslate()是累积的操作,因为它们汇总,让您描述复杂的3D世界空间变换或描述你的OpenGL观看卷。例如:如果我想翻译在+ X方向的立方体,然后绕Z轴旋转我发出后跟一个glTranslate()

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()清除(当前矩阵模式)有这么跟随gluPerspective()由glLoadIdentity()单位矩阵矩阵相当于给glLoadIdentity一个()调用。换句话说,该序列是无意义的。

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.

扭转这些因为gluPerspective()将乘透视当前矩阵变换的顺序。如果当前矩阵是一种身份,然后乘只会导致gluPerspective()矩阵变换这是你想要为你的投影矩阵模式时的99%时的角度观看。

Reverse the order of these because gluPerspective() will multiply the current matrix by the perspective transform. If the current matrix is identity then the multiply will simply result in the gluPerspective() matrix transform which is what you want for your projection matrix mode 99% of the time when perspective viewing.

有到glMatrixMode的)行为(或如何将这些矩阵函数修改GL矩阵状态。

There are no differences between OpenGL and OpenGL ES with respect to the behavior of glMatrixMode() or how these matrix functions modify GL matrix state.

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

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