0
votes

I've encountered this error a few times now when compiling my shaders.

Here is the infoLog/Error

Vertex shader failed to compile with the following errors: ERROR: 0:1: error(#132) Syntax error: "<" parse error ERROR: error(#273) 1 compilation errors. No code generated

This occurs on the fragment shader aswell. Here is my very very basic test vertex and frag shader code:

@version 330

layout (location = 0) in vec3 position;

void main(){

    gl_Position = vec4(position, 1.0);
}

And Here's the frag:

@version 330

out vec4 fragColor;

void main(){

    fragColor = vec4(1.0, 0.0, 0.0, 1.0);
}

Here is the Shader class that has all the load/compile/link methods:

public  abstract class Shader {

    private int program;

    public Shader(){


        program = glCreateProgram();

        if(program == 0){
            System.err.println("Shader creation failed: Could not find valid memory location");     
            System.exit(1);
        }
    }



    public void bind(){

         glUseProgram(program);

    }

    public void addProgram(String text, int type){

        int shader = glCreateShader(type);

        if(shader == 0)
        {
            System.err.println("Shader creation failed: Could not find valid memory location");      
            System.exit(1);
        }

        glShaderSource(shader, text);
        glCompileShader(shader);             

        if(glGetShaderi(shader, GL_COMPILE_STATUS) == 0){
            System.err.println("Shader compilation failed");
            System.err.println(glGetShaderInfoLog(shader, 1024));
            System.exit(1);
        }

        glAttachShader(program, shader);
    }


    public String loadShader(String fileName){


        StringBuilder shaderSource = new StringBuilder();
        BufferedReader shaderReader = null;

        try{

            shaderReader = new BufferedReader(new FileReader("./res/shaders/" + fileName));

            String line;
            while((line = shaderReader.readLine()) != null){

                shaderSource.append(line).append("\n");
            }

            shaderReader.close();


        }catch(Exception e){
            e.printStackTrace();
            System.out.println("HERE IT IS!!!!");
            System.exit(1);
        }

        return shaderSource.toString();

    }

    public void compileShader(){

        glLinkProgram(program);

        if(glGetProgrami(program, GL_LINK_STATUS) == 0){
            System.err.println(glGetShaderInfoLog(program, 1024));
            System.exit(1);
        }

        glValidateProgram(program);

        if(glGetProgrami(program, GL_VALIDATE_STATUS) == 0){
            System.err.println(glGetShaderInfoLog(program, 1024));
            System.exit(1);
        }

    }
}

Ive done a lot of experimenting to seee where the problem is and I've narrowed it down to one of two things.(A) somehow loading in the text from the file in the loadShader() method is returning a bunch of random symbols(notice in the infoLog up top the parse error indicates the character was "<" which is clearly not even in either of the shaders. Or (B) the error is with the glCompileShader(shader) call in the addProgram() method. I think option A is more likely, but as I said, the fileLoader has never done that before.

1
can you print the whole shader source after you read it? (or inspect it with the debugger)ratchet freak
shouldn't it be #version... instead of @version?BDL
you know what... I think your right... I hope not because then I'm the idiot... Holy crap... that was It... to think it was a preprocessor tag I screwed up... facepalm... thanks a tonAndrew Graham

1 Answers

1
votes

And the answer is....... It's # not @ when declaring version in the shader code...