看起来我无法编译我的GLSL着色器。有时(主要是在编辑文件后),我在编译时会遇到以下错误:
----- 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
这很奇怪,因为我发誓文件中不包含那个尴尬的 gp!
部分。尽管如此,我用 cat 进行了调查。
#version 330 core
uniform mat4 mvpMatrix;
in vec4 vertexPosition_modelspace;
void main() {
gl_Position = mvpMatrix * vertexPosition_modelspace;
}
并且 更少
#version 330 core
uniform mat4 mvpMatrix;
in vec4 vertexPosition_modelspace;
void main() {
gl_Position = mvpMatrix * vertexPosition_modelspace;
}
他们两个都证明了我的正确性。
我想知道是什么导致了这种奇怪的行为。
这是一个链接到我的项目的链接。您应该能够通过进入src目录并输入make
(仅适用于Linux)轻松编译它。它需要GLFW,GLEW,GLM和GL3。
而且代码本身:
加载着色器文件
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::string
而不是搞乱原始数组、memset
、偏移量和复杂的转换来编写该片段。 - sehe