@saket
I think the driver of your graphics card isn't able to understand the GLSL command. As i see you're using an Intel Graphics Card, i had a lot of problems with my GLSL code on several machines with Intel Graphics.
Try to change the attributes and varying qualifiers:
static const char *vertexShaderSource =
"#version 140\n"
"in vec4 posAttr;\n"
"in vec4 colAttr;\n"
"out vec4 col;\n"
"uniform mat4 matrix;\n"
"void main() {\n"
" col = vec4(1, 0, 0, 1);\n"
" gl_Position = matrix * posAttr;\n"
"}\n";
static const char *fragmentShaderSource =
"#version 140\n"
"in vec4 col;\n"
"out vec4 fragcol;\n"
"void main() {\n"
" //gl_FragColor = col;\n"
" fragcol = col;\n"
"}\n";
And try to get the Info from the shader after compilation (https://www.opengl.org/wiki/Shader_Compilation#Shader_error_handling)
GLuint shader = glCreateShader(...);
// Get strings for glShaderSource.
glShaderSource(shader, ...);
glCompileShader(shader);
GLint isCompiled = 0;
glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled);
if(isCompiled == GL_FALSE)
{
GLint maxLength = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);
// The maxLength includes the NULL character
std::vector<GLchar> errorLog(maxLength);
glGetShaderInfoLog(shader, maxLength, &maxLength, &errorLog[0]);
// Provide the infolog in whatever manor you deem best.
// Exit with failure.
glDeleteShader(shader); // Don't leak the shader.
return;
}
// Shader compilation is successful.