The cube stays squished height wise when resizing window height.
Window.java(where projection is set in init() method)
Projection.updatePerspective(FOV, getWidth() / getHeight(), Z_NEAR, Z_FAR);
Projection.java(Note: Matrix4f class is from JOML Library)
public class Projection {
public static Matrix4f perspective;
public static Matrix4f orthogonal;
public static void updatePerspective(float fov, float aspect, float zNear, float zFar){
Matrix4f matrix = new Matrix4f();
matrix.identity();
matrix.perspective(fov, aspect, zNear, zFar);
perspective = matrix;
}
public static void updateOrthogonal(float left,float right,float bottom,float top,float near,float far){
Matrix4f matrix = new Matrix4f().identity();
matrix.m00 = 2/(right - left);
matrix.m11 = 2/(top - bottom);
matrix.m22 = -2/(far - near);
matrix.m32 = (far+near)/(far - near);
matrix.m30 = (right+left)/(right -left);
matrix.m31 = (top + bottom)/(top-bottom);
orthogonal = matrix;
}
}
Then every render iteration projection is sent to shader:
public void render(Window window, Camera camera, List<GameObject> renderList) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// LEAVE
//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
Matrix4f viewMatrix = MatrixUtils.getViewMatrix(camera);
shaderProgram.bind();
shaderProgram.setUniform("projectionMatrix", Projection.perspective);
//shaderProgram.setUniform("camera_pos", camera.getPosition());
System.out.println("0");
shaderProgram.setUniform("texture_sampler", 0);
for(GameObject gameObject : renderList){
Matrix4f modelViewMatrix = MatrixUtils.getModelViewMatrix(gameObject.getTransform(), viewMatrix);
shaderProgram.setUniform("modelViewMatrix", modelViewMatrix);
shaderProgram.setUniform("material", gameObject.getMesh().getMaterial());
gameObject.getMesh().render();
}
System.out.println("6");
shaderProgram.unbind();
System.out.println("7");
}