Reputation: 1308
I'm trying to link a glsl program with 2 shaders that have previously compiled succesfully, but the program won't link. According to glRemedy's debugger, the error message is ERROR: Definition for "void main()" not found
. After some debugging, i found
out that the GPU is receiving NO shaders, again according to glRemedy. My code looks right
and performs as expected from client side, i believe.
Vertex shader:
layout(location = 0) in vec3 vertexPosicao;
void main() {
gl_Position.xyz = vertexPosicao;
gl_Position.w = 1.0;
}
Fragment shader:
out vec3 cor;
void main() {
cor = vec3(1, 0, 0);
}
Loading code:
bool Shader::fromCode(std::string strCode) {
GLint result;
GLchar *code = new GLchar[strCode.size() + 1];
strcpy(code, strCode.c_str());
glShaderSource(m_id, 1, const_cast<const GLchar **>(&code), NULL);
glCompileShader(m_id);
glGetShaderiv(m_id, GL_COMPILE_STATUS, &result);
return (bool)result;
}
EDIT:
After using glShaderSource
on the shader ID i used, i got the source back. All of it. But it seems it's missing \n's. Would that be a problem?
EDIT 2:
Infolog says everything's ok. From the C++ code, the Program's Infolog says it's ok too, but from glRemedy, there's that error above. Also, i can't see the source of the shaders from glRemedy and their size is 0kb. And no, the test i have set up shows something's not working.
EDIT 3:
Merry Christmas! =D
Upvotes: 1
Views: 870
Reputation: 162319
Why so complicated, that copy to a newly allocated GLchar* I mean (which you forget to delete[] afterwards). I'd rewrite it as
bool Shader::fromCode(std::string strCode) {
GLint result;
GLuint source_length = strCode.length();
GLchar const * strCodePtr = strCode.c_str();
glShaderSource(m_id, 1, &strCodePtr, &source_length);
glCompileShader(m_id);
glGetShaderiv(m_id, GL_COMPILE_STATUS, &result);
return (bool)result;
}
the additional source_length parameter takes care of any trailing garbage that might be found in the memory afterwards (number 1 reason, most people's shader loaders don't work).
Upvotes: 1