I'm trying to use simple glsl shader loaded from file. This is what I have:
GLuint
shdld(char *path) {
GLuint shd;
GLint cflag, nlog;
FILE *fp;
int i, c;
GLchar source[1000], elog[1000];
fp = fopen(path, "r");
if (fp == NULL) {
printf("Unable to open file %s\n", path);
return 0;
}
for (i = 0; (c = getc(fp)) != EOF; i++)
source[i] = c;
source[i++] = '\0';
fclose(fp);
shd = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(shd, 1, source, NULL);
glCompileShader(shd);
cflag = GL_FALSE;
glGetShaderiv(shd, GL_COMPILE_STATUS, &cflag);
if (cflag == GL_FALSE) {
glGetShaderInfoLog(shd, sizeof elog, NULL, elog);
printf("Unable to compile shader %s\n", path);
printf("%s\n", elog);
glDeleteShader(shd);
return 0;
}
return shd;
}
Unfortunately the shader doesn't compile and what is worse elog contains some garbage content instead the log message. My question is: How to get the error message and display it into stdout in order to debug my shader?