Mitchell
Mitchell

Reputation: 11

LWJGL Vertex and Fragment Shaders Wont Compile (Error CO206)

I have been interested in learning OpenGl for a while. However every time I start working with it, I get the same error when compiling my shaders. This is the error code that is spits out.

0(1) : error C0206: invalid token "invalid atom 483265304" in version line

I have tried looking up the error and haven't found much of anything... And certainly nothing that provided incite on how to fix the problem.

I do not know C or C++ so I am using LWJGL.

Here is the code I'm using to compile my shaders:

private static int loadShader(String file, int type){
    //System.out.println("Loading Shader.");
    StringBuilder shaderSource = new StringBuilder();
    try {
        BufferedReader reader = new BufferedReader(new FileReader(file));
        String line;
        while((line = reader.readLine())!=null){
            //System.out.println(line);
            shaderSource.append(line).append("/n");
        }
        reader.close();
        //System.out.println("Closed Reader.");

    } catch (IOException e) {
        System.err.println("Could not read file!");
        e.printStackTrace();
        System.exit(-1);
    }
    //System.out.println("Creating Shader ID...");
    int shaderID = GL20.glCreateShader(type);
    //System.out.println("Created Shader ID, Compiling Shader.");
    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. Location: " + file);
        System.exit(-1);
    }
    return shaderID;
}

This is my vertex shader:

#version 400 core

in vec3 position;
out vec3 colour;

void main(void){

    gl_Position = vec4(position, 1.0);
    colour = vec3(position.x+0.5, 1.0, position.y+0.5);
}

and this is my Fragment Shader:

#version 400 core

in vec3 colour;
out vec4 out_Colour;

void main(void){
    out_Colour = vec4(colour, 1.0);
}

If anybody reads this, thanks in advance for your time.

Upvotes: 1

Views: 1114

Answers (1)

Andrew Williamson
Andrew Williamson

Reputation: 8691

Basic typo - you're appending "/n" instead of "\n" when you read in each line.

@Nicol Bolas makes a good point - there is a function Files.readAllBytes(Path path), if you use it instead of re-implementing the functionality you will be less prone to little bugs like this.

Upvotes: 1

Related Questions