OpenGL 3.0+:正交矩阵不起作用

OpenGL 3.0+: Orthographic Matrix does not work

目前我正在开发一个小型游戏引擎。我已经完成了转换,但是包括正交投影破坏了一个程序,然后精灵根本没有渲染。转换 class 只是平移和缩放对象,它本身就可以完美地工作。

正交矩阵创建:

Matrix Matrix::orthographic(const float & left, const float & right, const float & top, const float & bottom, const float & near, const float & far)
{
    Matrix m(0.0f);
    m.value[0][0] = 2 / (right - left);
    m.value[1][1] = 2 / (top - bottom);
    m.value[2][2] = 2 / (far - near);

    m.value[3][0] = -(right + left) / (right - left);
    m.value[3][1] = -(top + bottom) / (top - bottom);
    m.value[3][2] = -(far + near) / (far - near);
    m.value[3][3] = 1;

    return m;
}

创建转换:

transformable = new Transformable(Vector3(10.0f, 10.0f, 0.0f), Vector3(64.f, 64.f, 0.0f));

这个矩阵的使用:

shaderProgram->setMatrixUniform("projection", Matrix::orthographic(0.0f, 800.0f, 600.0f, 0.0f, -1.0f, 1.0f));

使用转换:

shaderProgram->setMatrixUniform("transformation", transformable->getMatrix());

有人可以帮我吗?我不知道我的错在哪里。

好的,我修复了它,Matrix 构造函数用奇怪的数字而不是 0 填充 Matrix,所以我替换了

Matrix m(0.0f);

Matrix m;