0
votes

What's wrong with this code for a 3.30 OpenGL and GLSL version?

    const char *vertSrcs[2] = { "#define A_MACRO\n", vShaderSrc };
    const char *fragSrcs[2] = { "#define A_MACRO\n", fShaderSrc };
    glShaderSource(vId, 2, vertSrcs, NULL);
    glShaderSource(fId, 2, fragSrcs, NULL);

I gather the shader state with GL_COMPILE_STATUS after the its compiled, get this error:

    Vertex shader failed to compile with the following errors:

The purpose for this macro is to change type qualifier on a color I passed from the vertex to the fragment, maybe there is another way to do that using a uniform and the layout but the question is why would the shader fail? I wonder if there is another OpenGL command which must specify the 2 char pointers. By the way, this works:

 ...
 glShaderSource(vId, 1, &vertSrcs[1], NULL);
 ...

EDIT: since I can't answer my own questions, found the solution

Very strange problem, the string loader happens to be the problem. Without using ifstream along with std::ios::in | std::ios::binary flags, the string was loaded with some garbage information to the end even with null terminated, therefore concatenating the strings will produce the error. For some reason the gl compiler didn't complain before with the single string version, besides calling

inStream.flags(std::ios::in | std::ios::binary)

wasn't enough, it need to be specified when opening, didn't find any doc for this.

1
So...what were the following errors? - genpfault
Unfortunately glGetShaderInfoLog(...); doesn't log anything more, i will let you know if i find why, at least running using the gDEBugger doesn't show any related error and runs good... - notNullGothik
You can answer yourself and accept it. And to avoid problems like the one you had, for this is the last parameter of glShaderSource, to tell OpenGL the length of each source string, thus keeping it from reading into the garbage. - datenwolf

1 Answers

0
votes

The very first nonempty line of a GLSL shader must be a #version preprocessor statement. Anything else is an error.