Ben*_*Ben 4 c++ shader opengl-es glsl
我正在使用 OpenGL ES 2.0.0 和 GLSL ES 1.0.0 进行开发。
目前我正在将一个正方形渲染到屏幕上,现在尝试应用纹理。
我在顶点和片段着色器中使用“不同”时遇到问题,收到错误消息:
- Failed to compile vertex shader -
0(3) : error C5060: out can't be used with non-varying tex_varying
in vec4 texture_coord ;
in vec4 position ;
out vec2 tex_varying ;
uniform mat4 translate ;
void main ( )
{
gl_Position = translate * position ;
tex_varying = texture_coord . xy ;
}
Run Code Online (Sandbox Code Playgroud)
我已阅读文档,但无法弄清楚我做错了什么。
这是代码。
顶点:
attribute vec4 position;
attribute vec4 texture_coord;
varying vec2 tex_varying;
uniform mat4 translate;
void main()
{
gl_Position = translate * position;
tex_varying = texture_coord.xy;
}
Run Code Online (Sandbox Code Playgroud)
分段:
varying vec2 tex_varying;
uniform sampler2D texture;
void main()
{
gl_FragColor = texture2D(texture, tex_varying);
}
Run Code Online (Sandbox Code Playgroud)
已解决: 这是一个迟到的答复,但我很久以前就解决了这个问题 - 以防其他人偶然发现这个问题。原来“tex_variing”是Nvidia保留的!只需重命名 tex_variing 即可解决该问题。
干杯。
您显示的 和 关键字适用于 GLSL v3 及更高版本in。out对于 v1(这是您要使用的?),您需要在顶点着色器中替换inwithattribute和outwith 。varying在片段着色器中,替换in为varying并且您不能使用out- 您需要gl_FragColor像您似乎正在做的那样输出。
因此,您的第二个/第三个着色器看起来像是您已将第一个着色器中的 GLSL v3 代码正确转换为 GLSL v1,并且看起来它们应该与 ES2/GLSL v1 一起使用