解析我的mat4变换矩阵到我的opengl着色器时遇到麻烦
trouble parsing my mat4 transformation matrix into my opengl shader?
我得到的错误信息是:
ERROR: 0:5: error<#12>> Unexpected qualifier
ERROR: 0:5: error<#12> Syntax error: "in_transformation" parse error
ERROR: error<#273> 2 compilation errors. No code generated
这是我的绘图函数,我将变换矩阵解析为着色器。我不确定这应该在这里,这应该在初始化函数中我在顶点数组中进行解析吗?矩阵?
void Mesh3D::Draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Draw elements of each mesh in the vector
glm::mat4 matrix = matrixViewProjection*this->matrixModel;
int loc = glGetUniformLocation(program, "in_transformation");
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(matrix));
for (int i = 0; i<nVectorGeometry; i++)
{
glBindVertexArray(vaos[i]);
glDrawElements(col->vectorGeometry[i].primitive
col->vectorGeometry[i].index_count,
GL_UNSIGNED_SHORT, col->vectorGeometry[i].indices);
}
glBindVertexArray(0);
glutSwapBuffers();
}
这是我的顶点着色器,因为我把它存储在头文件中注意,这一切都没有在转换矩阵中解析,所以问题与我如何存储着色器无关
static std::string shaderVert = "#version 330n"
"in vec3 in_coords;n"
"in vec3 in_normals;n"
"in vec4 in_colors; n"//added by me
"in map4 in_transformation;n"//added by me
"out vec3 vertex_normal;n"
"out vec4 vertex_color;n"
"void main(void) {n"
"vertex_normal = in_normals;n"
"vertex_color = in_colors;n"//added by me
"gl_Position =in_transformation* vec4(in_coords, 1.0);n"
"}n";
谢谢,我不确定我是否正在设置变换矩阵正确:/?
这是我的变换矩阵的格式:static glm::mat4 matrix =
{ 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
你的变换变量在着色器中不是一个"统一"的变量。它的类型是map4,你确定你不是指mat4吗?
可以声明为
uniform mat4 transformation;
然后你可以得到位置并解析它
另外,考虑从文件中读取着色器,这样你就不必在每行末尾显式地添加换行符。我知道它是这样工作的,但它更容易为你写你的着色器
相关文章:
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- 这些是什么样的错误?即使我不在 Linux 上工作,我也遇到了 Linux 错误
- 在为我的基于文本的 RPG 游戏制作库存时遇到困难
- 在我的四叉树实现中遇到问题
- 我在使用 boost::serialization 时遇到了一个问题,我的代码在 Linux 中运行良好,但在 Wind
- 为什么我的程序在打开网络设备时遇到问题
- 为什么我的类电影在创建电影实例时遇到问题?
- 我的代码运行良好,但现在当尝试将其制作成模板时,我遇到了许多看似无关的错误。这是怎么回事?
- 我的期末考试遇到了麻烦.代码不断循环回到我的订购菜单,不会显示我的总价
- 对数组进行排序时遇到问题。为什么我的数组无法正确排序?
- 当我的代码工作正常时,为什么在SPOJ中遇到运行时(Sigabrt)错误
- 打印我的字符串阵列时,会遇到细分错误
- 我在让我的代码输出整个链表时遇到问题.它只是输出我修改过的一些文本文件,而不是整个东西
- 在 c++ 中为我的类设置/获取方法时遇到问题
- 我的基本蛮力计划遇到了麻烦.具体的类功能
- 在我的代码覆盖本身时遇到麻烦,我不确定为什么
- 我的程序在尝试将数据集追加到类对象时遇到"Process returned -1073741819 (0xC0000005)"
- 我一直遇到 if elif 和 C++ 中的其他问题
- 我不知道如何使用 boost,虽然我的老师确实提供了代码,但我遇到了一个错误
- 初学者C - 编译我的代码时遇到困难