I\'m trying to read some OpenGL tutorials on the net. the problem is that I found some old ones that use gluPerspective()
. gluPerspective was deprecated in Open
This is a modified version of Dan's function, with simplified calculations from Unspecified Behavior.
void buildPerspProjMat(GLfloat *m, GLfloat fov, GLfloat aspect,
GLfloat znear, GLfloat zfar){
GLfloat h = tan(fov);
GLfloat w = h / aspect;
GLfloat depth = znear - zfar;
GLfloat q = (zfar + znear) / depth;
GLfloat qn = 2 * zfar * znear / depth;
m[0] = w; m[1] = 0; m[2] = 0; m[3] = 0;
m[4] = 0; m[5] = h; m[6] = 0; m[7] = 0;
m[8] = 0; m[9] = 0; m[10] = q; m[11] = -1;
m[12] = 0; m[13] = 0; m[14] = qn; m[15] = 0;
}