Shader program linking issue

Started by
10 comments, last by Kametec 10 years, 12 months ago

Are you really sure that the shaders are correct? Why you're doing stuff like this:


GLchar **str = new GLchar*[1];

Not sure how that pointer works, too sleepy. I'd probably write it like this, much simpler:


char *str = new char[256]; 
memset(str, 0, 256);
readvertexshader();
memset(str, 0, 256);
readfragmentshader();
// ...
glShaderSource(fShad, 1, (const char**)&str, NULL);
// and now you can really make sure that you have the actual shader source there, just print it out
printf("shader source:\n%s\n", str);

Actually... I think you should have written (const char**)&str[1] before, because of that weird pointer thingie you were doing. I tried your code on my computer and seemed to work ok with those changes, had to change version numbers too though, my card doesn't support OpenGL 4.0.

Edit: And oh, seemed like I had to call ifs.close() too, not sure if this is only like this on Linux? I think it clears the eof bit, too lazy to check out. Sleep I goes.

Derp

Advertisement

Hi,

thanks for your reply, it helped me to solve the problem. The error was caused by missing ifs.close(), and the second shader wasn't read correctly because of it.

As to why I used GLchar **str, well, I'm starting to learn C++ as well as OpenGL. I have some experience with other languages, though. I've read in documentaion that glShaderSource accepts GLchar **, so I declared my variable as GLchar **. Thinking of it as two-dimensional array helped me to get it running.

Now, that I am familiar with & and * operators I admit you're right, and I will use an array of GLchar passed as &arr_name in future code.

In summary: I've included ifs.close() and the whole issue dissapeared. I didn't do anything else, so I managed to get file reading to work properly.

Thanks again.

This topic is closed to new replies.

Advertisement