I'm working on getting shaders working for the first time, and run into a problem. Using the following two shaders, my rectangle renders a purplish color.
// if both shaders were loaded, return the ShaderProgram
if(vertexSource && fragmentSource) {
// Compile the shader program
GLuint program = glCreateProgram();
glLinkProgram(program);
ShaderProgram* result = new ShaderProgram(program);
// Release the buffers allocated in loadShaderSource
delete[] vertexSource;
delete[] fragmentSource;
// Return the ShaderProgram
return result;
}
}
// If the shader is incomplete (missing one of the two shader programs)
// make sure we don't leave allocated buffer behind
if(vertexSource)
delete[] vertexSource;
Alright, so I added error checking for the shaders and I get this output:
rtex shader was successfully compiled to run on hardware.
ðº
ðº
ðFragment shader failed to compile with the following errors:
ERROR: 0:1: error(#132) Syntax error: '<' parse error
ERROR: error(#273) 1 compilation errors. No code generated
º
𺫫««hader(s) were not successfully compiled before glLinkProgram() was called. Link failed.
ðº
ðº
ð
So for whatever reason, my file reading code is adding a bunch of random crap to the shader and is causing it to fail. I have no idea why it's doing this.
std::ifstream file;
std::stringstream buffer;
// First load the vertex shader
file.open(filename.c_str());
// Read into buffer
buffer << file.rdbuf();
file.close();
return buffer.str();
When I view "buffer" in the debugger, I see my shader code with a bunch of random crap appended to the end.
EDIT: Okay, I figured it out. It was a problem converting std::string to const char * for opengl that was causing problems.
Alrighty, I added shader logging and got this output:
Vertex: Vertex shader was successfully compiled to run on hardware.
Fragment: Fragment shader failed to compile with the following errors:
ERROR: 0:1: error(#132) Syntax error: '<' parse error
ERROR: error(#273) 1 compilation errors. No code generated
Fragment shader(s) were not successfully compiled before glLinkProgram() was called. Link failed.
So for whatever reason, my file reading code is adding random crap to the end of the files which is causing it to fail.
std::ifstream file;
std::stringstream buffer;
// First load the vertex shader
file.open(filename.c_str());
EDIT: Okay, I figured it out. It was a problem converting std::string to const char * for opengl that was causing problems.
Alrighty, I added shader logging and got this output:
Vertex: Vertex shader was successfully compiled to run on hardware.
Fragment: Fragment shader failed to compile with the following errors:
ERROR: 0:1: error(#132) Syntax error: '<' parse error
ERROR: error(#273) 1 compilation errors. No code generated
Fragment shader(s) were not successfully compiled before glLinkProgram() was called. Link failed.
So for whatever reason, my file reading code is adding random crap to the end of the files which is causing it to fail.
std::ifstream file;
std::stringstream buffer;
// First load the vertex shader
file.open(filename.c_str());
// Read into buffer
buffer << file.rdbuf();
file.close();
return buffer.str();
always output the feedback from the APIs. It's there to help you solve your problems.