ERROR: 0:3: 错误(#279) 无效的布局限定符 ‘location’

huangapple go评论69阅读模式
英文:

ERROR: 0:3: error(#279) Invalid layout qualifier 'location'

问题

我试图按照教程操作,但在尝试编译他制作的顶点着色器时,我得到以下输出:

顶点着色器编译失败,出现以下错误:
错误:0:3:错误(#279) 无效的布局限定符 'location'
错误:错误(#273) 1 个编译错误。没有生成代码

我使用的是 GLSL 3.2.9232,我的代码:

#version 150

layout (location = 0) in vec3 position;

void main()
{
    gl_Position = vec4(0.25 * position, 1.0);
}
英文:

i am trying to follow a tutorial and when i try to compile the vertex shader he made i get this output:

Vertex shader failed to compile with the following errors:
ERROR: 0:3: error(#279) Invalid layout qualifier 'location'
ERROR: error(#273) 1 compilation errors.  No code generated

I use GLSL 3.2.9232 and my code :

#version 150

layout (location = 0) in vec3 position;

void main()
{
    gl_Position = vec4(0.25 * position, 1.0);
}

答案1

得分: 1

输入布局位置限定符(参见[顶点着色器属性索引](https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL)#Vertex_shader_attribute_index))在GLSL 3.30中引入,在GLSL 1.50中不可用。请对比[OpenGL Shading Language 3.30规范](https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.3.30.pdf)和[OpenGL Shading Language 1.50规范](https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.1.50.pdf)。

切换到GLSL 3.30

#version 150
```glsl
#version 330

如果你的系统不支持GLSL 3.30,你必须移除布局限定符:

layout (location = 0) in vec3 position;

in vec3 position;

你可以在程序链接之前使用glBindAttribLocation指定属性位置:

glBindAttribLocation(program, 0, "position"); // 必须在glLinkProgram之前完成
glLinkProgram(program)

<details>
<summary>英文:</summary>

Input layout locations qualifiers (see [Vertex shader attribute index](https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL)#Vertex_shader_attribute_index)) are introduced in in GLSL 3.30 and cannot be used in GLSL 1.50. Compare [OpenGL Shading Language 3.30 Specification](https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.3.30.pdf) and  [OpenGL Shading Language 1.50 Specification](https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.1.50.pdf).

Switch to glsl 3.30:

&lt;s&gt;`#version 150`&lt;/s&gt;
```glsl
#version 330

If your system doesn't support GLSL 3.30, you have to remove the layout qualifier

<s>layout (location = 0) in vec3 position;</s>

in vec3 position; 

You can specify the attribute location with glBindAttribLocation before the program is linked:

glBindAttribLocation(program, 0, &quot;position&quot;); // has to be done before glLinkProgram
glLinkProgram(program)

huangapple
  • 本文由 发表于 2020年10月16日 00:29:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/64375952.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定