【问题标题】:Orthographic projection matrix in OpenGLOpenGL中的正交投影矩阵
【发布时间】:2014-11-13 02:19:56
【问题描述】:

我正在尝试实现正交相机。当我使用 DirectX 时,可以通过某种方式确定正交投影矩阵。一个普通的带纹理的矩形可能表示如下:

auto l = -screenWidth / 2 + rectPosition.X;
auto r = l + rectWidth;
auto t = screenHeight / 2 - rectPosition.Y;
auto b = t - rectHeight;

float vx [] =
{
    l, t, 0, 1, 0, 0, // x y z w u v
    r, b, 0, 1, 1, 1,
    l, b, 0, 1, 0, 1,
    l, t, 0, 1, 0, 0,
    r, t, 0, 1, 1, 0,
    r, b, 0, 1, 1, 1,
};

可以这样设置正交矩阵:

ortho(screenWidth,screenHeight,0.1f,1000.f);

我可以通过将相机的投影矩阵设置为正交矩阵来获得可见图像,而无需更改相机的更新代码。 所以,我认为这种方法必须奏效。但我看到的只是黑屏。该怎么办?

【问题讨论】:

    标签: opengl


    【解决方案1】:

    使用 glutOrtho2d。如果您有任何疑问,请参考链接

    https://www.opengl.org/sdk/docs/man2/xhtml/gluOrtho2D.xml

    【讨论】:

    • 最好使用现代 OpenGL 并自己提供矩阵。
    【解决方案2】:

    单位投影矩阵将视口的左上角和右下角范围放在 (-1, +1) 和 (+1, -1) 处,没有透视效果,因此“默认”OpenGL 会为您提供正交投影屏幕左上角为 (-1, +1),右下角为 (+1, -1) 的投影。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-06
      • 1970-01-01
      • 1970-01-01
      • 2019-08-10
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      • 1970-01-01
      相关资源
      最近更新 更多