在GLSL着色语言
中编译着色器时出现错误ERROR: 0:4: Invalid storage qualifiers 'attribute' in global
variablecontext
ERROR: 0:7: Use of undeclared identifier 'gl_Position'
ERROR: 0:7: Use of undeclared identifier 'position'
ERROR: 0:8: Use of undeclared identifier 'position'
ERROR: 0:8: Use of undeclared identifier 'position'
无法编译着色器!
我的代码:
#version 120
varying vec3 colour;
attribute vec3 position;
void main(void){
gl_Position = vec4(position, 1.0);
colour = vec3(position.x + 0.5, 1.0, position.y + 0.5);
}
这是一个顶点着色器。
编辑:这就是加载着色器的方式
protected void bindAtrribute(int attribute){
GL20.glBindAttribLocation(programID, attribute, "position");
}
private static int loadShader(String file, int type){
StringBuilder shaderSource = new StringBuilder();
try{
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while((line = reader.readLine())!=null){
shaderSource.append(line).append("\n");
}
reader.close();
}catch(IOException e){
e.printStackTrace();
System.exit(-1);
}
int shaderID = GL20.glCreateShader(type);
GL20.glShaderSource(shaderID, shaderSource);
GL20.glCompileShader(shaderID);
if(GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS )== GL11.GL_FALSE){
System.out.println(GL20.glGetShaderInfoLog(shaderID, 500));
System.err.println("Could not compile shader!");
System.exit(-1);
}
return shaderID;
}
这不是整个课程