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

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

我正在尝试按照教程进行操作,当我尝试编译他制作的顶点着色器时,我得到了这个输出:

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

我使用 GLSL 3.2.9232 和我的代码:

#version 150

layout (location = 0) in vec3 position;

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

输入布局位置限定符(参见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 and OpenGL Shading Language 1.50 Specification

切换到 glsl 3.30:

#version 150

#version 330

如果您的系统不支持 GLSL 3.30,您必须删除布局限定符

layout (location = 0) in vec3 position;

in vec3 position; 

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

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