void Program::link() { glLinkProgram(program); GL_CHECK_ERROR(); if (programLinkStatus(program) == false) throw error("error linking program: " + programInfoLog(program)); }
bool Shader::load(const std::string name, const char* vertexFilename, const char* fragmentFilename) { m_name = name; GLint success = 0; //here we create a vertex shader and set the shader source m_vertexShader = loadShader(vertexFilename, GL_VERTEX_SHADER); //next compile the vertex shader glCompileShader(m_vertexShader); //check if it compiled ok. glGetShaderiv(m_vertexShader, GL_COMPILE_STATUS, &success); if(!success) { std::cout << std::endl << "Error compiling GLSL vertex shader: '" << vertexFilename << "'" << std::endl << std::endl; std::cout << "Shader info log:" << std::endl << shaderInfoLog(m_vertexShader) << std::endl; return false; } else { //create a fragment shader and set the shader source m_fragmentShader = loadShader(fragmentFilename, GL_FRAGMENT_SHADER); //compile the fragment shader glCompileShader(m_fragmentShader); //check for any compiling errors glGetShaderiv(m_fragmentShader, GL_COMPILE_STATUS, &success); if(!success) { std::cout << std::endl << "Error compiling GLSL fragment shader: '" << fragmentFilename << "'" << std::endl << std::endl; std::cout << "Shader info log:" << std::endl << shaderInfoLog(m_fragmentShader) << std::endl; return false; } else { //create the program m_programObject = glCreateProgram(); //attach the vertex and fragment shaders glAttachShader(m_programObject, m_vertexShader); glAttachShader(m_programObject, m_fragmentShader); //link it all together glLinkProgram(m_programObject); //check for any errors with the shader program glGetProgramiv(m_programObject, GL_LINK_STATUS, &success); if(!success) { std::cout << std::endl << "Error linking GLSL shaders into a shader program." << std::endl; std::cout << "GLSL vertex shader: '" << vertexFilename << "'" << std::endl; std::cout << "GLSL fragment shader: '" << fragmentFilename << "'" << std::endl << std::endl; std::cout << "Program info log:" << std::endl << programInfoLog(m_programObject) << std::endl; return false; } } } std::cout << "Loaded GLSL program: '" << m_name << "'" << std::endl; return true; }