c++ - GLSL 330 矩阵计算错误{无编译错误}

标签 c++ math opengl matrix glsl

编辑: 好的,现在知道了 :D 问题:完全忘记了 glm 使用列主矩阵。只需将 GL_TRUE 更改为 GL_FALSE,一切正常。


我尝试用我的 ProjectionMatrix 计算我的 ModelMatrix。像这样:

#version 330

layout(location = 0) in vec4 position;
layout(location = 1) in vec4 color;


uniform mat4 projectionMatrix;   //This are the Matrixes from my cpp-app
uniform mat4 modelMatrix;        //With a debugger that can show all active uniforms i checked their values: They're right!

uniform mat4 testUni;            //Here I checked if its working when I precompute the model and perspective matrices in my source: works
mat4 viewMatrix = mat4(1.0f);

noperspective out vec4 vertColor;


mat4 MVP = projectionMatrix * modelMatrix ; //Should actually have the same value like testUni

void main() 
{


gl_Position = testUni * position ;    //Well... :) Works
gl_Position = MVP * position ;    //Well... :) Doesn't work [Just the perspective Transforn]


vertColor = position;
}

最佳答案

移动语句

mat4 MVP = projectionMatrix * modelMatrix ; //Should actually have the same value like testUni

进入 main()。着色器执行从 main 开始。如果您想避免逐顶点计算,请在外部预先计算矩阵并将其作为统一提供。

关于c++ - GLSL 330 矩阵计算错误{无编译错误},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14144344/

相关文章:

c++ - 如何在 OpenGL 中使用 glOrtho()?

c - 如何将与 OpenGL 一起使用的纹理嵌入到 C 数组中?

c++ - MFC CScrollView 滚动不工作

math - 通过异或将两个 GUID 组合起来的结果是否满足成为 GUID 的条件?

c - 如何将 float 舍入为 int?

python - 为什么 ruby​​ 和 python 数学计算不同

c++ - 如何使用 Nsight 调试 (GLSL) 着色器?

c++ - std::list 转换和复制

c++ - UDP 广播未收到

c++ - 独立于平台的资源系统(如 Qt 资源系统)