GLSL / OpenGL着色语言错误,无效的存储限定符

时间:2018-08-30 07:44:04

标签: java opengl glsl

在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;
}

这不是整个课程

0 个答案:

没有答案