I made a projection function for 2D games and interface overlay.
<setOrtho function - original>
The origin(0,0) is left ★bottom★ of the screen.
The origin bottom is more trouble than making 2D Games. (thinking about turn upside down)
Hasnot depth(Z) buffer.
<setOrthoOriginLT function>
The origin(0,0) is left ★top★ of the screen.
Has depth(Z) buffer. (0~65535) - Sometimes using depth buffer in 2D game.
/**
* <code>setOrtho</code> sets the display system to be in orthographic
* mode. If the system has already been set to orthographic mode a
* <code>JmeException</code> is thrown. The origin (0,0) is the top
* left of the screen.
*/
public void setOrthoOriginLT() {
final GL gl = GLU.getCurrentGL();
if (inOrthoMode) {
throw new JmeException("Already in Orthographic mode.");
}
// set up ortho mode
RendererRecord matRecord = (RendererRecord) DisplaySystem
.getDisplaySystem().getCurrentContext().getRendererRecord();
matRecord.switchMode(GL.GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadIdentity();
Matrix4f mat = new Matrix4f(
2.0f / width, 0, 0, 0,
0, -2.0f / height, 0, 0,
0, 0, 0.000015f, 0,
-1, 1, 0, 1);
gl.glLoadMatrixf( mat.toFloatBuffer() );
matRecord.switchMode(GL.GL_MODELVIEW);
gl.glPushMatrix();
gl.glLoadIdentity();
inOrthoMode = true;
}