GLSL gives strange error: "#version required and missing" on mac only

I have a strange and deeply frustrating problem. I have a shader that works great on Windows and Linux. When I go to my mac it gives me terrible errors and black screen.

// Vertex - THIS COMMENT DOES NOT EXIST IN ACTUAL SHADER. ACTUAL STARTS AT #version 150 

#version 410

in highp vec4 vertex;
in mediump vec3 normal;

uniform mediump mat4 matrix; // MVP
uniform mediump vec3 col; // The color in question

uniform highp vec4 lightPosition;
uniform highp vec3 La; // Ambient
uniform highp vec3 Ld; // diffuse
uniform highp vec3 Ls; // Specular

uniform highp vec3 Ka; // Ambient Reflectivity
uniform highp vec3 Kd; // Diffuse Reflectivity
uniform highp vec3 Ks; // Specular Reflectivity
uniform float Shininess; // Specular Shininess factor

uniform mediump mat4 ModelViewMatrix;
uniform mediump mat3 NormalMatrix;

out mediump vec3 LightIntensity;
out mediump vec4 color;

void main()
{

    color = vec4(col * 0.2 + col * 0.8, 1.0);

    color = clamp(color, 0.0, 1.0);

    vec3 tnorm = normalize( NormalMatrix * normal);
    vec4 eyeCoords = ModelViewMatrix * vertex;

    vec3 s = normalize(vec3(lightPosition - eyeCoords));
    vec3 v = normalize(-eyeCoords.xyz);
    vec3 r = reflect( -s, tnorm );
    float sDotN = max( dot(s,tnorm), 0.0 );
    vec3 ambient = La * Ka;
    vec3 diffuse = Ld * Kd * sDotN;
    vec3 spec = vec3(0.0);
    if( sDotN > 0.0 )
       spec = Ls * Ks *
           pow( max( dot(r,v), 0.0 ), Shininess );

    LightIntensity = ambient + diffuse + spec;

    gl_Position = matrix * vertex;
}

//fragment

#version 410

in mediump vec4 color;
in mediump vec3 LightIntensity;

out vec4 out_Color;

void main(void)
{

    out_Color =  vec4(LightIntensity, 1.0) * color;
}


// error
QGLShader::compile(Vertex): ERROR: 0:1: '' :  #version required and missing.
ERROR: 0:11: 'attribute' : syntax error syntax error

Vertex shader for simpleShaderProg (MainVertexShader & PositionOnlyVertexShader) failed to compile
QGLShader::compile(Fragment): ERROR: 0:1: '' :  #version required and missing.

Fragment shader for simpleShaderProg (MainFragmentShader & ShockingPinkSrcFragmentShader) failed to compile
QGLShader::link: "ERROR: One or more attached shaders not successfully compiled
"
Errors linking simple shader: ERROR: One or more attached shaders not successfully compiled

QGLShader::compile(Vertex): ERROR: 0:1: '' :  #version required and missing.
ERROR: 0:5: 'attribute' : syntax error syntax error

Vertex shader for blitShaderProg (MainWithTexCoordsVertexShader & UntransformedPositionVertexShader) failed to compile
QGLShader::compile(Fragment): ERROR: 0:1: '' :  #version required and missing.
ERROR: 0:11: 'varying' : syntax error syntax error

Fragment shader for blitShaderProg (MainFragmentShader & ImageSrcFragmentShader) failed to compile
QGLShader::link: "ERROR: One or more attached shaders not successfully compiled
"
Errors linking blit shader: ERROR: One or more attached shaders not successfully compiled


// C++

QGLShader *vshader1 = new QGLShader(QGLShader::Vertex, this);


    vshader1->compileSourceFile(":shaders/vert1.vert");

    QGLShader *fshader1 = new QGLShader(QGLShader::Fragment, this);

    fshader1->compileSourceFile(":shaders/frag1.frag");

    program1.addShader(vshader1);
    program1.addShader(fshader1);
    program1.link();

      

So basically, if I add version #version 150 or #version 410, it complains that #version is not listed. If I specify #version 130 or #version 350 it complains that I was asked to enter an invalid version (shouldn't I just go back to the available version?)

Any idea what's going on? This is especially annoying since I specified #version and I didn't use a different keyword.

+3


source to share





All Articles