And make the other source codes I've seen floating around on the internet for the same functions look a bit messy.
Code: Select all
glmatrix *GL_OrthoMatrix (glmatrix *m, float left, float right, float bottom, float top, float near, float far)
{
float r_l = right - left;
float t_b = top - bottom;
float f_n = far - near;
float tx = - (right + left) / (right - left);
float ty = - (top + bottom) / (top - bottom);
float tz = - (far + near) / (far - near);
glmatrix tmp;
GL_IdentityMatrix (&tmp);
tmp.m16[0] = 2.0f / r_l;
tmp.m16[1] = 0.0f;
tmp.m16[2] = 0.0f;
tmp.m16[3] = tx;
tmp.m16[4] = 0.0f;
tmp.m16[5] = 2.0f / t_b;
tmp.m16[6] = 0.0f;
tmp.m16[7] = ty;
tmp.m16[8] = 0.0f;
tmp.m16[9] = 0.0f;
tmp.m16[10] = 2.0f / f_n;
tmp.m16[11] = tz;
tmp.m16[12] = 0.0f;
tmp.m16[13] = 0.0f;
tmp.m16[14] = 0.0f;
tmp.m16[15] = 1.0f;
GL_MultiplyMatrix (m, &tmp, m);
return m;
}
Untested at the moment. Will be updated should it need adjustment.