0

I am getting the following error in my fragment shader:

Compile log: ERROR: 0:7: 'texture' : syntax error: syntax error

The shader is written like this:

#version 300 es

in mediump vec2 texCoord;

out mediump vec4 fColor;

uniform sampler texture;

void main(void) {

    fColor = texture(texture, texCoord);
}

Why am I getting the error?

2
  • You mean: fColor = texture2D(texture, texCoord) ? Commented May 7, 2017 at 23:53
  • apparently texture2d was changed in glsl 3.0 Commented May 8, 2017 at 0:02

2 Answers 2

1

You had two errors. Firstly, texture is a keyword, so you can't use that as a variable name. Secondly sampler doesn't exist as a datatype in OpenGL ES; you need a specific subtype, e.g. sampler2D.

Working shader is:

#version 300 es

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

void main(void) {
    fColor = texture(myTexture, texCoord);
}
Sign up to request clarification or add additional context in comments.

Comments

0

texture is now a reserved word in GLSL 3.00 , you need to change the name.

More info

3 Comments

` 'myTexture' : syntax error: syntax error` any variable name results in the same error. I got this code from the 2014 SIGGRAPH video which came out after the changes for GLSL3.0 and after reading about the texture reserved work stuff.
OK, maybe not the only change to do then, I just happen to have noticed this one, maybe there is more
but this is a trivial shader. can you see anything else? is it safe to say whatever is incorrect is restricted to this code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.