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.

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.

Try adding a carriage return character at the end of each line. Like this:

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

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.

Since I’m no C-Coder I may be totally wrong, but why that :

glShaderSourceARB (FragmentShaderObject, 1, (const GLcharARB**) ShaderText, [i]NULL[/i]);

You’re supposed to pass the length of the shader as the last parameter.

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.

Originally posted by Jan2000:
[b]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.

[quote]

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.
[/b][/QUOTE]

ShaderText must be an array of pointers to char but it’s not (C Programming 101 ).

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

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 :slight_smile:

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

Jan.

Yeah, evanGLizr was right.

Thanks, man!

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