setOrtho for 2D games

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;
    }


openGL starts at the bottom left…



If this is a user contribution (and not a problem/patch) would you please move it to contributions?

for 2d java opengl games, best library to use to is http://slick.cokeandcode.com has tons of great tools and support.

faust said:

for 2d java opengl games, best library to use to is http://slick.cokeandcode.com has tons of great tools and support.


Thanks.
But sometime i use 3D rendering in my 2D game.
basixs said:

If this is a user contribution (and not a problem/patch) would you please move it to contributions?


i guess it should go to user code, since it doesnt need to be in jme.