So I've been learning OpenGL and decided to write a small static function for loading shaders from files. Here it is :
std::string HM::GetShaderSource(std::string filename)
{
std::string shaderSource = "";
std::string line = "";
std::ifstream shaderFile(filename);
if (shaderFile.is_open())
{
while (getline(shaderFile, line))
{
shaderSource.append(line + "\n");
}
shaderFile.close();
}
else std::cout << "Unable to open shader file : " << filename << std::endl;
std::cout << " first output : " << std::endl << (const GLchar *)shaderSource.c_str() << std::endl;
return shaderSource;
}
Then I call it out in my code like this :
const char * vertexShaderSource = HM::GetShaderSource("VertexShader.txt").c_str();
std::cout << "second output: " << vertexShaderSource << std::endl;
std::cout << "third output: " << HM::GetShaderSource("VertexShader.txt").c_str() << std::endl;
And this prints out :
first output: ...Normal Shader Code...
second output: second output: ▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌
▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌7
first output: ...Normal Shader Code...
third output: ...Normal Shader Code...
So why is it behaving so oddly? Why when I place this in a variable it gives this strange output?