Reputation: 3931
I am writing an OpenGL / C++ plugin using VBO and GLSL shaders. However, while I can compile the shaders successfully, and link them to the program, its status link check with glGetProgramiv(...,GL_LINK_STATUS,...)
returns a "No definition of main in vertex shader" error.
The vertex shader is sending a color to the fragment shader. If I remove this color-passing, the link is successfully validated.
What's wrong in my code if I want to pass color to fragment shader ?
const GLchar *vert_src =
"#version 410\n"
"layout (location = 0) in vec3 Pos;\n"
"layout (location = 1) in vec3 vColor;\n"
"uniform mat4 projectionMatrix;\n"
"uniform mat4 modelViewMatrix;\n"
"out vec3 color;\n"; // -> REMOVING THIS LINE MAKES THE VALIDATION WORK
"void main() {\n"
" color=vColor;\n" // -> AND THIS LINE TOO
" gl_Position = projectionMatrix*modelViewMatrix*vec4(Pos.x, Pos.y, Pos.z, 1.0);"
"}\n";
const GLchar *frag_src =
"#version 410\n"
"in vec3 color;\n";
"out vec4 fragColor;\n"
"void main() {\n"
" fragColor = vec4(color, 1.0);"
"}\n";
GLuint program = glCreateProgram();
GLuint v_shader = glCreateShader(GL_VERTEX_SHADER);
GLuint f_shader = glCreateShader(GL_FRAGMENT_SHADER);
int len=(GLint)strlen(vert_src);
glShaderSource(v_shader, 1, &vert_src, &len);
glCompileShader(v_shader);
glGetShaderiv(v_shader, GL_COMPILE_STATUS, &success); --> SUCCESS
len=(GLint)strlen(frag_src);
glShaderSource(f_shader, 1, &frag_src, &len);
glCompileShader(f_shader);
glGetShaderiv(f_shader, GL_COMPILE_STATUS, &success); --> SUCCESS
glAttachShader(program, v_shader); --> SUCCESS
glAttachShader(program, f_shader); --> SUCCESS
glLinkProgram(program); --> SUCCESS
glValidateProgram(program); --> SUCCESS
glGetProgramiv(program, GL_LINK_STATUS, &success); --> ERROR: Program is not successfully linked
[...] rest of code
Upvotes: 4
Views: 1735
Reputation: 72469
You have semicolons outside the strings that should not be there:
const GLchar *vert_src =
"#version 410\n"
"layout (location = 0) in vec3 Pos;\n"
"layout (location = 1) in vec3 vColor;\n"
"uniform mat4 projectionMatrix;\n"
"uniform mat4 modelViewMatrix;\n"
"out vec3 color;\n"; // <- HERE YOU HAVE A SEMICOLON
"void main() {\n"
" color=vColor;\n"
" gl_Position = projectionMatrix*modelViewMatrix*vec4(Pos.x, Pos.y, Pos.z, 1.0);"
"}\n";
const GLchar *frag_src =
"#version 410\n"
"in vec3 color;\n"; // <- HERE YOU HAVE ANOTHER SEMICOLON
"out vec4 fragColor;\n"
"void main() {\n"
" fragColor = vec4(color, 1.0);"
"}\n";
Upvotes: 5