在OpenGL ES中翻转Y轴?

Mat*_*ins 4 graphics android opengl-es

我试图用OpenGL ES绘制正交模式,点(0,0)位于屏幕的左下角.但是,我想把它放在左上角.

这是我在Android应用中设置的地方:

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);
}
Run Code Online (Sandbox Code Playgroud)

我尝试过多种方式更改上述调用,包括:

    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);
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用视口无济于事:

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);
}
Run Code Online (Sandbox Code Playgroud)

而且,我尝试使用视口设置无效:

    gl.glViewport(0, 0, width, height);
    gl.glViewport(0, 0, width, -height);
    gl.glViewport(0, height, width, 0);
    gl.glViewport(0, -height, width, 0);
Run Code Online (Sandbox Code Playgroud)

关于如何将点(0,0)放到屏幕左上角的任何线索?谢谢!

rio*_*oki 9

怎么样:

glViewport(0, 0, width, height);
gluOrtho2D(0, width, height, 0);
Run Code Online (Sandbox Code Playgroud)

glViewport调用仅在设备坐标中设置视口.这是你的窗口系统.glOrtho(gluOrtho2D)调用设置从世界坐标到设备坐标的坐标映射.

看到: