I'm getting started with OpenGL. I'm trying to get my first program working, but I have no luck so far and I have no idea why. My test program is inspired by the first program in a book named "OpenGL Programming Guide, The Official Guide to Learning OpenGL, Version 4.3, Eight Edition".

I've written both vertex and fragment shaders, I've written code to initialize FreeGlut, GLEW, compile the shaders and link the shader program. But I have issues with the linking proccess. The output of glGetProgramInfoLog is this:

Vertex shader(s) failed to link, fragment shader(s) failed to link.
Vertex link error: INVALID_OPERATION.
ERROR: error(#97) No program main found
fragment link error: INVALID_OPERATION.
ERROR: error(#97) No program main found

Hmm... At least from what I know you have to append a "/n" after reading each line of the shader.

You have to append new lines only if you're using a reading function, which discards them. Such as std::istream::getline. I am sure I'm passing the file content as is, including line breaks. I believe I would be getting compile errors otherwise.

i usually (at least in testing) call glGetError() after each line to ensure i get the root error and not a trickle error.

so either your error is above the glGetProgram line OR the envirnoment you are using doesn't support GL_LINK_STATUS

I've included a function which calls glGetError() and writes the error, together with an info string passed as parameter, to cout. I've got this output:

You need to have a context in use before calling glewInit, so just after glutInit isn't probably enough, call it after you've created the window and context. And btw, what happens when you read the last character from the text file? Isn't that appending EOF character into your string?

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.

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.