I am attempting to build a simple OpenGL 3.2 program which consists of a single fragment shader, but I do not seem to be able to actually compile the shader. I'm fairly sure that my shader syntax is correct, but even if it's not, I am unable to retrieve an error message using glGetShaderInfoLog
.
I have developed a short program that shows this in action:
GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
const char *shaderData =
"#version 120\n"
"void main()\n"
"{\n"
" gl_FragColor = gl_Color;\n"
"}\n";
glShaderSource(shader, 1, &shaderData, NULL);
GLint status;
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if (status == GL_FALSE)
{
GLint infoLogLength;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
GLchar* strInfoLog = new GLchar[infoLogLength + 1];
glGetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog);
fprintf(stderr, "Compilation error in shader %s: %s\n", this->name, strInfoLog);
delete[] strInfoLog;
}
This yields the message:
Compilation error in shader Fragment Shader:
The issue seems to be that the call to getShaderiv
to retrieve the GL_INFO_LOG_LENGTH
value returns 0 every time, so therefore I allocate an empty string. I have tried hard-coding this value to 100, but I still receive nothing from getShaderInfoLog
.
My concern here is not to fix the shader (I can do that myself if it is wrong), but to get the debug information. I know that this can be done, because I have used Shader Maker to develop shaders briefly, and I am able to get very detailed debug messages. For example:
ERROR: 0:11: 'undefined_variable' : syntax error syntax error
Unless Shader Marker has its own validation tool internally, I'm sure it has to be using the same method that I am trying to use. I have seen several examples on the internet in which people retrieve the error message for a shader in the same way, so I'm fairly sure I'm doing it correctly.
Now, I am getting a compile-time warning which could potentially explain this problem:
#warning gl.h and gl3.h are both included. Compiler will not invoke errors if using removed OpenGL functionality.
After doing a full text search, I cannot find anywhere where I call #include <OpenGL/gl.h>
, so I am guessing that this header is being included by one of the NSOpenGL*
classes. I'm fairly sure that I'm not using any removed functionality in this short program, and this issue only has about 5 hits on Google, but I thought I'd better mention this anyway.
As noted in a previous comment, the glCompileShader
call was missing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With