http://puu.sh/n3am6/11935f9c68.png
I am trying to adapt my current (incomplete) 3d engine to work with orthographic projection/2D games but, as above, it doesnt quite render properly. That is meant to be a red square(square data given below):
float[] vertices = new float[]{
0, 10, 0,
0, 0, 0,
10, 0, 0,
10, 10, 0
};
int[] indices = new int[]{
0, 1, 2, 2, 3, 0
};
Mesh mesh = new Mesh();
mesh.setIndices(indices);
mesh.setVertices(vertices);
Material material = new Material(new Color(1f, 0f, 0f), 0.0f, false);
mesh.setMaterial(material);
orthoCube = new GameObject();
orthoCube.setMesh(mesh);
orthoCube.getTransform().setPosition(new Vector3f(100, 100, 0.5f));
orthoCube.getTransform().setScale(1.0f);
And here is how i am creating the projection matrix(parameters are: left, right, up, down, near, far):
Projection.createOrthogonal(0, Window.WIDTH, Window.HEIGHT, 0, 1, -100)
That method is here(using JOML):
public static Matrix4f createOrthogonal(float left,float right,float bottom,float top,float near,float far){
Matrix4f orthogonal = new Matrix4f();
orthogonal.m00 = 2/(right - left);
orthogonal.m11 = 2/(top - bottom);
orthogonal.m22 = -2/(far - near);
orthogonal.m23 = (far+near)/(far - near);
orthogonal.m03 = (right+left)/(right -left);
orthogonal.m13 = (top + bottom)/(top-bottom);
return orthogonal;
}
I thought that this should work.
Any suggestions?