Perspective projection stretches at -certain- aspect ratios?

(Stretches horizontally, that is.)

I’ve been developing my demo in 640x480, and all along it has looked a little stretched (my cube is maybe 10-15% broader than it is tall) when running in a window. My desktop native res is 1680x1050, FWIW.

After spending a while checking my manually-constructed perspective projection matrix, and thinking I needed a post-step to convert to window coordinates – till I read somewhere that this is done in the pipeline between the vertex and fragment shaders (not sure if this is true).

So I changed the window resolution, and suddenly, at 640x320, everything looks fine. So does it at any 2:1 ratio. (1:1 goes without saying.) If I set the window to 840x525 (half my desktop res in x and y), I get a very wide, spinning cube (looks about 2:1).

What is going on? FWIW, here’s my perspective projection:



    public Matrix4 getStandardProjectionMatrix(float fovYDeg, float aspectRatio, float near, float far)
    {
        Matrix4 result = new Matrix4();
        
        float fovYRad = fovYDeg * 180f / (float)PI; 
        float d = 1f/(float)(tan(fovYRad / 2));


        result.val[Matrix4.M00] = d / aspectRatio;
        result.val[Matrix4.M11] = d;
        result.val[Matrix4.M22] = (far + near) / (near - far);
        result.val[Matrix4.M23] = (2 * far * near) / (near - far);
        result.val[Matrix4.M32] = -1f;
        
        return result;
    }

    private void render()
    {    
        ...
        projectionMatrix = getStandardProjectionMatrix(60f, DISPLAY_WIDTH/DISPLAY_HEIGHT, 0.1f, 10000f);
        mvpMatrix = projectionMatrix.mul(viewMatrix.mul(modelMatrix));
        ...
    }


Sorted – it was this.