0

I'm having trouble getting OpenGL to work properly. It fails on all shaders and simply returns an info log with the length of 0.

To see if it was in fact OpenGL, I created a little piece of code to test it:

GLuint s = glCreateShader(GL_VERTEX_SHADER);

const char *src = "bad\nsource\ncode";

glShaderSource(s, 1, &src, 0);

GLint len;
glGetShaderiv(s, GL_INFO_LOG_LENGTH, &len);

std::vector<char> buffer(len+1);
glGetShaderInfoLog(s, len, 0, buffer.data());
buffer[len] = '\0';

std::cout << len << std::endl;

std::cout << buffer.data() << std::endl;

And when ran, it simply prints 0 to the console.

What's happening?

1 Answer 1

4

You need to compile your shader in order to get an errorlog.

Pseudo Code:

glCompileShader(shader);

GLint status;
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if(status == GL_FALSE) {
    GLint infolog_length;
    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infolog_length);

    GLchar[] infolog = new GLchar[infolog_length+1];
    glGetShaderInfoLog(shader, infolog_length, null, infolog.ptr);

    // print infolog etc.
}

From The Documentation:

glGetShaderInfoLog returns the information log for the specified shader object. The information log for a shader object is modified when the shader is compiled. The string that is returned will be null terminated.

Sign up to request clarification or add additional context in comments.

3 Comments

The failure to call glCompileShader was actually a mistake in my test code (absent in the real code) that I didn't catch. But at least I know now OpenGL isn't broken. Interestingly enough, I did call compile on my actual shaders, but the mistake was due certain constructors not working right and resulting in the shaders not being initialized properly.
Side note: you can (should?) get the info log even when compilation succeeds. For instance, the driver can put warnings in there.
another side note: GL implementations are not required to put anything into the info logs, even when compilation/linking fails, so always returning a log size of 0 bytes would still be compliant to the spec.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.