Android – flip the Y axis in OpenGL es?
I try to draw orthogonal mode with OpenGL es, and the point (0,0) is in the lower left corner of the screen. However, I want to put it in the upper left corner
This is where I set it in the Android App:
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);
}
I have tried several ways to change the above calls, including:
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);
I've also tried to use viewports to no avail:
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);
}
Also, the viewport settings I tried to use are invalid:
gl.glViewport(0, 0, width, height);
gl.glViewport(0, 0, width, -height);
gl.glViewport(0, height, width, 0);
gl.glViewport(0, -height, width, 0);
Any clues about how to place a point (0,0) in the upper left corner of the screen? thank you!
resolvent:
how:
glViewport(0, 0, width, height);
gluOrtho2D(0, width, height, 0);
The glviewport call sets the viewport only in the device coordinates. This is your window system. The glortho (gluortho2d) call sets the coordinate mapping from the world coordinates to the device coordinates
See:
> http://pyopengl.sourceforge.net/documentation/manual/gluOrtho2D.3G.html > http://www.opengl.org/sdk/docs/man/xhtml/glViewport.xml