It seems I can't have my GLSL shaders compiled. Once in a while (mainly after editing a file), I get following error while compiling:
----- SRC ----- (150 B) #version 330 core uniform mat4 mvpMatrix; in vec4 vertexPosition_modelspace; void main() { gl_Position = mvpMatrix * vertexPosition_modelspace; } gp! ----- END ----- SimpleTransform.vertexshader:Vertex shader failed to compile with the following errors: ERROR: 0:10: error(#132) Syntax error: 'gp' parse error ERROR: error(#273) 1 compilation errors. No code generated It's quite strange since I swear the file doesn't contain that awkward gp! part. Nevertheless I investigated it with cat
#version 330 core uniform mat4 mvpMatrix; in vec4 vertexPosition_modelspace; void main() { gl_Position = mvpMatrix * vertexPosition_modelspace; } and less
#version 330 core uniform mat4 mvpMatrix; in vec4 vertexPosition_modelspace; void main() { gl_Position = mvpMatrix * vertexPosition_modelspace; } and both of them proved me right.
I wonder what's causing this strange behaviour.
Here's link to my project. You should be able to easily compile it by entering src directory and typing make (Linux only). It requires GLFW, GLEW, GLM and GL3.
And the code itself:
Loading shader files
GLuint shader_load(GLenum type, const char filename[]) { if ((type != GL_VERTEX_SHADER && type != GL_FRAGMENT_SHADER) || !filename) return 0; /* wczytywanie pliku shadera */ FILE *file = fopen(filename, "rb"); //okreslenie rozmiaru pliku fseek(file, 0, SEEK_END); uint32 iFileSize = ftell(file); fseek(file, 0, SEEK_SET); //wczytywanie char *tmp = new char[iFileSize]; memset(tmp, 0, sizeof(tmp)); uint32 iBytes = (uint32) fread(tmp, sizeof(char), iFileSize, file); fclose(file); if (iBytes != iFileSize) printf("Warning: reading error possible!\n"); #ifdef _DEBUG_ printf("----- SRC ----- (%d B)\n%s\n----- END -----\n", iBytes, tmp); #endif /* przygotowanie shadera */ GLuint shader = glCreateShader(type); glShaderSource(shader, 1, const_cast<const GLchar**>(&tmp), NULL); delete[] tmp; glCompileShader(shader); //kompilacja shadera /* sprawdzenie statusu kompilacji */ int status = GL_FALSE; glGetShaderiv(shader, GL_COMPILE_STATUS, &status); int logsize = 0; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logsize); char *log = new char[logsize]; glGetShaderInfoLog(shader, logsize, NULL, log); printf("%s:%s", filename, log); delete[] log; if (status != GL_TRUE) return 0; return shader; }
std::stringinstead of juggling raw arrays,memset, off-by-ones and hairy casts :)