d opengl 自定义与固定管道矩阵的怪异

发布于 2024-11-05 10:33:47 字数 1997 浏览 0 评论 0原文

我最近一直在努力转移到自己处理矩阵控件,以便我的引擎准备好转移到 4.0+ 上下文,尽管目前我正在使用 Derelict 的 2.1 上下文。我已经尝试了各种矩阵计算,但似乎没有任何东西适用于我的着色器(除了 FPS 计数器之外,屏幕上没有任何东西,除非我切换回固定管道,或者如果我切换 vs 设置 gl_Position = vec4(position,1.0); )。即使当我获取 OpenGL 通常设置的值并将它们放入其中时,我也会得到相同的结果。

我添加了我的矩阵和固定管道返回到绘制调用的矩阵的打印,并且输出是相同的。我已经检查并仔细检查了我的着色器代码,所以我非常不知道这个错误是从哪里来的。

这种情况在 OSX 和 Windows 上都会发生。我有一个 glGetError() 检查每个绘图调用,但没有收到任何错误。着色器链接并验证,没有警告或错误。

统一加载代码:

glUniformMatrix4fv(ModelViewLoc,1, GL_FALSE ,modelview);
glUniformMatrix4fv(ProjectionLoc,1, GL_FALSE ,projection);

顶点着色器:

#version 120

//layout(location = 0) in vec3 position;
attribute vec3 position;

uniform mat4 ModelView;
uniform mat4 Projection;

void main()
        {
                mat4 mvp = Projection*ModelView;
                gl_Position = mvp * vec4(position,1.0);
                //gl_Position = vec4(position,1.0);
        }

片段着色器:

#version 120

uniform float slider;

        void main()
        {
                vec4 diffuse = vec4(vec3(slider),1.0);

                gl_FragColor = diffuse;
        }

调试输出:

模型 1:

OpenGL ModelView: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -2, -2, -8, 1]
mine:             [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -2, -2, -8, 1]

OpenGL Projection:[1.30323, 0, 0, 0, 0, 1.30323, 0, 0, 0, 0, -1.0002, -1, 0, 0, -0.20002, 0]
mine:             [1.30323, 0, 0, 0, 0, 1.30323, 0, 0, 0, 0, -1.0002, -1, 0, 0, -0.20002, 0]

模型 2:

OpenGL ModelView: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 2, -8, 1]
mine:             [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 2, -8, 1]

OpenGL Projection:[1.30323, 0, 0, 0, 0, 1.30323, 0, 0, 0, 0, -1.0002, -1, 0, 0, -0.20002, 0]
mine:             [1.30323, 0, 0, 0, 0, 1.30323, 0, 0, 0, 0, -1.0002, -1, 0, 0, -0.20002, 0]

*更新*我已经发布了代码矩阵库@ github.com/mclark4386/DMath 看到什么了吗?^^;

I have recently been working on shifting over to handling my matrix controls myself, so that my engine will be ready to shift over to a 4.0+ context, though currently I am using a 2.1 context with Derelict. I have tried all kinds of matrix calcs and nothing seems to work with my shader(nothing on screen except for FPS counter unless I switch back to fixed-pipe, or if I switch the vs to set gl_Position = vec4(position,1.0);). Even when I grab the values that OpenGL normally sets and put them into it I get the same.

I added print out of both my matrix and the one that the fixed-pipeline returned to the draw calls and the output is IDENTICAL. I've already checked and double checked my shader code, so I'm pretty lost as to from where this bug is coming.

This happens on both OSX and Windows. I have a glGetError() check every draw call and am not getting any errors. Shaders link and validate with out warning or error.

code for uniform loading:

glUniformMatrix4fv(ModelViewLoc,1, GL_FALSE ,modelview);
glUniformMatrix4fv(ProjectionLoc,1, GL_FALSE ,projection);

Vertex Shader:

#version 120

//layout(location = 0) in vec3 position;
attribute vec3 position;

uniform mat4 ModelView;
uniform mat4 Projection;

void main()
        {
                mat4 mvp = Projection*ModelView;
                gl_Position = mvp * vec4(position,1.0);
                //gl_Position = vec4(position,1.0);
        }

Fragment Shader:

#version 120

uniform float slider;

        void main()
        {
                vec4 diffuse = vec4(vec3(slider),1.0);

                gl_FragColor = diffuse;
        }

debug output:

Model 1:

OpenGL ModelView: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -2, -2, -8, 1]
mine:             [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -2, -2, -8, 1]

OpenGL Projection:[1.30323, 0, 0, 0, 0, 1.30323, 0, 0, 0, 0, -1.0002, -1, 0, 0, -0.20002, 0]
mine:             [1.30323, 0, 0, 0, 0, 1.30323, 0, 0, 0, 0, -1.0002, -1, 0, 0, -0.20002, 0]

Model 2:

OpenGL ModelView: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 2, -8, 1]
mine:             [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 2, -8, 1]

OpenGL Projection:[1.30323, 0, 0, 0, 0, 1.30323, 0, 0, 0, 0, -1.0002, -1, 0, 0, -0.20002, 0]
mine:             [1.30323, 0, 0, 0, 0, 1.30323, 0, 0, 0, 0, -1.0002, -1, 0, 0, -0.20002, 0]

*UPDATE*I have released the code for matrix lib @ github.com/mclark4386/DMath See anything there?^^;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文