I'm trying to load a simple GLSL program from a .txt
file. Here is the function which loads the file:
string getShaderSource(char path[])
{
string out;
ifstream mFile;
stringstream buf;
mFile.open(path);
if (mFile.is_open())
{
buf << mFile.rdbuf();
out = buf.str();
}
else
printf("Cannot open shader source file.");
mFile.close();
//out.append("\0");
return out;
}
And I use use the function like this:
string vs = getShaderSource("C:/vs.txt");
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, (const GLchar**)&vs, NULL);
Problem is the shader doesn't compiles no matter what, here is the error:
0(1) : error C0000: syntax error, unexpected $undefined at token "<undefined>"
Very simple GLSL code:
#version 410
layout (location = 0) in vec3 vp;
layout (location = 1) in vec3 color;
smooth out vec4 theColor;
void main () {
gl_Position = vec4 (vp, 1.0);
theColor = vec4(color, 0.0);
}
I know there are similar questions out there, I've tried a lot to fix the problem but no progress. What am I doing wrong?