OpenGL glOrtho




The glOrtho function multiplies the current matrix by an orthographic matrix.

Syntax

void WINAPI glOrtho(
  GLdouble left,
  GLdouble right,
  GLdouble bottom,
  GLdouble top,
  GLdouble zNear,
  GLdouble zFar
);

Parameters

left

The coordinates for the left vertical clipping plane.

right

The coordinates for theright vertical clipping plane.

bottom

The coordinates for the bottom horizontal clipping plane.

top

The coordinates for the top horizontal clipping plans.

zNear

The distances to the nearer depth clipping plane. This distance is negative if the plane is to be behind the viewer.

zFar

The distances to the farther depth clipping plane. This distance is negative if the plane is to be behind the viewer.

Return value

This function does not return a value.

Error codes

The following error code can be retrieved by the glGetError function.

NameMeaning
GL_INVALID_OPERATION

The function was called between a call to glBegin and the corresponding call to glEnd.

Remarks

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.

Dd373965.ortho1(en-us,VS.85).png

where

Dd373965.ortho2(en-us,VS.85).png

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;
 }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值