I see a couple of problems. First, the argument tan () must be converted from degrees to radians.
Secondly, the formula for perspective projection in OpenGL is slightly different from yours. As stated here , it uses the โnearโ in the denominator instead of your โfarโ. Numerators are also different. Changing your function a bit and translating it from Java to C, I created a projection matrix identical to the one specified by gluPerspective (), with the following:
static void my_PerspectiveFOV (double fov, double aspect, double near, double far, double * mret) {
double D2R = M_PI / 180.0;
double yScale = 1.0 / tan (D2R * fov / 2);
double xScale = yScale / aspect;
double nearmfar = near - far;
double m [] = {
xScale, 0, 0, 0,
0, yScale, 0, 0,
0, 0, (far + near) / nearmfar, -1,
0, 0, 2 * far * near / nearmfar, 0
};
geom_matrix4_copy (m, mret);
}
source share