Results 1 to 3 of 3

Thread: shader programme does not link

  1. #1
    Newbie Newbie
    Join Date
    Apr 2015
    Posts
    2

    Exclamation shader programme does not link

    Hello to everyone!

    When calling create_programme_from_files the vertex and fragment shaders compile, but the Programme does not link. gl_log writes to a text file for documentation. From the log file I get the following output:

    creating shader from test.vert...
    shader compiled. index 1
    creating shader from test.frag...
    shader compiled. index 2
    created programme 3. attaching shaders 1 and 2...
    ERROR: could not link shader programme GL index 3
    programme info log for GL index 3:
    ERROR: Definition for "void main()" not found.

    Here are the functions for creating the shaders and the programme:
    Code :
    void parse_file_into_str(const char* file_name, std::string shader_str)
    {
    	std::ifstream file(file_name);
    	while (file.good())
    	{
    		std::string line;
    		std::getline(file, line);
    		shader_str.append(line + "\n");
    	}
    	file.close();
    }
     
     
    bool create_shader(const char* file_name, GLuint* shader, GLenum type)
    {
    	gl_log("creating shader from %s...\n", file_name);
    	std::string shader_string;
    	parse_file_into_str(file_name, shader_string);
    	const GLchar* shader_str = shader_string.c_str();
    	*shader = glCreateShader(type);
    	glShaderSource(*shader, 1, &shader_str, NULL);
    	glCompileShader(*shader);
    	//check for compile errors
    	int params = -1;
    	glGetShaderiv(*shader, GL_COMPILE_STATUS, &params);
    	if (GL_TRUE != params)
    	{
    		gl_log_err("ERROR: GL shader index %i did not compile\n", *shader);
    		_print_shader_info_log(*shader);
    		return false;
    	}
    	gl_log("shader compiled. index %i\n", *shader);
    	return true;
    }
     
     
    bool create_programme(GLuint vert, GLuint frag, GLuint* programme)
    	{
    	*programme = glCreateProgram();
    	gl_log("created programme %u. attaching shaders %u and %u...\n", *programme, vert, frag);
    	glAttachShader(*programme, frag);
    	glAttachShader(*programme, vert);
     
    	glLinkProgram(*programme);
    	//check if link was successful
    	GLint params = -1;
    	glGetProgramiv(*programme, GL_LINK_STATUS, &params);
    	if (GL_TRUE != params)
    	{
    		gl_log_err("ERROR: could not link shader programme GL index %u\n", *programme);
    		_print_programme_info_log(*programme);
    		return false;
    	}
     
    	assert(is_valid(*programme));
     
    	glDeleteShader(vert);
    	glDeleteShader(frag);
    	return true;
    }
     
    GLuint create_programme_from_files(const char* vert_file_name, const char* frag_file_name)
    {
    	GLuint vert, frag, programme;
    	assert(create_shader(vert_file_name, &vert, GL_VERTEX_SHADER));
    	assert(create_shader(frag_file_name, &frag, GL_FRAGMENT_SHADER));
    	assert(create_programme(vert, frag, &programme));
    	return programme;
    }

    Hopefully you can help me and thank you in advance.

  2. #2
    Senior Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    281
    Your shader sources are probably empty because of this:
    Code :
    void parse_file_into_str(const char* file_name, std::string shader_str)
    {
        std::ifstream file(file_name);
        while (file.good())
        {
            std::string line;
            std::getline(file, line);
            shader_str.append(line + "\n");
        }
        file.close();
    }
    shader_str is neither a pointer nor a reference. When you call this function, a copy is passed into the
    function, the copy is modified localy and discarded when the function returns. So when you call this
    function on an std::string, it is not modified and you are passing an empty string into glShaderSource.

  3. #3
    Newbie Newbie
    Join Date
    Apr 2015
    Posts
    2
    Thanks a lot. This solved the problem.

Similar Threads

  1. link to working c++ code with shader texturing?
    By crankygoo in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-03-2010, 09:50 PM
  2. Replies: 6
    Last Post: 05-11-2005, 12:20 AM
  3. Chroma keying through Pixel shader programme
    By mayursb in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-06-2005, 06:47 AM
  4. The most Simple shader, can't get it to link.
    By coderdave in forum OpenGL: GLSL
    Replies: 1
    Last Post: 02-23-2005, 08:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean