gpt4 book ai didi

c++ - OpenGL ES 2.0 2D 投影矩阵,将 GLfloat (*)[4] 转换为 GLfloat 时出错

转载 作者:太空宇宙 更新时间:2023-11-04 11:51:59 27 4
gpt4 key购买 nike

我正在 OpenGL ES 2.0 中创建一个应用程序,想要设置一个 2D 投影矩阵来解决由屏幕纵横比引起的拉伸(stretch)和扭曲。我使用一个函数创建了一个具有所需值的矩阵。该函数的结果是一个 4x4 矩阵,然后将其上传到顶点着色器。当我运行该程序时,出现构建错误:“无法将 GLfloat (*)[4]' 转换为 GLfloat' 作为返回”。我的 C++ 知识有限,不知道如何解决这个问题,下面是我调用的函数的代码。

GLfloat ortho_matrix(float left, float right, float bottom, float top, float near,
float far)
{
GLfloat result[4][4];

result[0][0] = 2.0 / (right - left);
result[1][0] = 0.0;
result[2][0] = 0.0;
result[3][0] = 0.0;

//Second Column
result[0][1] = 0.0;
result[1][1] = 2.0 / (top - bottom);
result[2][1] = 0.0;
result[3][1] = 0.0;

//Third Column
result[0][2] = 0.0;
result[1][2] = 0.0;
result[2][2] = -2.0 / (far - near);
result[3][2] = 0.0;

//Fourth Column
result[0][3] = -(right + left) / (right - left);
result[1][3] = -(top + bottom) / (top - bottom);
result[2][3] = -(far + near) / (far - near);
result[3][3] = 1;

return result;
}

最佳答案

您正试图从您的函数返回一个 float ,而您需要返回一个二维数组。以这种方式声明您的功能:

void ortho_matrix(float left, float right, float bottom, float top, float near,
float far, GLfloat result[4][4])

关于c++ - OpenGL ES 2.0 2D 投影矩阵,将 GLfloat (*)[4] 转换为 GLfloat 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17786210/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com