Can't retrieve error report from failure compilation of shaders

Here is the function to "load" my shader, I did some test by print out the length of the error report in a console, it seems that the length is 0....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
GLuint System::SysCreateShader(GLenum shadertype, std::string &source)
{
    GLuint shader = glCreateShader(shadertype);

    const char* sourceptr = source.c_str();
    glShaderSource( shader, 1, &sourceptr, NULL);

    GLint status;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
    if (status == GL_FALSE)
    {
        int error_log_length;
        GLchar *error_log = new GLchar[300];
        glGetShaderiv(shader, GL_INFO_LOG_LENGTH+1, &error_log_length);
        glGetShaderInfoLog(shader, error_log_length+1, NULL, error_log);

        char* strshadertype;
        switch (shadertype)
        {
            case GL_VERTEX_SHADER: strshadertype = "Vertex Shader"; break;
            case GL_FRAGMENT_SHADER: strshadertype = "Fragment Shader"; break;
            case GL_GEOMETRY_SHADER: strshadertype = "eometry Shader"; break;;
        }

        fprintf(stderr, "shader compile failure in %s, \n %s \n", strshadertype, error_log);
        delete [] error_log;
    }
    return shader;
}



With the same approach to load or link shaders into a program, but this one work totally fine...I really have no idea what is the problems with the previous code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
void System::SysCreateProgram(GLuint &program)
{
    program = glCreateProgram();

    std::vector <GLuint> shader_array;
    std::string vertexshaderstr, fragmentshaderstr;

    SysReadFileToStr("FragmentShader.txt", fragmentshaderstr);
    SysReadFileToStr("VertexShader.vs", vertexshaderstr);

    shader_array.push_back(SysCreateShader(GL_VERTEX_SHADER, vertexshaderstr));
    shader_array.push_back(SysCreateShader(GL_FRAGMENT_SHADER, fragmentshaderstr));

    glAttachShader(program, shader_array[0]);
    glAttachShader(program, shader_array[1]);

    glLinkProgram(program);

    GLint status;
    glGetProgramiv(program, GL_LINK_STATUS, &status);
    if (status == GL_FALSE)
    {
        int error_log_length;
        GLchar *error_log = new GLchar[300];
        glGetProgramiv(program, GL_INFO_LOG_LENGTH, &error_log_length);
        glGetProgramInfoLog(program, error_log_length, NULL, error_log);

        fprintf(stderr, "Lingkage error: %s \n", error_log);
        delete [] error_log;
    }


    sysprogram = program;

}
Instead of this, you can use ARB_debug_output which generally gives you shader compiler messages.
Silly me, forgot glCompile...Any way thanks NoXzema, that can be useful for me in future
Topic archived. No new replies allowed.