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