Why isn't my shader linking?

I’m having a bit of a problem linking my shaders. They seam to build fine, but the vertex shader continually fails to link, without indicating what’s causing the link to fail. I’ve included source for a simple app which builds and links the shaders, which I am using to test at the moment, since I can’t seam to get to the point where I’m evaluating what the shaders are doing to the screen. Any ideas?

My current shaders:

GLchar TerrainVertexShaderStr[] = {
(GLchar
) "#version 120
",
(GLchar*) "uniform sampler2D vertTexture;
",
(GLchar*) "uniform sampler2D normTexture;
",
(GLchar*) "uniform vec3 sunpos;
",
(GLchar*) "uniform vec4 transMatrix;
",
(GLchar*) "in vec2 vPosition;
",
(GLchar*) "out float color;
",
(GLchar*) "out float diff;
",
(GLchar*) "void main () {
",
(GLchar*) " vec2 tpos = vec2(vPosition.xy);
",
(GLchar*) " tpos.x = (tpos.x * transMatrix.b) + transMatrix.r;
",
(GLchar*) " tpos.y = (tpos.y * transMatrix.a) + transMatrix.g;
",
(GLchar*) " vec4 vert = texture(vertTexture, tpos);
",
(GLchar*) " vec3 norm = texture(normTexture, tpos).xyz;
",
(GLchar*) " color = clamp(((vert.y / 1.5f) + 400.0f) / 5120.0f, 0.02f, 1.0f);
",
(GLchar*) " diff = clamp(dot(norm.xyz, normalize(sunpos - vert.xyz)), 0.6f, 1.0f);
",
(GLchar*) " gl_Position = gl_ModelViewProjectionMatrix * vert;
",
(GLchar*) “}”
};

GLchar TerrainFragmentShaderStr[] = {
(GLchar
) "#version 120
",
(GLchar*) "uniform sampler1D colorTexture;
",
(GLchar*) "uniform sampler2D grndTexture;
",
(GLchar*) "in float color;
",
(GLchar*) "in float diff;
",
(GLchar*) "void main () {
",
(GLchar*) " vec4 vcolor = texture1D(colorTexture, color);
“,
//” vec4 tcolor = texture(grndTexture, texCrd);
",
(GLchar*) " gl_FragColor = vcolor * diff;
",
(GLchar*) “}”
};

The output from my execution:

OpenGL Version: 2.1.8543 Release
GLSL Version: 1.20
Compiling vertex shader:
Vertex shader was successfully compiled to run on hardware.

Compiling fragment shader:
Fragment shader was successfully compiled to run on hardware.

Creating progrem:
Fragment shader(s) linked, vertex shader(s) failed to link.


#version 120
...
in vec2 vPosition;
out float color;
out float diff;

in and out are defined in GLSL 1.30 and above. You should be getting a compiler error in your shader compiling.

That odd, considering the previous incarnation of this shader (below) compiled and linked fine. And the problems I’m experiencing are in the linker and not the compiler. This is being run on a Radeon X1200, changing it isn’t an option. The only real difference between the two is that I’m grabbing a couple of texel’s with texture2D calls.

This is supported in GLSL 1.20, and I haven’t been able to find anything saying the drivers I’m using are an exception to that.

My previous working shader:

"#version 120
",
"uniform vec3 sunpos;                               
",
"in vec4 vPosition;                                 
",
"in vec3 vNormal;                                   
",
"in vec4 vColor;                                    
",
"in vec2 vTexCoord;                                 
",
"out vec2 texCrd;                                   
",
"out float color;                                   
",
"out float diff;                                    
",
"void main () {                                     
",
"  texCrd = vTexCoord;                              
",
"  color = clamp(((gl_Vertex.y / 1.5f) + 400.0f) / 5120.0f, 0.02f, 1.0f);   
",
"  diff = clamp(dot(vNormal.xyz, normalize(sunpos - gl_Vertex.xyz)), 0.6f, 1.0f);                  
",
"  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;                      
",
"}"
};

As far as I remember, for pre-HD2000 Radeon cards the drivers seem to not do anything at compile time but the compilation was also done at link time thus despite you don’t get an actual compile error but a link error, it is most likely because of the ‘in’ and ‘out’ stuff. As Alfonse noted, those are only available in GLSL 1.30 which was introduced together with OpenGL 3.0 which targeted HD2000+ cards thus it’s definitely not supported on the X1200. So please try to use a valid shader at least as what you wrote (even if the first version happened to work) is just not a valid GLSL 1.20 shader.

I apologise. I shouldn’t ask for help then dump on the response given when it goes contrary to what I understand, since if I understood it I wouldn’t need to ask. I’ve modified the shaders to be the following, which I believe are valid 1.2 shaders.

I’m getting the same error. As informative as the error “vertex shader (s) failed to link” is.

GLchar *TerrainVertexShaderStr[] = {
    (GLchar*) "#version 120
",
    (GLchar*) "uniform sampler2D vertTexture;                         
",
    (GLchar*) "uniform sampler2D normTexture;                         
",
    (GLchar*) "uniform vec3 sunpos;                                   
",
    (GLchar*) "uniform vec4 transMatrix;                              
",
    (GLchar*) "attribute vec2 vPosition;                                     
",
    (GLchar*) "varying vec2 texCrd;                                    
",
    (GLchar*) "varying float color;                                       
",
    (GLchar*) "varying float diff;                                        
",
    (GLchar*) "void main () {                                         
",
    (GLchar*) "  vec2 tpos = vec2(gl_Vertex.xy);                      
",
    (GLchar*) "  tpos.x = (tpos.x * transMatrix.b) + transMatrix.r;   
",
    (GLchar*) "  tpos.y = (tpos.y * transMatrix.a) + transMatrix.g;   
",
    (GLchar*) "  vec4 vert = texture2D(vertTexture, tpos).xyzw;              
",
    (GLchar*) "  vec3 norm = texture2D(normTexture, tpos).xyz;          
",
    (GLchar*) "  color = clamp(((vert.y / 1.5f) + 400.0f) / 5120.0f, 0.02f, 1.0f); 
",
    (GLchar*) "  diff = clamp(dot(norm.xyz, normalize(sunpos - vert.xyz)), 0.6f, 1.0f); 
",
    (GLchar*) "  texCrd = vec2(vPosition.xy); 
",
    (GLchar*) "  gl_Position = gl_ModelViewProjectionMatrix * vert; 
",
    (GLchar*) "}"
};

GLchar *TerrainFragmentShaderStr[] = {
    (GLchar*) "#version 120
",
    (GLchar*) "uniform sampler1D colorTexture;                    
",
    (GLchar*) "uniform sampler2D grndTexture;                     
",
    (GLchar*) "varying vec2 texCrd;                                    
",
    (GLchar*) "varying float color;                                    
",
    (GLchar*) "varying float diff;                                     
",
    (GLchar*) "void main () {                                     
",
    (GLchar*) "  vec4 vcolor = texture1D(colorTexture, color);    
",
    (GLchar*) "  vec4 tcolor = texture2D(grndTexture, texCrd);      
",
    (GLchar*) "  gl_FragColor = vcolor * diff;     
",
    (GLchar*) "}"
};

Any other pointers?

It seams as though I’m SOL with regards to using textures in my vertex shader. Another user with a similar problem found a solution and got me thinking about things and unless I’m mistaken when a call to

glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &value)

returns 0, nothing I try is going to get a sampler2D to work in the vertex shader.

Thank you for the info on in/out, and your help to date.