View Full Version : GLSL compile error

11-10-2011, 08:39 AM
Hi everyone.
It's my first approach to GLSL. I'm trying to run a simple program but I found some problems and I don't know how to fix them.

The program doesn't compile my shaders, the code is simple:

.vertex shader:

#version 120

uniform mat4 projection_matrix;
uniform mat4 modelview_matrix;

in vec3 a_Vertex;
in vec3 a_Color;
out vec4 color;

void main(void)
vec4 pos = modelview_matrix * vec4(a_Vertex, 1.0);
gl_Position = projection_matrix * pos;
color = vec4(a_Color, 1.0);

fragment shader:

#version 120

in vec4 color;
out vec4 outColor;

void main(void)
outColor = color;

Here is the code that compiles shaders:

GLint result;
glGetShaderiv(shader.id, GL_COMPILE_STATUS, &result);

if(result == GL_FALSE)
std::cout << "Could not compile shader: " << shader.id << ": " << shader.filename << std::endl;
return false;

return true;

The error log is the same for both shaders:

ERROR: 0:6: 'in' : syntax error syntax error
ERROR: Parser found no code to compile in source strings

I' don't know how to fix these errors.
I'm using Xcode for Snow Leopard.
Thank you

11-10-2011, 09:34 AM
Just change the first line from #version 120 to #version 150.
in and out are not defined in GLSL version 120

The problem is that you are using GLSL under Snow Leopard, which does not support GLSL > 120, so you need to use legacy GLSL code.

You need to change in to attribut and out to varying. Check for other version inconsistencies.

11-10-2011, 09:54 AM
Thank you very much!

I've changed in to attribute and out to varying, and used gl_FragColor in fragment shader (instead of out variables), but I don't change version 120 to 150 (I suppose it's not a problem).
Now the program works!
thank you

11-10-2011, 12:31 PM
In fact, if you had change to version 150 it will recognize in and out keywords. The problem is that this version is not supported by snow leopard.