【问题标题】:Fragment Shader Compile error in Open GLES 3.0Open GLES 3.0 中的片段着色器编译错误
【发布时间】:2017-10-05 21:09:50
【问题描述】:

我的片段着色器出现以下错误:

编译日志:ERROR: 0:7: 'texture' : syntax error: syntax error

着色器是这样写的:

#version 300 es

in mediump vec2 texCoord;

out mediump vec4 fColor;

uniform sampler texture;

void main(void) {

    fColor = texture(texture, texCoord);
}

为什么我会收到错误消息?

【问题讨论】:

  • 你的意思是:fColor = texture2D(texture, texCoord) ?
  • 显然 texture2d 在 glsl 3.0 中发生了变化

标签: opengl-es fragment-shader


【解决方案1】:

您有两个错误。首先,texture 是一个关键字,因此不能将其用作变量名。其次,sampler 在 OpenGL ES 中不作为数据类型存在;你需要一个特定的子类型,例如sampler2D.

工作着色器是:

#version 300 es

in mediump vec2 texCoord;
out mediump vec4 fColor;
uniform sampler2D myTexture;

void main(void) {
    fColor = texture(myTexture, texCoord);
}

【讨论】:

    【解决方案2】:

    texture现在是 GLSL 3.00 中的保留字,您需要更改名称。

    More info

    【讨论】:

    • ` 'myTexture' : syntax error: syntax error` 任何变量名都会导致相同的错误。我从 2014 年 SIGGRAPH 视频中获得了这段代码,该视频是在 GLSL3.0 的更改之后以及在阅读了有关纹理保留工作的内容之后发布的。
    • 好吧,也许不是唯一要做的改变,我只是碰巧注意到了这个,也许还有更多
    • 但这是一个微不足道的着色器。你还能看到什么吗?是否可以安全地说任何不正确的内容都仅限于此代码?
    猜你喜欢
    • 2016-01-22
    • 1970-01-01
    • 2013-11-07
    • 2022-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多