This is more of a basic C/C++ question. I’m using ifstream to read from a text file the shader program. glShaderSource needs that shader code in the form of GLchar **. Is there anyway to get a const char * array that is just large enough to hold all the lines in the code? Or is there some other way I’m not seeing?
fstream shaderFile( filePath, ios::in );
if ( shaderFile.is_open() )
{
std::stringstream buffer;
buffer << shaderFile.rdbuf();
shader = buffer.str();
}
That’s basically what I’m doing and I’m passing shader.c_str(). However, the shader is failing to compile. One thing I don’t understand though, if my shaders are failing to link and compile (and they obviously are since my triangles are not being colored blue), but I’m still getting two white triangles. I thought shaders were needed to do everything in the core profile?
// load and compile vertex shader
string shaderProgramText;
const char* text = getShaderProgram( shaderInfo.vShaderFile, shaderProgramText );
GLint length = shaderProgramText.size();
glShaderSource( GL_VERTEX_SHADER, 1, (const GLchar**)&text, (GLint*)&length );
glCompileShader( shaderObject );
I’ve also checked my c_str, and it has all the shader code with newlines. Should I be inserting ‘\0’ and setting the last parameter of glShaderSource to NULL instead?
EDIT:
I used glGetShaderiv and got:
Shader compilation failed…
(0) : error C0000: syntax error, unexpected $end at token “<EOF>”
What does this mean?