Flip Y-axis in OpenGL ES?
我正试图用OpenGLES以正交模式绘制,点(0,0)在屏幕的左下角。不过,我想把它放在左上角。
以下是我在Android应用程序中进行设置的地方:
1 2 3 4 5 6 | public void onSurfaceChanged(final GL10 gl, final int width, final int height) { assert gl != null; // use orthographic projection (no depth perception) GLU.gluOrtho2D(gl, 0, width, 0, height); } |
我尝试通过多种方式更改上述呼叫,包括:
1 2 3 4 | GLU.gluOrtho2D(gl, 0, width, 0, height); GLU.gluOrtho2D(gl, 0, width, 0, -height); GLU.gluOrtho2D(gl, 0, width, height, 0); GLU.gluOrtho2D(gl, 0, width, -height, 0); |
号
我还尝试使用视区进行播放,但没有效果:
1 2 3 4 5 6 7 8 9 10 11 | public void onSurfaceChanged(final GL10 gl, final int width, final int height) { assert gl != null; // define the viewport gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); // use orthographic projection (no depth perception) GLU.gluOrtho2D(gl, 0, width, 0, height); } |
我再次尝试使用视区设置,但没有效果:
1 2 3 4 | gl.glViewport(0, 0, width, height); gl.glViewport(0, 0, width, -height); gl.glViewport(0, height, width, 0); gl.glViewport(0, -height, width, 0); |
。
有关于如何将点(0,0)指向屏幕左上角的线索吗?谢谢!
怎么样:
1 2 | glViewport(0, 0, width, height); gluOrtho2D(0, width, height, 0); |
glviewport调用仅在设备坐标中设置视区。那是你的窗户系统。glortho(gluortho2d)调用设置从世界坐标到设备坐标的坐标映射。
见:
- http://pyopengl.sourceforge.net/documentation/manual/gluortho2d.3g.html
- http://www.opengl.org/sdk/docs/man/xhtml/glviewport.xml
埃多克斯1〔0〕怎么样?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | double fov = 60.f * 3.1415f/180.f; float aspect = (float) width / (float) height; float zNear = 0.01f; float zFar = 3000.0f; // cotangent float f = (float) (Math.cos(fov*0.5f) / Math.sin(fov*0.5f)); float perspMtx[] = new float[16]; // columns first for( int i=0; i<16; ++i ) perspMtx[i] = 0.0f; perspMtx[0] = f / aspect; perspMtx[5] = -f; // flip Y? <- THIS IS YOUR ANSWER perspMtx[10] = (zFar+zNear) / (zNear - zFar); perspMtx[11] = -1.0f; perspMtx[14] = 2.0f*(zFar*zNear) / (zNear - zFar); gl.glMultMatrixf(perspMtx, 0); |
这为我解决了问题,应该类似于正交投影矩阵