The glOrtho function multiplies the current matrix by an orthographic matrix.
void WINAPI glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar );
The coordinates for the left vertical clipping plane.
The coordinates for theright vertical clipping plane.
The coordinates for the bottom horizontal clipping plane.
The coordinates for the top horizontal clipping plans.
The distances to the nearer depth clipping plane. This distance is negative if the plane is to be behind the viewer.
The distances to the farther depth clipping plane. This distance is negative if the plane is to be behind the viewer.
This function does not return a value.
The following error code can be retrieved by the glGetError function.
Name | Meaning |
---|---|
|
The function was called between a call to glBegin and the corresponding call to glEnd. |
The glOrtho function describes a perspective matrix that produces a parallel projection. The (left,bottom, near) and (right, top, near) parameters specify the points on the near clipping plane that are mapped to the lower-left and upper-right corners of the window, respectively, assuming that the eye is located at (0, 0, 0). The far parameter specifies the location of the far clipping plane. BothzNear and zFar can be either positive or negative. The corresponding matrix is shown in the following image.
where
The current matrix is multiplied by this matrix with the result replacing the current matrix. That is, if M is the current matrix and O is the ortho matrix, then M is replaced with M • O.
glm implementation
template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T>::tmat4x4
(
value_type const & s
)
{
value_type const Zero(0);
this->value[0] = col_type(s, Zero, Zero, Zero);
this->value[1] = col_type(Zero, s, Zero, Zero);
this->value[2] = col_type(Zero, Zero, s, Zero);
this->value[3] = col_type(Zero, Zero, Zero, s);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tmat4x4<valType> ortho
(
valType const & left,
valType const & right,
valType const & bottom,
valType const & top,
valType const & zNear,
valType const & zFar
)
{
detail::tmat4x4<valType> Result(1);
Result[0][0] = valType(2) / (right - left);
Result[1][1] = valType(2) / (top - bottom);
Result[2][2] = - valType(2) / (zFar - zNear);
Result[3][0] = - (right + left) / (right - left);
Result[3][1] = - (top + bottom) / (top - bottom);
Result[3][2] = - (zFar + zNear) / (zFar - zNear);
return Result;
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tmat4x4<valType> ortho(
valType const & left,
valType const & right,
valType const & bottom,
valType const & top)
{
detail::tmat4x4<valType> Result(1);
Result[0][0] = valType(2) / (right - left);
Result[1][1] = valType(2) / (top - bottom);
Result[2][2] = - valType(1);
Result[3][0] = - (right + left) / (right - left);
Result[3][1] = - (top + bottom) / (top - bottom);
return Result;
}