Beispiel #1
0
 void Program::link()
 {
   glLinkProgram(program);
   GL_CHECK_ERROR();
   if (programLinkStatus(program) == false)
     throw error("error linking program: " + programInfoLog(program));
 }
Beispiel #2
0
/**
 * Create a GLSL program object from vertex and fragment shader files.
 *
 * @param  vShaderFile   The vertex shader filename
 * @param  fShaderFile   The fragment shader filename
 * @return handle to the GLSL program
 */
GLuint createGLSLProgram(const char* vertexSource, const char* fragmentSource)
{
	GLuint vertexShader;
	GLuint fragmentShader;
	char* log;
   _program = glCreateProgram();
   
   // Create vertex shader
   vertexShader  = createShader(vertexSource, GL_VERTEX_SHADER);

   // Check for compile errors
   if(!shaderCompileStatus(vertexShader))
   {
      log = getShaderLog(vertexShader);
      fprintf(stderr, "Could not compile vertex shader:\n%s\n", log);
      free(log);
      terminate(EXIT_FAILURE);
   }

   // Create fragment shader
   fragmentShader = createShader(fragmentSource, GL_FRAGMENT_SHADER);
   
   // Check for compile errors
   if(!shaderCompileStatus(fragmentShader))
   {
      log = getShaderLog(fragmentShader);
      fprintf(stderr, "Could not compile fragment shader:\n%s\n", log);
      free(log);
      terminate(EXIT_FAILURE);
   }

   // Attach the shaders to the program
   glAttachShader(_program, vertexShader);
   glAttachShader(_program, fragmentShader);
   
   // Link the program
   glLinkProgram(_program);
   
   // Check for linker errors
   if(!programLinkStatus(_program))
   {
      log = getProgramLog(_program);
      fprintf(stderr, "GLSL program filed to link:\n%s\n", log);
      free(log);
      terminate(EXIT_FAILURE);
   }

   return _program;
}