gpt4 book ai didi

qt - GLSL 给出奇怪的错误 : "#version required and missing" only on mac

转载 作者:行者123 更新时间:2023-12-05 08:12:09 25 4
gpt4 key购买 nike

我有一个奇怪的、非常令人沮丧的问题。我有一个在 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 并且没有使用 varying 关键字。

最佳答案

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

关于qt - GLSL 给出奇怪的错误 : "#version required and missing" only on mac,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25297114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com