OpenGL着色器阅读器返回垃圾字符



为什么这个函数:

string Utils::readShaderFile(const char* filePath) {
string content;
ifstream fileStream(filePath, ios::in);
string line = "";
while (!fileStream.eof()) {
getline(fileStream, line);
content.append(line + "n");
}
fileStream.close();
return content;
}

返回
 ■#version 430
void main(void)
{
if (gl_VertexID == 0) gl_Position = vec4(0.25, -0.25, 0.0, 1.0);
else if (gl_VertexID == 1) gl_Position = vec4(-0.25, -0.25, 0.0, 1.0);
else gl_Position = vec4(0.25, 0.25, 0.0, 1.0);
}

在第一行有一些垃圾字符?

我相信这就是为什么我得到着色器编译错误的原因:

Vertex Shader compilation error.
Shader Info Log: 0(1) : error C0000: syntax error, unexpected $undefined at token "<undefined>"

所以,问题是我用命令提示符echo "" >> shader.glsl创建了我的shader .glsl文件,它在文件的开头设置了一些奇怪的字符。

在我通过VS2019add item选项创建文件后,它运行良好。

最新更新