1

I'm having problems to compile and execute a simple OpenGL application in Mac OSX 10.9. It works just fine in windows. But in Mac I keep getting some errors while linking the vertex shader to the fragment shader in the shaderProgram.

Here is my console Output.

4.1 INTEL-8.26.34

ERROR! could not link the shader program
WARNING: Output of vertex shader 'outColor' not read by fragment shader
ERROR: Input of fragment shader 'inColor' not written by vertex shader
Program ended with exit code: 0

Here is the Method that I'm using to link both together.

GLuint createShaderProgram(GLuint vertexShader, GLuint fragmentShader)
{
    // Create and link the shader program
    GLuint shaderProgram = glCreateProgram(); // create handle
    if (!shaderProgram) {
    ERROR("could not create the shader program", false);
    return NULL_HANDLE;
    }
    glAttachShader(shaderProgram, vertexShader);    // attach vertex shader
    glAttachShader(shaderProgram, fragmentShader);  // attach fragment shader
    glLinkProgram(shaderProgram);



    // check to see if the linking was successful
    int linked;
    glGetProgramiv(shaderProgram, GL_LINK_STATUS, &linked); // get link status
    if (!linked) {
        ERROR("could not link the shader program", false);
        int maxLength;
        int length;
        glGetProgramiv(shaderProgram, GL_INFO_LOG_LENGTH, &maxLength);
        char* log = new char[maxLength];
        glGetProgramInfoLog(shaderProgram, maxLength,&length,log);
        printf(log);

        return NULL_HANDLE;
    }

    return shaderProgram;
}

Here is my vertexshader.

#version 410 core
layout (location = 0) in vec3 inPosition;
layout (location = 3) in vec3 inColor;
layout (location = 3) smooth out vec4 outColor;
void main()
{   
    gl_Position = vec4(inPosition, 1.0);
    outColor = vec4(inColor, 1.0);
}

Here is the fragShader

#version 410 core
layout (location = 3) smooth in vec4 inColor;
layout (location = 0) out vec4 outColor;
void main()
{
    outColor = inColor;
}

Thanks!!

2
  • This appears to be a bug with Apple's GLSL compiler. It does not correctly understand Separate Shader Object semantics for matching attributes by their index location when linking a GLSL 4.10 shader. While ratchetfreak's answer will fix your problem, it is not technically correct. The names do not need to match (or at least if the compiler/linker were doing its job, they would not), this is a problem on Apple's end. You might be able to hint the driver into working the way it is supposed to if you add #extension GL_ARB_separate_shader_objects : enable to the top of your shader. Commented Jun 17, 2014 at 15:15
  • One other thing to consider, if you want Separate Shader Objects to work, you are supposed to re-declare gl_PerVertex. So try also adding out gl_PerVertex { vec4 gl_Position; };. If even that does not fix it, then you can blame Apple for this one. Commented Jun 17, 2014 at 15:22

1 Answer 1

1

the names need to match:

have the name of the output of the vertex shader match the name of the input of the fragment shader:

#version 410 core
layout (location = 0) in vec3 inPosition;
layout (location = 3) in vec3 inColor;
smooth out vec4 vertOutColor;
void main()
{   
    gl_Position = vec4(inPosition, 1.0);
    vertOutColor = vec4(inColor, 1.0);
}

fragment shader:

#version 410 core
smooth in vec4 vertOutColor;
layout (location = 0) out vec4 outColor;
void main()
{
    outColor = vertOutColor;
}
Sign up to request clarification or add additional context in comments.

3 Comments

No they don't, this is using Separate Shader Objects. The names do not matter at all. It is the locations that must match. See Section 4.3.8.1 here. As best I can tell, this is a GLSL compiler bug. Explicit location matching for stage inputs/outputs is core in GLSL 4.10.
Just tried it and now I'm getting different errors. ERROR! Could not compile shader 'vertexShader1.vert' ERROR! Could not compile shader 'fragmentShader1.frag' Program ended with exit code: 0
@MarcusGabilheri I forgot to rename the variables in the code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.