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 8 of 8

Thread: AARG!! glShaderSourceARB

  1. #1
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    AARG!! glShaderSourceARB

    DAMN!!

    I feel really stupid, but i donīt know why this does not work. I could not find any tutorial showing how to use this function properly, since this is such a trivial thing.

    Code :
    char ShaderText[1][1024];
     
    strcpy (ShaderText[0], 
    "uniform sampler2D Texture0;\
    uniform sampler2D Texture1;\
    uniform sampler2D Texture2;\
    uniform sampler2D Texture3;\
    \
    void main(void)\
    {\
    vec2 TexCoord = vec2( gl_TexCoord[0] );\
    vec4 RGB      = texture2D( Texture0, TexCoord );\
    \
    gl_FragColor  = texture2D(Texture1, TexCoord) * RGB.r +\
    texture2D(Texture2, TexCoord) * RGB.g +\
    texture2D(Texture3, TexCoord) * RGB.b;\
     }\0\0\0");
     
    glShaderSourceARB (FragmentShaderObject, 1, (const GLcharARB**) ShaderText, NULL);
    The function glShaderSourceARB simply crashes. I donīt know why, i have tried everything.
    Note that all obects (FragmentShaderObject, etc.) are created, i just didnīt post the code for it.

    Itīs the first time i try to get glSlang running, the piece of shader-code is just a copy out of a tutorial, it should not have any effect.

    Thanks in advance,
    Jan.
    GLIM - Immediate Mode Emulation for GL3

  2. #2
    Member Regular Contributor
    Join Date
    Jan 2003
    Location
    Edmonton, Alberta, Canada
    Posts
    320

    Re: AARG!! glShaderSourceARB

    Try adding a carriage return character at the end of each line. Like this:
    Code :
    char ShaderText[1][1024];
     
    strcpy (ShaderText[0], 
    "uniform sampler2D Texture0;\n\
    uniform sampler2D Texture1;\n\
    uniform sampler2D Texture2;\n\
    uniform sampler2D Texture3;\n\
    \n\
    void main(void)\n\
    {\n\
    vec2 TexCoord = vec2( gl_TexCoord[0] );\n\
    vec4 RGB      = texture2D( Texture0, TexCoord );\n\
    \n\
    gl_FragColor  = texture2D(Texture1, TexCoord) * RGB.r +\n\
    texture2D(Texture2, TexCoord) * RGB.g +\n\
    texture2D(Texture3, TexCoord) * RGB.b;\n\
     }\0\0\0");

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,576

    Re: AARG!! glShaderSourceARB

    Since a crashing OpenGL function is usually a violation of the spec, unless you pass an invalid pointer, you should send a bug report to the people who made your GL implementation.

  4. #4
    Junior Member Regular Contributor
    Join Date
    May 2003
    Location
    Germany
    Posts
    229

    Re: AARG!! glShaderSourceARB

    Since I'm no C-Coder I may be totally wrong, but why that :
    Code :
    glShaderSourceARB (FragmentShaderObject, 1, (const GLcharARB**) ShaderText, [i]NULL[/i]);
    You're supposed to pass the length of the shader as the last parameter.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Jan 2001
    Location
    NVIDIA, Austin, TX
    Posts
    555

    Re: AARG!! glShaderSourceARB

    If you pass NULL as the last parameter of glShaderSourceARB, it will calculate the length itself, which means you must null terminate the string you pass in.

  6. #6
    Junior Member Regular Contributor
    Join Date
    Jun 2001
    Posts
    183

    Re: AARG!! glShaderSourceARB

    Originally posted by Jan2000:
    DAMN!!

    I feel really stupid, but i donīt know why this does not work. I could not find any tutorial showing how to use this function properly, since this is such a trivial thing.

    Code :
    char ShaderText[1][1024];
    [...]
    glShaderSourceARB (FragmentShaderObject, 1, (const GLcharARB**) ShaderText, NULL);
    [...]
    The function glShaderSourceARB simply crashes. I donīt know why, i have tried everything.
    ShaderText must be an array of pointers to char but it's not (C Programming 101 ).

    Instead, use something like
    Code :
    GLchar ARB *pLonelyShader;
    pLonelyShader = ShaderText[0];
    glShaderSourceARB (FragmentShaderObject, 1, (const GLcharARB**) &pLonelyShader, NULL);
    Another thing, putting \0\0\0 at the end of your string is not very useful, as strcpy is only going to copy until the first null char (and anyways C already null terminates all literal strings).

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: AARG!! glShaderSourceARB

    Originally posted by evanGLizr:
    Another thing, putting \0\0\0 at the end of your string is not very useful, as strcpy is only going to copy until the first null char (and anyways C already null terminates all literal strings).
    Yeah, i know that. The "\0\0\0" was just a result of my desperate attempt to make it work :-)

    Anyway thanks to all of you for your answers, i will try it immediatly.

    Jan.
    GLIM - Immediate Mode Emulation for GL3

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: AARG!! glShaderSourceARB

    Yeah, evanGLizr was right.

    Thanks, man!
    GLIM - Immediate Mode Emulation for GL3

Posting Permissions

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