在 iphone opengl es 2.0 项目上更改 xcode 中的着色器代码会导致错误

发布于 2024-09-27 01:09:28 字数 707 浏览 0 评论 0原文

我是着色器新手,我正在尝试学习基础知识。 但每次我更改顶点着色器中的一些代码时,都会导致错误。

“验证失败:程序未成功链接。”

我使用 iPhone 的标准 openGL 项目作为 Xcode 的启动器(带有在 y 位置移动的 2d 立方体)。

从一开始,着色器看起来像这样:

attribute vec4 position;  
attribute vec4 color;  

varying vec4 colorVarying;  

void main()  
{  
     gl_Position = position;  
     gl_Position.y += sin(translate) / 2.0;  
     colorVarying = color;  
}  

我想将其更改为:

uniform mat4 gl_ProjectionMatrix;  
uniform mat4 gl_ModelViewMatrix;  

attribute vec4 gl_Vertex;  

void main()  
{  
     gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;  
}  

我得到的只是一个白屏和上面提到的错误。

有什么问题吗?

/尼古拉斯

Im new to shaders and I'm trying to learn the basics.
But everytime I change some code in my vertex shader it results in an error.

"Validation Failed: Program is not successfully linked."

Im using the standard openGL project for the iphone as a starter in Xcode ( with a 2d cube moving in y-position).

From the beginning the shader looks like this:

attribute vec4 position;  
attribute vec4 color;  

varying vec4 colorVarying;  

void main()  
{  
     gl_Position = position;  
     gl_Position.y += sin(translate) / 2.0;  
     colorVarying = color;  
}  

and I want to change it to :

uniform mat4 gl_ProjectionMatrix;  
uniform mat4 gl_ModelViewMatrix;  

attribute vec4 gl_Vertex;  

void main()  
{  
     gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;  
}  

I all get is a white screen and the error mentioned above.

What's the problem?

/Niclas

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋叶绚丽 2024-10-04 01:09:28

请注意,您使用的是“变化的”参数。这需要为顶点着色器和片段着色器定义。由于您似乎只更改了顶点着色器,我猜测这会导致您的链接问题,因为 colorVarying 可能仍在片段着色器中。尝试将“colorVarying”的逻辑放回到顶点着色器中。像这样的东西:

uniform mat4 gl_ProjectionMatrix;   
uniform mat4 gl_ModelViewMatrix;   

attribute vec4 gl_Vertex;   

attribute vec4 color;
varying vec4 colorVarying;

void main()   
{   
    gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;  
    colorVarying = color; 
}

Notice that you are using a "varying" parameter. This needs to be defined for both the vertex and the fragment shader. Since you appear to have only changed the vertex shader I'm guessing that this is causing your link problem as the colorVarying is probably still in the fragment shader. Try putting the logic of "colorVarying" back into your vertex shader. Something like:

uniform mat4 gl_ProjectionMatrix;   
uniform mat4 gl_ModelViewMatrix;   

attribute vec4 gl_Vertex;   

attribute vec4 color;
varying vec4 colorVarying;

void main()   
{   
    gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;  
    colorVarying = color; 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文