1
\$\begingroup\$

I have a GL shader file whose first few lines currently look like this:

#version 120
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 vertexUV;

When I try to compile this shader when running the program, it returns this error:

0:2(1): error: syntax error, unexpected NEW_IDENTIFIER

From what I know, this means that the word layout is giving it trouble. What am I doing wrong? Do I need to provide more information?

\$\endgroup\$
3
\$\begingroup\$

I believe that the problem is that you are trying to use the layout keyword, but the version is set at 120. Try changing the first line to #version 330. There is an alternative way of setting attribute locations, which can be found in this answer.

\$\endgroup\$
  • \$\begingroup\$ That's strange. A friend of mine (who made the above code) reports that this code works fine when he runs it, version 120 and all. \$\endgroup\$ – Joe Z. Jan 14 '14 at 6:22
  • \$\begingroup\$ Also, my version of Mesa is GL 3.0, I can't use any versions higher than 130. \$\endgroup\$ – Joe Z. Jan 14 '14 at 6:23
  • 5
    \$\begingroup\$ @JoeZ.: every driver vendor (NVIDIA, AMD, Intel, Mesa, etc.) has to reimplement the GLSL compiler from scratch. There are lots of bugs and conformance violations all over the place. Just because one vendor accepts newer GLSL code with an old #version directive doesn't mean it's correct. Also be aware that just because the driver only supports GL 3.0 doesn't mean it won't support a newer version of GLSL as an extension; the latest Mesa should support up to GLSL 3.30 with some drivers (not sure which ones). \$\endgroup\$ – Sean Middleditch Jan 14 '14 at 7:54
  • \$\begingroup\$ So I figured out that enabling GL_ARB_explicit_attrib_location made that error go away. \$\endgroup\$ – Joe Z. Jan 14 '14 at 18:31
  • \$\begingroup\$ @JoeZ. I added an alternative method for setting attribute locations to the answer. I know you already solved it using GL_ARB_explicit_attrib_location, but that should help other people if that doesn't work for them. \$\endgroup\$ – Lysol Jan 15 '14 at 3:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.