Problem with fragment shader code

Hi - I’m learning to use OpenGL and am following an online tutorial. However, the code for the shaders that they supply to begin with were written for version 1.5 and I am running version 1.2
I have spent a good couple of hours trying to figure out what is wrong by looking on the internet and modifying the code appropriately to account for the differences between the two versions. However I am currently stuck with the vertex shader (I think the fragment shader is OK) and I keep getting the

ERROR: 0:3: '' : syntax error #version

which apparently means something is still wrong with the code. Any help would be appreciated and I’m sure it’s really simple but I’m just not able to fix it…

Fragment shader



#version 120 core

out vec4 gl_FragColor;

void main()
{
    gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}

Vertex Shader


#version 120 core

in vec2 in_Vertex;

void main()
{
    gl_Position = vec4(in_Vertex, 0.0, 1.0);
}

(Compiling with Mac OSX 10.9.2 Xcode)

To fix those shaders for #120, they should look like this:


#version 120
attribute vec2 in_Vertex;
void main()
{
    gl_Position = vec4(in_Vertex, 0.0, 1.0);
}


#version 120
void main()
{
    gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}

Because:

  1. the “core” profile qualifier didn’t exist in #120. It was introduced in #150 (and defaults to “core”, so you never need to use it on OSX.)
  2. vertex "in"puts are "attribute"s in #120. Vertex "out"puts and fragment "in"puts are "varying"s.
  3. gl_FragColor is pre-declared in #120, and you can’t re-declare it. In #150 core, you can’t use gl_FragColor, you must declare your own "out"put.

It should only take a couple of hours to read the definitive GLSL references and then all of these differences should be clear.

(Compiling with Mac OSX 10.9.2 Xcode)

On OSX you could use the #150 shaders as-is, if you create a Core Profile context.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.