0
votes

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.

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. Is there something I'm doing wrong ?

1
Where are your #version directives? - genpfault
@genpfault It's been a while since I last wrote shaders, I never knew about the #version directive, however adding a #version 140 doesn't change anything - Radu Chivu

1 Answers

1
votes

After some debugging I realized I was trying to compile the shaders before a valid context was created. My bad.