GLSL给出了一个奇怪的错误:" #version需要和丢失"只在mac上

时间:2014-08-13 22:15:26

标签: qt opengl glsl

我有一个奇怪的,令人沮丧的问题。我有一个在Windows和Linux上运行良好的着色器。当我把它移到我的Mac上时,它给了我可怕的错误和黑屏。

// 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();

所以基本上如果我放入版本#version 150或#version 410,它会抱怨没有指定#version。如果我指定#version 130或#version 350,它会抱怨我已经要求提供无效版本(不应该只是恢复到可用版本吗?)

知道发生了什么事吗?这特别令人恼火,因为我指定了#version并且我没有使用变量关键字。

1 个答案:

答案 0 :(得分:0)

我相信#version 150 core应该出现在着色器文件的最顶部,其后有一个空行,并引用corelegacyes。 ..