Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Why isn't my shader linking?

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    11

    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\n",
    (GLchar*) "uniform sampler2D vertTexture; \n",
    (GLchar*) "uniform sampler2D normTexture; \n",
    (GLchar*) "uniform vec3 sunpos; \n",
    (GLchar*) "uniform vec4 transMatrix; \n",
    (GLchar*) "in vec2 vPosition; \n",
    (GLchar*) "out float color; \n",
    (GLchar*) "out float diff; \n",
    (GLchar*) "void main () { \n",
    (GLchar*) " vec2 tpos = vec2(vPosition.xy); \n",
    (GLchar*) " tpos.x = (tpos.x * transMatrix.b) + transMatrix.r; \n",
    (GLchar*) " tpos.y = (tpos.y * transMatrix.a) + transMatrix.g; \n",
    (GLchar*) " vec4 vert = texture(vertTexture, tpos); \n",
    (GLchar*) " vec3 norm = texture(normTexture, tpos).xyz; \n",
    (GLchar*) " color = clamp(((vert.y / 1.5f) + 400.0f) / 5120.0f, 0.02f, 1.0f); \n",
    (GLchar*) " diff = clamp(dot(norm.xyz, normalize(sunpos - vert.xyz)), 0.6f, 1.0f); \n",
    (GLchar*) " gl_Position = gl_ModelViewProjectionMatrix * vert; \n",
    (GLchar*) "}"
    };

    GLchar *TerrainFragmentShaderStr[] = {
    (GLchar*) "#version 120\n",
    (GLchar*) "uniform sampler1D colorTexture; \n",
    (GLchar*) "uniform sampler2D grndTexture; \n",
    (GLchar*) "in float color; \n",
    (GLchar*) "in float diff; \n",
    (GLchar*) "void main () { \n",
    (GLchar*) " vec4 vcolor = texture1D(colorTexture, color); \n",
    //" vec4 tcolor = texture(grndTexture, texCrd); \n",
    (GLchar*) " gl_FragColor = vcolor * diff; \n",
    (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.
    Attached Files Attached Files

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,714
    Code :
    #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.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    11
    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:
    Code :
    "#version 120\n",
    "uniform vec3 sunpos;                               \n",
    "in vec4 vPosition;                                 \n",
    "in vec3 vNormal;                                   \n",
    "in vec4 vColor;                                    \n",
    "in vec2 vTexCoord;                                 \n",
    "out vec2 texCrd;                                   \n",
    "out float color;                                   \n",
    "out float diff;                                    \n",
    "void main () {                                     \n",
    "  texCrd = vTexCoord;                              \n",
    "  color = clamp(((gl_Vertex.y / 1.5f) + 400.0f) / 5120.0f, 0.02f, 1.0f);   \n",
    "  diff = clamp(dot(vNormal.xyz, normalize(sunpos - gl_Vertex.xyz)), 0.6f, 1.0f);                  \n",
    "  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;                      \n",
    "}"
    };

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941
    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.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    11
    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.

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

    Any other pointers?

  6. #6
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    11
    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

    Code :
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •