简体   繁体   English

使用QGLShaderProgram时GLSL编译错误

[英]GLSL compilation error when using QGLShaderProgram

I'm currently trying out some of the opengl components in Qt 5, I'm compiling on Mac OSX 10.8 with QtCreator 2.6.2, clang 4.2 I've written a very basic GLSL shader that compiles and links well in OpenGl Shader Builder, but when I try to load it using a QGLShader, it fails to compile and the log function returns no error message. 我目前正在尝试使用Qt 5中的一些opengl组件,正在使用QtCreator 2.6.2和clang 4.2在Mac OSX 10.8上进行编译。我编写了一个非常基本的GLSL着色器,可以很好地在OpenGl Shader Builder中进行编译和链接,但是当我尝试使用QGLShader加载它时,它无法编译,并且log函数未返回任何错误消息。

Vertex Shader: 顶点着色器:

attribute vec4 in_position;
attribute vec3 in_normal;
attribute vec3 in_color;
attribute vec2 in_tex;

uniform vec4 lightPosition;

varying vec2 texCoords;
varying vec3 normal;
varying vec3 vertToLightDir;

void main(void)
{
    gl_Position = gl_ModelViewProjectionMatrix * in_position;
    vec4 worldVert = gl_ModelViewMatrix * in_position;
    vertToLightDir = normalize(vec3(lightPosition - worldVert));
    normal = gl_NormalMatrix * in_normal;
    texCoords = in_tex;
}

Fragment Shader: 片段着色器:

uniform sampler2D texture0;
uniform vec4 lightColor;

varying vec2 texCoords;
varying vec3 normal;
varying vec3 vertToLightDir;

void main(void)
{
    float lightIntensity = clamp(dot(normal, vertToLightDir), 0.0, 1.0);
    gl_FragColor = (texture2D(texture0, texCoords) + (lightColor * lightIntensity)) * 0.5;
}

The code that loads the shaders: 加载着色器的代码:

QGLShader fragShader(QGLShader::Fragment);
bool success = fragShader.compileSourceFile("Fragment.glsl");
qDebug() << fragShader.log();

I used the debugger to see that the compileSourceFile function returns false, I also used access("Fragment.glsl", F_OK) to see if the program manages to find the file and it does, the same goes for the vertex shader file, I can't seem to find the reason they won't compile. 我使用调试器查看compileSourceFile函数返回false,还使用了access(“ Fragment.glsl”,F_OK)来查看程序是否设法找到了文件,并且确实如此,顶点着色器文件也是如此似乎找不到他们无法编译的原因。 Is there something I'm doing wrong ? 我在做错什么吗?

After some debugging I realized I was trying to compile the shaders before a valid context was created. 经过一些调试后,我意识到我正在尝试在创建有效上下文之前编译着色器。 My bad. 我的错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM