英文:
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:
<s>`#version 150`</s>
```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, "position"); // has to be done before glLinkProgram
glLinkProgram(program)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论