I’m running a check every loop to see if the screen has been resized and if so, update the projection matrix but when I resize my screen It dose not respond correctly
public void checkScreen(long window){
IntBuffer w = BufferUtils.createIntBuffer(1);
IntBuffer h = BufferUtils.createIntBuffer(1);
org.lwjgl.glfw.GLFW.glfwGetWindowSize(window, w, h);
int width = w.get(0);
int height = h.get(0);
if(window_width!=width||window_height!=height){
createProjectionMatrix(window);
renderer.updateProjectionMatrix(projectionMatrix);
terrainRenderer.updateProjectionMatrix(projectionMatrix);
}
}
private void createProjectionMatrix(long window){
System.out.println("Updating Screen Size");
IntBuffer w = BufferUtils.createIntBuffer(1);
IntBuffer h = BufferUtils.createIntBuffer(1);
org.lwjgl.glfw.GLFW.glfwGetWindowSize(window, w, h);
int width = w.get(0);
int height = h.get(0);
window_width = width;
window_height = height;
float aspectRatio = (float) width / (float) height;
float y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV/2f))) * aspectRatio);
float x_scale = y_scale / aspectRatio;
float frustum_length = FAR_PLANE - NEAR_PLANE;
projectionMatrix = new Matrix4f();
projectionMatrix.m00 = x_scale;
projectionMatrix.m11 = y_scale;
projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustum_length);
projectionMatrix.m23 = -1;
projectionMatrix.m32 = -((2 * NEAR_PLANE * FAR_PLANE) / frustum_length);
projectionMatrix.m33 = 0;
}