Hi, recently I'm trying to make a perspective projection matrix for OpenGL. I've been successful so far, the perspectivity itself is working. My problem is with the aspect ratio: when I render a cube, it is stretched when the aspect ratio isn't 1. I've found a similar question in the forum that was marked as solved but that didn't help me. The aspect ratio is correct, it's printed out when resized.
One weird behaviour I encountered is that when the aspect ratio is between 2 and 3, the projection works as expected, so when I toggle between 1.9 and 2 the cube on the screen scales immediately in one direction.
Here is my matrix (I know that it's row major):
float b,t,l,r,n,f,an;
n = 0.1;
f = 100;
an = 3.14/2;
t = tan(an/2) * n;
b = -t;
r = t*ar;
l = -r;
float p[] = {
2*n/(r-l), 0, (r+l)/(r-l), 0,
0, 2*n/(t-b), (t+b)/(t-b), 0,
0, 0, -(f+n)/(f-n), -2*f*n/(f-n),
0, 0, -1, 0
};