PDA

View Full Version : AARG!! glShaderSourceARB



Jan
01-22-2004, 01:10 PM
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.




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.

Ostsol
01-22-2004, 02:36 PM
Try adding a carriage return character at the end of each line. Like this:



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");

Korval
01-22-2004, 02:38 PM
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.

PanzerSchreck
01-22-2004, 03:08 PM
Since I'm no C-Coder I may be totally wrong, but why that :


glShaderSourceARB (FragmentShaderObject, 1, (const GLcharARB**) ShaderText, NULL);
You're supposed to pass the length of the shader as the last parameter.

jra101
01-22-2004, 03:45 PM
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.

evanGLizr
01-22-2004, 06:19 PM
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.




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 http://www.opengl.org/discussion_boards/ubb/wink.gif ).

Instead, use something like



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).

Jan
01-23-2004, 03:42 AM
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.

Jan
01-23-2004, 03:55 AM
Yeah, evanGLizr was right.

Thanks, man!