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



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

正交矩阵创建:

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());

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

好的,我修复了它,矩阵结构体用奇怪的数字而不是 0 填充矩阵,所以我替换了

Matrix m(0.0f);

Matrix m;

最新更新