I'm trying to rewrite the shader loader I was using, and I keep getting the title error when I try to compile my program. My search of related questions turned up these two topics which suggested that the issue might be with my use of strings, so I tried copying the loaded shaders from string objects to arrays, and it's still happening. Here's the relevant section of my Initialize function:
// Begin shader loading
vertShader = glCreateShader(GL_VERTEX_SHADER);
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
// Vertex shader first
vertShaderCode = loader.read("vs.txt");
char codeHolder[vertShaderCode.size() + 1];
std::size_t length = vertShaderCode.copy(codeHolder, vertShaderCode.size(), 0);
codeHolder[length] = '\0';
const char* tmp1 = codeHolder;
// Compile the vertex shader
glShaderSource(vertShader, 1, &tmp1, NULL);
glCompileShader(vertShader);
This is a little more verbose than is probably necessary, but I was trying to be very explicit so I didn't miss anything.
I know my shader loader class is working fine, because in the section where I'm checking the compilation status and printing out error messages, I added in some code to check to make sure everything was being passed correctly:
//check the compile status
glGetShaderiv(vertShader, GL_COMPILE_STATUS, &shader_status);
if (!shader_status)
{
ofstream fout;
fout.open("verification.txt");
fout << vertShaderCode << endl;
int index = 0;
while(tmp1[index] != '\0' && index < 1000)
{
fout << tmp1[index];
index++;
}
fout << endl;
index = 0;
while(codeHolder[index] != '\0' && index < 1000)
{
fout << codeHolder[index];
index++;
}
fout.close();
GLchar InfoLog[1024];
glGetShaderInfoLog(vertShader, sizeof(InfoLog), NULL, InfoLog);
fprintf(stderr, "Vertex Shader %d: '%s'\n", vertShader, InfoLog);
return false;
}
the "verification.txt" file ends up with three copies of the shader code as I would expect:
attributevec3v_position;attributevec3v_color;varyingvec3color;uniformmat4mvpMatrix;voidmain(){gl_Position=mvpMatrix*vec4(v_position,1.0);color=v_color;}
attributevec3v_position;attributevec3v_color;varyingvec3color;uniformmat4mvpMatrix;voidmain(){gl_Position=mvpMatrix*vec4(v_position,1.0);color=v_color;}
attributevec3v_position;attributevec3v_color;varyingvec3color;uniformmat4mvpMatrix;voidmain(){gl_Position=mvpMatrix*vec4(v_position,1.0);color=v_color;}
I know the rest of my program works fine, too, as it works perfectly if I just hard code the shaders into my application program.
Thanks in advance, this is super annoying.
Edit: Here's my makefile
# Linux
CC=g++
LIBS= -lglut -lGLEW -lGL
# Compiler flags
CXXFLAGS= -g -Wall -std=c++0x
all: ../bin/Matrix
../bin/Matrix: ../src/main.cpp
$(CC) $(CXXFLAGS) ../src/main.cpp -o ../bin/Matrix $(LIBS)