I’m just trying to create an orthographic projection matrix, but I am having some serious problems here. I do not have access to glOrtho, so please don’t tell me to use that. I am using LWJGL, and the Matrix4f class is column major so I am pretty sure that this code should not be behaving like it is
float left = 0;
float right = 1;
float bottom = 1;
float top = 0;
float near = 0f;
float far = 100f;
projectionMatrix.m00 = 2 / (right - left);
projectionMatrix.m11 = 2 / (top - bottom);
projectionMatrix.m22 = -2 / (far - near);
projectionMatrix.m30 = -((right + left) / (right - left));
projectionMatrix.m31 = -((top + bottom) / (top - bottom));
projectionMatrix.m32 = -((far + near) / (far - near));
I can’t upload an image to this post because this account is new, but it draws my quad in the top left of the screen with the bottom right of the quad in the center of the screen.
When I try to change the values so that it is correctly setup to my screen, as shown below, nothing shows up at all.
float left = 0;
float right = Engine.windowWidth;
float bottom = Engine.windowHeight;
float top = 0;
float near = 0f;
float far = 100f;
projectionMatrix.m00 = 2 / (right - left);
projectionMatrix.m11 = 2 / (top - bottom);
projectionMatrix.m22 = -2 / (far - near);
projectionMatrix.m30 = -((right + left) / (right - left));
projectionMatrix.m31 = -((top + bottom) / (top - bottom));
projectionMatrix.m32 = -((far + near) / (far - near));
Changing the right and bottom values slowly move the quad off the screen to the left. I have been struggling with this for a while now and I feel like it’s something really stupid that I am missing.