Пример #1
0
bool Shader::rebuild()
{
	errors = "";
	std::string VertexShaderCode;
	std::string FragmentShaderCode;

	// Create the shaders
	GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
	GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

	// Read the Vertex Shader code from the file
	VertexShaderCode = "";
	std::ifstream VertexShaderStream(vertFile.c_str(), std::ios::in);
	if (VertexShaderStream.is_open())
	{
		std::string Line = "";
		while (getline(VertexShaderStream, Line))
			VertexShaderCode += "\n" + Line;
		VertexShaderStream.close();
	}
	else
	{
		errors = "Shader rebuild failed! Couldn't open file " + vertFile;
		prn("Shader rebuild failed! Couldn't open file %s", vertFile.c_str());
		return false;
	}

	// Read the Fragment Shader code from the file
	fragBuff = FragmentShaderCode = "";
	std::ifstream FragmentShaderStream(fragFile.c_str(), std::ios::in);
	if (FragmentShaderStream.is_open()){
		std::string Line = "";
		while (getline(FragmentShaderStream, Line))
			FragmentShaderCode += "\n" + Line;
		FragmentShaderStream.close();
	}
	else
	{
		errors = "Shader rebuild failed! Couldn't open file " + fragFile;
		prn("Shader rebuild failed! Couldn't open file %s", fragFile.c_str());
		return false;
	}

	GLint result = GL_FALSE;
	int InfoLogLength;

	// Compile Vertex Shader
	prn("Compiling shader : %s\n", vertFile.c_str());
	char const * VertexSourcePointer = VertexShaderCode.c_str();
	glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL);
	glCompileShader(VertexShaderID);

	// Check Vertex Shader
	glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &result);
	if (!result) {
		glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
		std::vector<char> VertexShaderErrorMessage(InfoLogLength);
		glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
		prn("%s\n", &VertexShaderErrorMessage[0]);
		errors = "Shader rebuild failed!\n" + std::string(&VertexShaderErrorMessage[0]);
		return false;
	}


	// Compile Fragment Shader
	prn("Compiling shader : %s\n", fragFile.c_str());
	char const * FragmentSourcePointer = FragmentShaderCode.c_str();
	glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL);
	glCompileShader(FragmentShaderID);

	// Check Fragment Shader
	glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &result);
	if (!result) {
		glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
		std::vector<char> FragmentShaderErrorMessage(InfoLogLength);
		glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
		prn("%s\n", &FragmentShaderErrorMessage[0]);
		errors = "Shader rebuild failed!\n" + std::string(&FragmentShaderErrorMessage[0]);
		return false;
	}

	// Link the program
	prn("Linking program\n");
	GLuint ProgramID = glCreateProgram();
	glAttachShader(ProgramID, VertexShaderID);
	glAttachShader(ProgramID, FragmentShaderID);
	glLinkProgram(ProgramID);

	// Check the program
	glGetProgramiv(ProgramID, GL_LINK_STATUS, &result);
	if (!result) {
		glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
		std::vector<char> ProgramErrorMessage(std::max(InfoLogLength, int(1)));
		glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
		prn("%s\n", &ProgramErrorMessage[0]);
		errors = "Shader rebuild failed!\n" + std::string(&ProgramErrorMessage[0]);
		return false;
	}

	release();

	vertBuff = VertexShaderCode;
	fragBuff = FragmentShaderCode;

	vertexShader = VertexShaderID;
	fragmentShader = FragmentShaderID;
	shaderProgram = ProgramID;
	return vertexShader && fragmentShader && shaderProgram;
}
Пример #2
0
GLuint ShaderLoader::LoadShaders(string vertex_file, string fragment_file)
{
	// Create the shader IDs
	GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
	GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

	// Read the Vertex Shader code from the file
	std::string VertexShaderCode;

	std::ifstream VertexShaderStream(vertex_file, std::ios::in);
	if(VertexShaderStream.is_open())
	{
		//Read the vertex shader line by line, and add the \n line ending
		std::string Line = "";
		while(getline(VertexShaderStream, Line))
			VertexShaderCode += "\n" + Line;
		VertexShaderStream.close();
	}
	else
	{
		printf("Can't open Vertex Shader code file: %s !\n", vertex_file);
		assert(false);
	}


	// Read the Fragment Shader code from the file
	std::string FragmentShaderCode;

	std::ifstream FragmentShaderStream(fragment_file, std::ios::in);
	if(FragmentShaderStream.is_open())
	{
		//Read the fragment shader line by line, and add the \n line ending
		std::string Line = "";
		while(getline(FragmentShaderStream, Line))
			FragmentShaderCode += "\n" + Line;
		FragmentShaderStream.close();
	}
	else
	{
		printf("Can't open Fragment Shader code file: %s !\n", fragment_file);
		assert(false);
	}

	//Now we compile them
	GLint Result = GL_FALSE;
	int InfoLogLength = 0;

//Compile Vertex Shader
	printf("Compiling Vertex Shader : %s\n", vertex_file);

	//get the shader text as a pointer
	char const * VertexSourcePointer = VertexShaderCode.c_str();
	//and pass it to OpenGL
	glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
	//then compile and save in the VertexShaderID
	glCompileShader(VertexShaderID);

	//check the compiled vertex shader
	//write the compile status in Result
	glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
	//write the log length
	glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);

	//now display the shader compilation output if any
	if ( InfoLogLength > 0 )
	{
		std::vector<char> VertexShaderErrorMessage(InfoLogLength+1);
		glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
		printf("Vertex Shader compilation output:\n");
		printf("%s\n", &VertexShaderErrorMessage[0]);
	}

//Compile Fragment Shader
	printf("Compiling Fragment Shader : %s\n", fragment_file);
	
	//get the shader text as a pointer
	char const * FragmentSourcePointer = FragmentShaderCode.c_str();
	//and pass it to OpenGL
	glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
	//then compile and save in the FragmentShaderID
	glCompileShader(FragmentShaderID);

	//check the compiled vertex shader
	//write the compile status in Result
	glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
	//write the log length
	glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);

	//now display the shader compilation output if any
	if ( InfoLogLength > 0 )
	{
		std::vector<char> FragmentShaderErrorMessage(InfoLogLength+1);
		glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
		printf("Fragment Shader compilation output:\n");
		printf("%s\n", &FragmentShaderErrorMessage[0]);
	}

	//Both shaders are compiled, now link the program
	printf("Linking program\n");

	GLuint ProgramID = glCreateProgram();

	//attach the compiled Vertex and Fragment shaders to the ProgramID
	glAttachShader(ProgramID, VertexShaderID);
	glAttachShader(ProgramID, FragmentShaderID);
	glLinkProgram(ProgramID);

	//now check the program
	glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
	glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);

	if ( InfoLogLength > 0 )
	{
		std::vector<char> ProgramErrorMessage(InfoLogLength+1);
		glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
		printf("Program Linking output:\n");
		printf("%s\n", &ProgramErrorMessage[0]);
	}

	//we are done with the shaders, it is safe to delete them
	glDeleteShader(VertexShaderID);
	glDeleteShader(FragmentShaderID);

	return ProgramID;
}
GLuint load(const char * vertex_file_path, const char * fragment_file_path){

	// Create the shaders
	GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
	GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

	// Read the Vertex Shader code from the file
	std::string VertexShaderCode;
	std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
	if (VertexShaderStream.is_open())
	{
		std::string Line = "";
		while (getline(VertexShaderStream, Line))
			VertexShaderCode += "\n" + Line;
		VertexShaderStream.close();
	}

	// Read the Fragment Shader code from the file
	std::string FragmentShaderCode;
	std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
	if (FragmentShaderStream.is_open()){
		std::string Line = "";
		while (getline(FragmentShaderStream, Line))
			FragmentShaderCode += "\n" + Line;
		FragmentShaderStream.close();
	}

	GLint Result = GL_FALSE;
	int InfoLogLength;

	// Compile Vertex Shader
	printf("Compiling shader : %s\n", vertex_file_path);
	char const * VertexSourcePointer = VertexShaderCode.c_str();
	glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL);
	glCompileShader(VertexShaderID);

	// Check Vertex Shader
	glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
	glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	std::vector<char> VertexShaderErrorMessage(InfoLogLength);
	glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
	fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]);

	// Compile Fragment Shader
	printf("Compiling shader : %s\n", fragment_file_path);
	char const * FragmentSourcePointer = FragmentShaderCode.c_str();
	glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL);
	glCompileShader(FragmentShaderID);

	// Check Fragment Shader
	glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
	glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	std::vector<char> FragmentShaderErrorMessage(InfoLogLength);
	glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
	fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]);

	// Link the program
	fprintf(stdout, "Linking program\n");
	GLuint ProgramID = glCreateProgram();
	glAttachShader(ProgramID, VertexShaderID);
	glAttachShader(ProgramID, FragmentShaderID);
	glLinkProgram(ProgramID);

	// Check the program
	glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
	glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	std::vector<char> ProgramErrorMessage(max(InfoLogLength, int(1)));
	glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
	fprintf(stdout, "%s\n", &ProgramErrorMessage[0]);

	glDeleteShader(VertexShaderID);
	glDeleteShader(FragmentShaderID);

	return ProgramID;
}
Пример #4
0
GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path){

	// Create the shaders
	GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
	GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

	// Read the Vertex Shader code from the file
	std::string VertexShaderCode;
	std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
	if(VertexShaderStream.is_open()){
		std::string Line = "";
		while(getline(VertexShaderStream, Line))
			VertexShaderCode += "\n" + Line;
		VertexShaderStream.close();
	}else{
		std::cout << "Failed to open " << vertex_file_path << ". Are you in the right directory?" << std::endl;
		return 0;
	}

	// Read the Fragment Shader code from the file
	std::string FragmentShaderCode;
	std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
	if(FragmentShaderStream.is_open()){
		std::string Line = "";
		while(getline(FragmentShaderStream, Line))
			FragmentShaderCode += "\n" + Line;
		FragmentShaderStream.close();
	}

	GLint Result = GL_FALSE;
	int InfoLogLength;

	// Compile Vertex Shader
	// std::cout << "Compiling shader " << vertex_file_path <<  std::endl;
	char const * VertexSourcePointer = VertexShaderCode.c_str();
	glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
	glCompileShader(VertexShaderID);

	// Check Vertex Shader
	glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
	glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	if ( InfoLogLength > 1 ){
		std::vector<char> VertexShaderErrorMessage(InfoLogLength+1);
		glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
		std::cout << &VertexShaderErrorMessage[0] << std::endl;
	}



	// Compile Fragment Shader
	// std::cout << "Compiling shader " << fragment_file_path <<  std::endl;
	char const * FragmentSourcePointer = FragmentShaderCode.c_str();
	glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
	glCompileShader(FragmentShaderID);

	// Check Fragment Shader
	glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
	glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	if ( InfoLogLength > 1 ){
		std::vector<char> FragmentShaderErrorMessage(InfoLogLength+1);
		glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
		std::cout << &FragmentShaderErrorMessage[0] << std::endl;
	}



	// Link the program
	// std::cout << "Linking program" << std::endl;
	GLuint ProgramID = glCreateProgram();
	if(ProgramID == 0){
		std::cout << "glCreateProgram() failed! (?\?\?)" << std::endl;
	}
	glAttachShader(ProgramID, VertexShaderID);
	glAttachShader(ProgramID, FragmentShaderID);
	glLinkProgram(ProgramID);

	// Check the program
	glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
	glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	if ( InfoLogLength > 1 ){
		std::vector<char> ProgramErrorMessage(InfoLogLength+1);
		glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
		std::cout << &ProgramErrorMessage[0] << std::endl;
	}

	glDeleteShader(VertexShaderID);
	glDeleteShader(FragmentShaderID);

	return ProgramID;
}
Пример #5
0
GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path){

	GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
	GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

	std::string VertexShaderCode;
	std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
	if(VertexShaderStream.is_open()){
		std::string Line = "";
		while(getline(VertexShaderStream, Line))
			VertexShaderCode += "\n" + Line;
		VertexShaderStream.close();
	}else{
		printf("Impossible to open %s. Are you in the right directory ? Don't forget to read the FAQ !\n", vertex_file_path);
		getchar();
		return 0;
	}

	std::string FragmentShaderCode;
	std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
	if(FragmentShaderStream.is_open()){
		std::string Line = "";
		while(getline(FragmentShaderStream, Line))
			FragmentShaderCode += "\n" + Line;
		FragmentShaderStream.close();
	}



	GLint Result = GL_FALSE;
	int InfoLogLength;



	char const * VertexSourcePointer = VertexShaderCode.c_str();
	glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
	glCompileShader(VertexShaderID);

	glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
	glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	if ( InfoLogLength > 0 ){
		std::vector<char> VertexShaderErrorMessage(InfoLogLength+1);
		glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
		printf("%s\n", &VertexShaderErrorMessage[0]);
	}



	char const * FragmentSourcePointer = FragmentShaderCode.c_str();
	glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
	glCompileShader(FragmentShaderID);

	glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
	glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	if ( InfoLogLength > 0 ){
		std::vector<char> FragmentShaderErrorMessage(InfoLogLength+1);
		glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
		printf("%s\n", &FragmentShaderErrorMessage[0]);
	}



	GLuint ProgramID = glCreateProgram();
	glAttachShader(ProgramID, VertexShaderID);
	glAttachShader(ProgramID, FragmentShaderID);
	glLinkProgram(ProgramID);

	glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
	glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	if ( InfoLogLength > 0 ){
		std::vector<char> ProgramErrorMessage(InfoLogLength+1);
		glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
		printf("%s\n", &ProgramErrorMessage[0]);
	}

	glDeleteShader(VertexShaderID);
	glDeleteShader(FragmentShaderID);

	return ProgramID;
}
Пример #6
0
	int MaterialManagerClass::loadShaders(std::string shader_name) {
		int ret = 0;
		GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
		//GLuint GeometryShaderID = glCreateShader(GL_GEOMETRY_SHADER);
		GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

		std::string VertexShaderCode;
		std::ifstream VertexShaderStream(shader_name+".vxshader", std::ios::in);
		if(VertexShaderStream.is_open()) {
			std::string Line = "";
			while(getline(VertexShaderStream, Line))
				VertexShaderCode += "\n" + Line;
			VertexShaderStream.close();
		} else ret |= SW_NOVXSHADER;

		/*std::string GeometryShaderCode;
		std::ifstream GeometryShaderStream(shader_name+".gmshader", std::ios::in);
		if(GeometryShaderStream.is_open()) {
			std::string Line = "";
			while(getline(GeometryShaderStream, Line))
				GeometryShaderCode += "\n" + Line;
			GeometryShaderStream.close();
		} else ret |= SW_NOGMSHADER;*/

		std::string FragmentShaderCode;
		std::ifstream FragmentShaderStream(shader_name+".pxshader", std::ios::in);
		printf("Opening shader: %s\n", (shader_name+".pxshader").c_str());
		if(FragmentShaderStream.is_open()) {
			std::string Line = "";
			while(getline(FragmentShaderStream, Line))
				FragmentShaderCode += "\n" + Line;
			FragmentShaderStream.close();
		} else ret |= SW_NOPXSHADER;

		GLint Result = GL_FALSE;
		int InfoLogLength;

		printf("Compiling shader: %s\n", (shader_name+".vxshader").c_str());
		const char * VertexSourcePointer = VertexShaderCode.c_str();
		glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL);
		glCompileShader(VertexShaderID);

		glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
		glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
		std::vector<char> VertexShaderErrorMessage(InfoLogLength);
		glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
		fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]);

		/*printf("Compiling shader: %s\n", (shader_name+".gmshader").c_str());
		const char * GeometrySourcePointer = GeometryShaderCode.c_str();
		glShaderSource(GeometryShaderID, 1, &GeometrySourcePointer, NULL);
		glCompileShader(GeometryShaderID);

		glGetShaderiv(GeometryShaderID, GL_COMPILE_STATUS, &Result);
		glGetShaderiv(GeometryShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
		std::vector<char> GeometryShaderErrorMessage(InfoLogLength);
		glGetShaderInfoLog(GeometryShaderID, InfoLogLength, NULL, &GeometryShaderErrorMessage[0]);
		fprintf(stdout, "%s\n", &GeometryShaderErrorMessage[0]);*/

		printf("Compiling shader: %s\n", (shader_name+".pxshader").c_str());
		const char * FragmentSourcePointer = FragmentShaderCode.c_str();
		glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL);
		glCompileShader(FragmentShaderID);

		glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
		glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
		std::vector<char> FragmentShaderErrorMessage(InfoLogLength);
		glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
		fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]);

		fprintf(stdout, "Linking program\n");
		GLuint ProgramID = glCreateProgram();
		glAttachShader(ProgramID, VertexShaderID);
		//glAttachShader(ProgramID, GeometryShaderID);
		glAttachShader(ProgramID, FragmentShaderID);
		glLinkProgram(ProgramID);

		glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
		glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
		std::vector<char> ProgramErrorMessage( max(InfoLogLength, int(1)));
		glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
		fprintf(stdout, "%s\n", &ProgramErrorMessage[0]);

		glDeleteShader(VertexShaderID);
		//glDeleteShader(GeometryShaderID);
		glDeleteShader(FragmentShaderID);

		fprintf(stdout, "shader ID: %d\n", ProgramID);
		programs.insert(std::pair<std::string, GLuint>(shader_name, ProgramID));

		return ret;
	}
Пример #7
0
GLuint LoadShaders(const std::string &vertex_file_path,const std::string &fragment_file_path){

  //std::cout << "load shaders" << std::endl;

  // Create the shaders
  GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
  GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
  
  // Read the Vertex Shader code from the file
  std::string VertexShaderCode;
  std::ifstream VertexShaderStream(vertex_file_path.c_str(), std::ios::in);
  if (VertexShaderStream.is_open()){
    std::string Line = "";
    while(getline(VertexShaderStream, Line))
      VertexShaderCode += "\n" + Line;
    VertexShaderStream.close();
  } else {
    std::cerr << "ERROR: cannot open " << vertex_file_path << std::endl;
    exit(0);
  }
  // Read the Fragment Shader code from the file
  std::string FragmentShaderCode;
  std::ifstream FragmentShaderStream(fragment_file_path.c_str(), std::ios::in);
  if(FragmentShaderStream.is_open()){
    std::string Line = "";
    while(getline(FragmentShaderStream, Line))
      FragmentShaderCode += "\n" + Line;
    FragmentShaderStream.close();
  } else {
    std::cerr << "ERROR: cannot open " << vertex_file_path << std::endl;
    exit(0);
  }
  
  GLint Result = GL_FALSE;
  int InfoLogLength;
  
  // Compile Vertex Shader
  //std::cout << "Compiling shader : " << vertex_file_path << std::endl;
  char const * VertexSourcePointer = VertexShaderCode.c_str();
  glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
  glCompileShader(VertexShaderID);
  // Check Vertex Shader
  glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
  glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
  if ( InfoLogLength > 0 ){
    std::vector<char> VertexShaderErrorMessage(InfoLogLength+1);
    glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
    std::cerr << "VERTEX SHADER ERROR: " << std::string(VertexShaderErrorMessage.begin(),
                                                        VertexShaderErrorMessage.end()) << std::endl;
  }
  
  // Compile Fragment Shader
  //std::cout << "Compiling shader : " << fragment_file_path << std::endl;
  char const * FragmentSourcePointer = FragmentShaderCode.c_str();
  glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
  glCompileShader(FragmentShaderID);
  // Check Fragment Shader
  glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
  glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
  if ( InfoLogLength > 0 ){
    std::vector<char> FragmentShaderErrorMessage(InfoLogLength+1);
    glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
    std::cerr << "FRAGMENT SHADER ERROR: " << std::string(FragmentShaderErrorMessage.begin(),
                                                          FragmentShaderErrorMessage.end()) << std::endl;
  }
  
  // Link the program
  //std::cout << "Linking program" << std::endl;
  GLuint ProgramID = glCreateProgram();
  glAttachShader(ProgramID, VertexShaderID);
  glAttachShader(ProgramID, FragmentShaderID);
  glLinkProgram(ProgramID);
  // Check the program
  glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
  glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
  if ( InfoLogLength > 0 ){
    std::vector<char> ProgramErrorMessage(InfoLogLength+1);
    glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
    std::cerr << "SHADER PROGRAM ERROR: " << std::string(ProgramErrorMessage.begin(),
                                                         ProgramErrorMessage.end()) << std::endl;
  }
  
  glDeleteShader(VertexShaderID);
  glDeleteShader(FragmentShaderID);
  
  return ProgramID;
}
Пример #8
0
GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path){

	// Создаем шейдеры
	GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
	GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

	// Загружаем код Вершинного Шейдера из файла
	std::string VertexShaderCode;
	std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
	if(VertexShaderStream.is_open())
	{
		std::string Line = "";
		while(getline(VertexShaderStream, Line))
			VertexShaderCode += "\n" + Line;
		VertexShaderStream.close();
	}

	// Загружаем код Фрагментного шейдера из файла
	std::string FragmentShaderCode;
	std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
	if(FragmentShaderStream.is_open()){
		std::string Line = "";
		while(getline(FragmentShaderStream, Line))
			FragmentShaderCode += "\n" + Line;
		FragmentShaderStream.close();
	}

	GLint Result = GL_FALSE;
	int InfoLogLength;

	// Компилируем Вершинный шейдер
	printf("Compile Vertex shader: %s\n", vertex_file_path);
	char const * VertexSourcePointer = VertexShaderCode.c_str();
	glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
	glCompileShader(VertexShaderID);

	// Выполняем проверку Вершинного шейдера
	glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
	glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	std::vector<char> VertexShaderErrorMessage(InfoLogLength);
	glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
	fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]);

	// Компилируем Фрагментный шейдер
	printf("Compile Fragment Shader: %s\n", fragment_file_path);
	char const * FragmentSourcePointer = FragmentShaderCode.c_str();
	glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
	glCompileShader(FragmentShaderID);

	// Проверяем Фрагментный шейдер
	glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
	glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	std::vector<char> FragmentShaderErrorMessage(InfoLogLength);
	glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
	fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]);

	// Создаем шейдерную программу и привязываем шейдеры к ней
	fprintf(stdout, "Create shader program \n");
	GLuint ProgramID = glCreateProgram();
	glAttachShader(ProgramID, VertexShaderID);
	glAttachShader(ProgramID, FragmentShaderID);
	glLinkProgram(ProgramID);

	// Проверяем шейдерную программу
	glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
	glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	std::vector<char> ProgramErrorMessage(max(InfoLogLength, int(1)) );
	glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
	fprintf(stdout, "%s\n", &ProgramErrorMessage[0]);

	glDeleteShader(VertexShaderID);
	glDeleteShader(FragmentShaderID);

	return ProgramID;
}
Пример #9
0
/* 载入着色器(shader)文件并编译;创建着色器程序并链接 */
void CShaderProgram::loadShaders(const char* vertexFilePath,const char* fragmentFilePath)
{
	// 创建着色器
	GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
	GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

	// 读取顶点(Vertex)着色器文件
	string VertexShaderCode;
	ifstream VertexShaderStream(vertexFilePath, ios::in);
	if (VertexShaderStream.is_open()) {
		string Line = "";
		while (getline(VertexShaderStream, Line))
			VertexShaderCode += "\n" + Line;
		VertexShaderStream.close();
	} else {
		fprintf(stderr, "Can not open vertex shader file: %s \n", vertexFilePath);
		exit(1);
	}

	// 读取片段(Fragment)着色器文件
	string FragmentShaderCode;
	ifstream FragmentShaderStream(fragmentFilePath, ios::in);
	if (FragmentShaderStream.is_open()) {
		string Line = "";
		while (getline(FragmentShaderStream, Line))
			FragmentShaderCode += "\n" + Line;
		FragmentShaderStream.close();
	} else {
		fprintf(stderr, "Can not open fragment shader file: %s \n", fragmentFilePath);
		exit(1);
	}

	// 编译顶点着色器
	printf("Compiling Vertex Shader: %s\n", vertexFilePath);
	char const * VertexSourcePointer = VertexShaderCode.c_str();
	glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
	glCompileShader(VertexShaderID);

	// 检查顶点着色器编译情况
	glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &iStatus);
	if (!iStatus) {
		glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
		vector<char> VertexShaderErrorMessage(InfoLogLength+1);
		glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
		fprintf(stderr, "Vertex Shader compiling error: %s\n", &VertexShaderErrorMessage[0]);
		exit(1);
	}

	// 编译片段着色器
	printf("Compiling Fragment Shader: %s\n", fragmentFilePath);
	char const * FragmentSourcePointer = FragmentShaderCode.c_str();
	glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
	glCompileShader(FragmentShaderID);

	// 检查片段着色器编译情况
	glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &iStatus);
	if (!iStatus){
		glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
		vector<char> FragmentShaderErrorMessage(InfoLogLength+1);
		glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
		fprintf(stderr, "Fragment Shader compiling error: %s\n", &FragmentShaderErrorMessage[0]);
		exit(1);
	}

	// 创建并链接着色器程序
	printf("Linking shader program\n");
	m_uiProgramID = glCreateProgram();
	glAttachShader(m_uiProgramID, VertexShaderID);
	glAttachShader(m_uiProgramID, FragmentShaderID);
	glLinkProgram(m_uiProgramID);

	// 检查着色器程序链接状况
	glGetProgramiv(m_uiProgramID, GL_LINK_STATUS, &iStatus);
	if (!iStatus){
		glGetProgramiv(m_uiProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
		vector<char> ProgramErrorMessage(InfoLogLength+1);
		glGetProgramInfoLog(m_uiProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
		fprintf(stderr, "shader program linking error: %s\n", &ProgramErrorMessage[0]);
	}

	glDeleteShader(VertexShaderID);
	glDeleteShader(FragmentShaderID);
}
Пример #10
0
GLuint LoadShaders(const char * vertex_file_path, const char * fragment_file_path)
{
	// Create the shaders
	GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
	GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

	// Read the Vertex Shader code from the file
	std::string VertexShaderCode;
	std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
	if(VertexShaderStream.is_open() == true)
	{
		std::string Line = "";
		while(getline(VertexShaderStream, Line))
			VertexShaderCode += "\n" + Line;
		VertexShaderStream.close();
	}
	else
	{
		CA_ERROR("GLShader::LoadShaders() : Can't open %s.\n", vertex_file_path);
		return 0;
	}

	// Read the Fragment Shader code from the file
	std::string FragmentShaderCode;
	std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);

	if(FragmentShaderStream.is_open() == true)
	{
		std::string Line = "";
		while(getline(FragmentShaderStream, Line))
			FragmentShaderCode += "\n" + Line;
		FragmentShaderStream.close();
	}
	else
	{
		CA_ERROR("Impossible to open %s.\n", fragment_file_path);
		return 0;
	}

	GLint Result = GL_FALSE;
	int InfoLGLength;

	// Compile Vertex Shader
	CA_TRACE("Compiling shader : %d (%s)\n", VertexShaderID, vertex_file_path);
	char const * VertexSourcePointer = VertexShaderCode.c_str();
	// (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
	GLCheck(glShaderSource(VertexShaderID, 1, &VertexSourcePointer, nullptr));
	GLCheck(glCompileShader(VertexShaderID));

	// Check Vertex Shader
	GLCheck(glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result));
	GLCheck(glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLGLength));
	if (Result == GL_FALSE)
	{
		std::vector<char> VertexShaderErrorMessage(InfoLGLength+1);
		glGetShaderInfoLog(VertexShaderID, InfoLGLength, nullptr, &VertexShaderErrorMessage[0]);
		CA_ERROR("Compile vertex shader error %s\n", &VertexShaderErrorMessage[0]);
	}

	// Compile Fragment Shader
	CA_TRACE("Compiling shader : %d (%s)\n", FragmentShaderID, fragment_file_path);
	char const * FragmentSourcePointer = FragmentShaderCode.c_str();
	GLCheck(glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , nullptr));
	GLCheck(glCompileShader(FragmentShaderID));

	// Check Fragment Shader
	GLCheck(glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result));
	GLCheck(glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLGLength));
	if (Result == GL_FALSE)
	{
		std::vector<char> FragmentShaderErrorMessage(InfoLGLength+1);
		glGetShaderInfoLog(FragmentShaderID, InfoLGLength, nullptr, &FragmentShaderErrorMessage[0]);
		CA_ERROR("Compile fragment shader error %s\n", &FragmentShaderErrorMessage[0]);
	}

	// Link the program
	GLuint ProgramID = glCreateProgram();
	CA_TRACE("Linking program %d (vertex shader %d, fragment shader %d)\n", ProgramID, VertexShaderID, FragmentShaderID);		
	GLCheck(glAttachShader(ProgramID, VertexShaderID));
	GLCheck(glAttachShader(ProgramID, FragmentShaderID));
	GLCheck(glLinkProgram(ProgramID));

	// Check the program
	GLCheck(glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result));
	GLCheck(glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLGLength));
	if (Result == GL_FALSE)
	{
		if ( InfoLGLength > 1 )
		{
			std::vector<char> ProgramErrorMessage(InfoLGLength+1);
			glGetProgramInfoLog(ProgramID, InfoLGLength, nullptr, &ProgramErrorMessage[0]);
			CA_ERROR("Link program error %s\n", &ProgramErrorMessage[0]);
		}
	}

	GLCheck(glDeleteShader(VertexShaderID));
	GLCheck(glDeleteShader(FragmentShaderID));

	return ProgramID;
}
Пример #11
0
GLuint LoadShaders(const char * vertex_file_path, const char * geometry_file_path,const char * fragment_file_path)
{
		// Create the shaders
	GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
	GLuint GeometryShaderID = glCreateShader(GL_GEOMETRY_SHADER);
	GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

	// Read the Vertex Shader code from the file
	std::string VertexShaderCode;
	std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
	if(VertexShaderStream.is_open()){
		std::string Line = "";
		while(getline(VertexShaderStream, Line))
			VertexShaderCode += "\n" + Line;
		VertexShaderStream.close();
	}else{
		printf("Impossible to open %s. Are you in the right directory ?\n", vertex_file_path);
		getchar();
		return 0;


	}

	
	// Read the Geometry Shader code from the file
	std::string GeometryShaderCode;
	std::ifstream GeometryShaderStream(geometry_file_path, std::ios::in);
	if(GeometryShaderStream.is_open()){
		std::string Line = "";
		while(getline(GeometryShaderStream, Line))
			GeometryShaderCode += "\n" + Line;
		GeometryShaderStream.close();
	}

	// Read the Fragment Shader code from the file
	std::string FragmentShaderCode;
	std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
	if(FragmentShaderStream.is_open()){
		std::string Line = "";
		while(getline(FragmentShaderStream, Line))
			FragmentShaderCode += "\n" + Line;
		FragmentShaderStream.close();
	}

	GLint Result = GL_FALSE;
	int InfoLogLength;

	// Compile Vertex Shader
	printf("Compiling shader : %s\n", vertex_file_path);
	char const * VertexSourcePointer = VertexShaderCode.c_str();
	glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
	glCompileShader(VertexShaderID);

	// Check Vertex Shader
	glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
	glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	if ( InfoLogLength > 0 ){
		std::vector<char> VertexShaderErrorMessage(InfoLogLength+1);
		glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
		printf("%s\n", &VertexShaderErrorMessage[0]);
	}

	
	// Compile Geometry Shader
	printf("Compiling shader : %s\n", geometry_file_path);
	char const * GeometrySourcePointer = GeometryShaderCode.c_str();
	glShaderSource(GeometryShaderID, 1, &GeometrySourcePointer , NULL);
	glCompileShader(GeometryShaderID);

	// Check Geometry Shader
	glGetShaderiv(GeometryShaderID, GL_COMPILE_STATUS, &Result);
	glGetShaderiv(GeometryShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	if ( InfoLogLength > 0 ){
		std::vector<char> GeometryShaderErrorMessage(InfoLogLength+1);
		glGetShaderInfoLog(GeometryShaderID, InfoLogLength, NULL, &GeometryShaderErrorMessage[0]);
		printf("%s\n", &GeometryShaderErrorMessage[0]);
	}
	

	// Compile Fragment Shader
	printf("Compiling shader : %s\n", fragment_file_path);
	char const * FragmentSourcePointer = FragmentShaderCode.c_str();
	glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
	glCompileShader(FragmentShaderID);

	// Check Fragment Shader
	glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
	glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	if ( InfoLogLength > 0 ){
		std::vector<char> FragmentShaderErrorMessage(InfoLogLength+1);
		glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
		printf("%s\n", &FragmentShaderErrorMessage[0]);
	}

	// Link the program
	printf("Linking program\n");
	GLuint ProgramID = glCreateProgram();
	glAttachShader(ProgramID, VertexShaderID);
	glAttachShader(ProgramID, GeometryShaderID);
	glAttachShader(ProgramID, FragmentShaderID);
	glLinkProgram(ProgramID);

	// Check the program
	glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
	glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
	if ( InfoLogLength > 0 ){
		std::vector<char> ProgramErrorMessage(InfoLogLength+1);
		glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
		printf("%s\n", &ProgramErrorMessage[0]);
	}

	glDeleteShader(VertexShaderID);
	glDeleteShader(GeometryShaderID);
	glDeleteShader(FragmentShaderID);

	return ProgramID;
}
Пример #12
0
int ShaderLoader::load(const char * vertex_file_path, const char * fragment_file_path, const char * geometry_file_path)
{
	// Start of user code load
    // Crée les shaders
    GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
    GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
    
    GLuint GeometryShaderID;
    if(geometry_file_path != NULL)
        GeometryShaderID = glCreateShader(GL_GEOMETRY_SHADER_EXT);
    
    // Lit le code du vertex shader à partir du fichier
    std::string VertexShaderCode;
    std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
    if(VertexShaderStream.is_open())
    {
        std::string Line = "";
        while(getline(VertexShaderStream, Line))
            VertexShaderCode += "\n" + Line;
        VertexShaderStream.close();
    }
    
    // Lit le code du fragment shader à partir du fichier
    std::string FragmentShaderCode;
    std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
    if(FragmentShaderStream.is_open()){
        std::string Line = "";
        while(getline(FragmentShaderStream, Line))
            FragmentShaderCode += "\n" + Line;
        FragmentShaderStream.close();
    }
    
    // Lit le code du geomtry shader à partir du fichier
    std::string GeometryShaderCode;
    if(geometry_file_path != NULL)
    {
        std::ifstream GeometryShaderStream(geometry_file_path, std::ios::in);
        if(GeometryShaderStream.is_open())
        {
            std::string Line = "";
            while(getline(GeometryShaderStream, Line))
                GeometryShaderCode += "\n" + Line;
            GeometryShaderStream.close();
        }
    }
    
    GLint Result = GL_FALSE;
    int InfoLogLength;
    
    // Compile le vertex shader
    printf("Compiling shader : %s\n", vertex_file_path);
    char const * VertexSourcePointer = VertexShaderCode.c_str();
    glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
    glCompileShader(VertexShaderID);
    
    // Vérifie le vertex shader
    glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    std::vector<char> VertexShaderErrorMessage(InfoLogLength);
    glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
    fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]);
    
    // Compile le fragment shader
    printf("Compiling shader : %s\n", fragment_file_path);
    char const * FragmentSourcePointer = FragmentShaderCode.c_str();
    glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
    glCompileShader(FragmentShaderID);
    
    // Vérifie le fragment shader
    glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    std::vector<char> FragmentShaderErrorMessage(InfoLogLength);
    glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
    fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]);
    
    if(geometry_file_path != NULL)
    {
        // Compile le geometry shader
        printf("Compiling shader : %s\n", geometry_file_path);
        char const * GeometrySourcePointer = GeometryShaderCode.c_str();
        glShaderSource(GeometryShaderID, 1, &GeometrySourcePointer , NULL);
        glCompileShader(GeometryShaderID);
        
        // Vérifie le geometry shader
        glGetShaderiv(GeometryShaderID, GL_COMPILE_STATUS, &Result);
        glGetShaderiv(GeometryShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
        std::vector<char> GeometryShaderErrorMessage(InfoLogLength);
        glGetShaderInfoLog(GeometryShaderID, InfoLogLength, NULL, &GeometryShaderErrorMessage[0]);
        fprintf(stdout, "%s\n", &GeometryShaderErrorMessage[0]);
    }
    
    // Lit le programme
    fprintf(stdout, "Linking program\n");
    GLuint ProgramID = glCreateProgram();
    glAttachShader(ProgramID, VertexShaderID);
    glAttachShader(ProgramID, FragmentShaderID);
    if(geometry_file_path != NULL)
        glAttachShader(ProgramID, GeometryShaderID);
    glLinkProgram(ProgramID);
    
    // Vérifie le programme
    glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
    glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    std::vector<char> ProgramErrorMessage( std::max(InfoLogLength, int(1)) );
    glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
    fprintf(stdout, "%s\n", &ProgramErrorMessage[0]);
    
    glDeleteShader(VertexShaderID);
    glDeleteShader(FragmentShaderID);
    if(geometry_file_path != NULL)
        glDeleteShader(GeometryShaderID);
    
    return ProgramID;
	// End of user code
}
Пример #13
0
bool Renderer::LoadShaders(std::string vertex, std::string fragment)
{
    const char* vertex_file_path = vertex.c_str();
    const char* fragment_file_path = fragment.c_str();

    // Create the shaders
    GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
    GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

    // Read the Vertex Shader code from the file
    std::string VertexShaderCode;
    std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
    if (VertexShaderStream.is_open())
    {
        std::string Line = "";
        while (getline(VertexShaderStream, Line))
            VertexShaderCode += "\n" + Line;
        VertexShaderStream.close();
    } else
    {
        fprintf(stderr, "RENDERER: Impossible to open shader file: \"%s\".\n",
                vertex_file_path);
        return false;
    }

    // Read the Fragment Shader code from the file
    std::string FragmentShaderCode;
    std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
    if (FragmentShaderStream.is_open())
    {
        std::string Line = "";
        while (getline(FragmentShaderStream, Line))
            FragmentShaderCode += "\n" + Line;
        FragmentShaderStream.close();
    } else
    {
        fprintf(stderr, "RENDERER: Impossible to open shader file: \"%s\".\n",
                vertex_file_path);
        return false;
    }


    GLint Result = GL_FALSE;
    int InfoLogLength;


    // Compile Vertex Shader
    char const * VertexSourcePointer = VertexShaderCode.c_str();
    glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL);
    glCompileShader(VertexShaderID);

    // Check Vertex Shader
    glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    
    // When empty, Info Log contains only \0 char, making the length = 1
    if (InfoLogLength > 1)
    {
        std::vector<char> VertexShaderErrorMessage(InfoLogLength + 1);
        glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL,
                           &VertexShaderErrorMessage[0]);
        if (!VertexShaderErrorMessage.empty())
            fprintf(stderr, "RENDERER: Vertex shaders compilation errors:\n%s\n",
                    &VertexShaderErrorMessage[0]);
    }


    // Compile Fragment Shader
    char const * FragmentSourcePointer = FragmentShaderCode.c_str();
    glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL);
    glCompileShader(FragmentShaderID);

    // Check Fragment Shader
    glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    
    // When empty, Info Log contains only \0 char, making the length = 1
    if (InfoLogLength > 1)
    {
        std::vector<char> FragmentShaderErrorMessage(InfoLogLength + 1);
        glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL,
                           &FragmentShaderErrorMessage[0]);
        if (!FragmentShaderErrorMessage.empty())
            fprintf(stderr, "RENDERER: Vertex shaders compilation errors:\n%s\n",
                    &FragmentShaderErrorMessage[0]);
    }



    // Link the program
    mProgram = glCreateProgram();
    glAttachShader(mProgram, VertexShaderID);
    glAttachShader(mProgram, FragmentShaderID);
    glLinkProgram(mProgram);

    // Check the program
    glGetProgramiv(mProgram, GL_LINK_STATUS, &Result);
    glGetProgramiv(mProgram, GL_INFO_LOG_LENGTH, &InfoLogLength);

    // When empty, Info Log contains only \0 char, making the length = 1
    if (InfoLogLength > 1)
    {
        std::vector<char> ProgramErrorMessage(InfoLogLength + 1);
        glGetProgramInfoLog(mProgram, InfoLogLength, NULL, &ProgramErrorMessage[0]);
        if (!ProgramErrorMessage.empty())
            fprintf(stderr, "RENDERER: Shaders linking errors:\n%s\n",
                    &ProgramErrorMessage[0]);
    }

    // Clean up
    glDetachShader(mProgram, VertexShaderID);
    glDetachShader(mProgram, FragmentShaderID);

    glDeleteShader(VertexShaderID);
    glDeleteShader(FragmentShaderID);

    return true;
}
Пример #14
0
GLuint CreateShader( string vertex, string fragment ){
   /*
      Tworzenie shadera wierzchołków i fragmentu
      Zmienne w których przypisane będą ww shadery
   */
   GLuint VertexShaderID = glCreateShader( GL_VERTEX_SHADER );
   GLuint FragmentShaderID = glCreateShader( GL_FRAGMENT_SHADER );

   /*
      Zmienne dla pobierania tekstu z plików tekstowych z shaderami
   */
   string Line;
   //vertex_shader:
   /*
      Zmienna dla całego kodu shadera wierzchołków.
   */
   string VertexShaderCode;
   /*
      Otwarcie pliku tekstowego do odczytu
   */
   ifstream VertexShaderStream( vertex.c_str() );
   /*
      Sprawdzenie czy plik został poprawnie otwarty.
   */
   if( VertexShaderStream.good() ){
      Line = "";
      /*
         Dopuki coś jest w pliku to pobierz całą linię tekstu do zmiennej Line.
      */
      while( getline( VertexShaderStream, Line ) ){
         /*
            Dodaj to do zmiennej, w której będzie cały kod shadera.
         */
         VertexShaderCode += Line + "\n";
      }
      /*
         Zamknięcie pliku.
      */
      VertexShaderStream.close();
   }
   /*
      W przeciwnym wypadku wypisz błąd otwarcia pliku.
   */
   else{
      cout<<"File problem: "<<vertex<<"\n";
      return 0;
   }
   /*
      Podobnie dla shadera fragmentu.
   */
   //Load code fragment_shader:
   string FragmentShaderCode;
   ifstream FragmentShaderStream( fragment.c_str() );
   if( FragmentShaderStream.good() ){
      Line = "";
      while( getline( FragmentShaderStream, Line ) ){
         FragmentShaderCode += Line + "\n";
      }
      FragmentShaderStream.close();
   }
   else{
      cout<<"File problem: "<<fragment<<"\n";
      return 0;
   }

   /*
      Zmienna dla sprawdzenia błędu w OpenGL.
   */
   GLint Result;
   /*
      Zmienna informaująca ile znaków potrzebnych jest do wyświetlenia pełnego komunikatu o błędzie.
   */
   GLint InfoLogLength;
   string Error;

   /*
      Zamiana ze string na const char * (aby nie było problemów z dopasowaniem typów).
   */
   const char *VertexShaderCodePointer = VertexShaderCode.c_str();
   /*
      Dodanie źródła dla kompilacji shadera wierchołków.
   */
   glShaderSource( VertexShaderID, 1, &VertexShaderCodePointer, 0 );
   /*
      Kompilowanie shadera wierchołków.
   */
   glCompileShader( VertexShaderID );
   //Check vertex_shader:
   Result = GL_FALSE;
   /*
      Sprawdzenie kodu błędu.
   */
   glGetShaderiv( VertexShaderID, GL_COMPILE_STATUS, &Result );
   /*
      Gdy jest błąd to wyświetl go.
   */
   if( Result == GL_FALSE ){
      InfoLogLength = 0;
      /*
         Pobranie do zmiennej InfoLogLength ilości znaków dla tekstu błedu.
      */
      glGetShaderiv( VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength );
      /*
         Wektor znaków dla OpenGL.
      */
      vector <GLchar> VertexShaderErrorMessage(InfoLogLength);
      /*
         Pobranie tekstu błędu do zmiennej VertexShaderErrorMessage o ilości znaków InfoLogLength.
      */
      glGetShaderInfoLog( VertexShaderID, InfoLogLength, &InfoLogLength, &VertexShaderErrorMessage[0] );
      /*
         Przekopiowanie z wektora VertexShaderErrorMessage zmiennej string Error
      */
      Error = string( VertexShaderErrorMessage.begin(), VertexShaderErrorMessage.end() );
      /*
         Wyświetlenie błedu.
      */
      cout<<"Vertex shader: "<<Error<<"\n";
      /*
         Usunięcie shadera wierzchołków z pamięci.
      */
      glDeleteShader( VertexShaderID );
      return 0;
   }

   //fragment_shader:
   /*
      Tak samo dla shadera fragmentu.
   */
   const char *FragmentShaderCodePointer = FragmentShaderCode.c_str();
   glShaderSource( FragmentShaderID, 1, &FragmentShaderCodePointer, 0 );
   glCompileShader( FragmentShaderID );
   //Check fragment_shader:
   Result = GL_FALSE;
   glGetShaderiv( FragmentShaderID, GL_COMPILE_STATUS, &Result );
   if( Result == GL_FALSE ){
      InfoLogLength = 0;
      glGetShaderiv( FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength );
      vector <GLchar> FragmentShaderErrorMessage(InfoLogLength);
      glGetShaderInfoLog( FragmentShaderID, InfoLogLength, &InfoLogLength, &FragmentShaderErrorMessage[0] );
      Error.clear();
      Error = string( FragmentShaderErrorMessage.begin(), FragmentShaderErrorMessage.end() );
      cout<<"Fragment shader: "<<Error<<"\n";
      glDeleteShader( VertexShaderID );
      glDeleteShader( FragmentShaderID );
      return 0;
   }

   Result = GL_FALSE;
   InfoLogLength = 0;

   //Create program shader:
   /*
      Stworzenie programy z wszystkimi shaderami.
   */
   GLuint ProgramID = glCreateProgram();
   /*
      Dołączenie shadera wierzchołków do programu.
   */
   glAttachShader( ProgramID, VertexShaderID );
   /*
      Dołączenie shadera fragmentu do programu.
   */
   glAttachShader( ProgramID, FragmentShaderID );
   /*
      Linkuje program, aby mógł być wykorzystany później.
   */
   glLinkProgram( ProgramID );

   //Check program:
   /*
      Sprawdzenie poprawności stworzonego programu.
   */
   glGetProgramiv( ProgramID, GL_LINK_STATUS, &Result );
   /*
      Tak samo jak wcześniej, dla sprawdzania błędów w shaderach.
   */
   if( Result == GL_FALSE ){
      glGetProgramiv( ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength );
      vector <GLchar> ProgramErrorMessage(InfoLogLength);
      glGetProgramInfoLog( ProgramID, InfoLogLength, &InfoLogLength, &ProgramErrorMessage[0] );
      Error.clear();
      Error = string( ProgramErrorMessage.begin(), ProgramErrorMessage.end() );
      cout<<"program shader: "<<Error<<"\n";
      glDeleteProgram( ProgramID );
      glDeleteShader( VertexShaderID );
      glDeleteShader( FragmentShaderID );
      return 0;
   }

   //delete shaders:
   /*
      Wyczyszczenie pamięci po stworzonych shaderach, które teraz są w ProgramID.
   */
   glDetachShader( ProgramID, VertexShaderID );
   glDetachShader( ProgramID, FragmentShaderID );
   glDeleteShader( VertexShaderID );
   glDeleteShader( FragmentShaderID );

   /*
      Zwróć identyfikator programu shaderów.
   */
   return ProgramID;
}
Пример #15
0
GLuint LoadShaders(const char* vsPath, const char* fsPath)
{

    GLuint VertexShader = glCreateShader(GL_VERTEX_SHADER);
    GLuint FragmentShader = glCreateShader(GL_FRAGMENT_SHADER);

    std::string VertexShaderCode;
    std::ifstream VertexShaderStream(vsPath, std::ios::in);

    if( VertexShaderStream.good() )
    {
        std::string Line = "";
        while(getline(VertexShaderStream, Line))
            VertexShaderCode += "\n" + Line;
        VertexShaderStream.close();
    } else
        std::cout << "Error reading the vertex-shader." << std::endl;

    std::string FragmentShaderCode;
    std::ifstream FragmentShaderStream(fsPath, std::ios::in);

    if( FragmentShaderStream.good() )
    {
        std::string Line = "";
        while(getline(FragmentShaderStream, Line))
            FragmentShaderCode += "\n" + Line;
        FragmentShaderStream.close();
    } else
        std::cout << "Error reading the fragment-shader." << std::endl;

    GLint Result = GL_FALSE;
    int InfoLogLength;

    std::cout << "Compiling Shader: " << vsPath << std::endl;
    char const* VertexSourcePointer = VertexShaderCode.c_str();
    glShaderSource(VertexShader, 1, &VertexSourcePointer, NULL);
    glCompileShader(VertexShader);

    glGetShaderiv(VertexShader, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(VertexShader, GL_INFO_LOG_LENGTH, &InfoLogLength);
    char* vsError = new char[InfoLogLength];
    glGetShaderInfoLog(VertexShader, InfoLogLength, NULL, vsError);
    //if(!vsError)
        std::cout << "Vertex-shader error message: " << vsError << std::endl;
    delete [] vsError;


    std::cout << "Compiling Shader: " << fsPath << std::endl;
    char const * FragmentSourcePointer = FragmentShaderCode.c_str();
    glShaderSource(FragmentShader, 1, &FragmentSourcePointer, NULL);
    glCompileShader(FragmentShader);

    glGetShaderiv(FragmentShader, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(FragmentShader, GL_INFO_LOG_LENGTH, &InfoLogLength);
    char* fsError = new char[InfoLogLength];
    glGetShaderInfoLog(FragmentShader, InfoLogLength, NULL, fsError);
   // if(!fsError)
        std::cout << "Fragment-shader error message: " << fsError << std::endl;
    delete [] fsError;

    std::cout << "Linking program." << std::endl;
    GLuint Program = glCreateProgram();
    glAttachShader(Program, VertexShader);
    glAttachShader(Program, FragmentShader);
    glLinkProgram(Program);

    glGetProgramiv(Program, GL_LINK_STATUS, &Result);
    glGetProgramiv(Program, GL_INFO_LOG_LENGTH, &InfoLogLength);
    InfoLogLength = InfoLogLength < 1 ? 1 : InfoLogLength;
    char* programError = new char[InfoLogLength];
    glGetProgramInfoLog(Program, InfoLogLength, NULL, programError);
 //   if(!programError)
        std::cout << "Program-linking error message: " << programError << std::endl;
    delete [] programError;

    glDeleteShader(VertexShader);
    glDeleteShader(FragmentShader);

    return Program;
}
Пример #16
0
GLuint ShaderLoader::loadShaders(
  const char * vertex_file_path,
  const char * tesselation_control_file_path,
  const char * tesselation_eval_file_path,
  const char * geometry_file_path,
  const char * fragment_file_path)
{
  // Create the shaders
  // Vertex and fragment shader is a must
  GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
  GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
  
  GLuint TesselationControlShaderID;
  GLuint TesselationEvaluationShaderID;
  GLuint GeometryShaderID;

  if (tesselation_control_file_path)
    TesselationControlShaderID = glCreateShader(GL_TESS_CONTROL_SHADER);
  if (tesselation_eval_file_path)
    TesselationEvaluationShaderID = glCreateShader(GL_TESS_EVALUATION_SHADER);
  if (geometry_file_path)
    GeometryShaderID = glCreateShader(GL_GEOMETRY_SHADER);

  // Read the Vertex Shader code from the file
  std::string VertexShaderCode;
  std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
  if(VertexShaderStream.is_open())
  {
    std::string Line = "";
    while(getline(VertexShaderStream, Line))
      VertexShaderCode += "\n" + Line;
    VertexShaderStream.close();
  }
  
  std::string TesselationControlShaderCode;
  if (tesselation_control_file_path){
    // Read the Tesselation Control Shader code from the file
    std::ifstream TesselationControlShaderStream(tesselation_control_file_path, std::ios::in);
    if(TesselationControlShaderStream.is_open()){
      std::string Line = "";
      while(getline(TesselationControlShaderStream, Line))
        TesselationControlShaderCode += "\n" + Line;
      TesselationControlShaderStream.close();
    }
  }

  std::string TesselationEvaluationShaderCode;
  if (tesselation_eval_file_path){
    // Read the Tesselation Evaluation Shader code from the file
    std::ifstream TesselationEvalStream(tesselation_eval_file_path, std::ios::in);
    if(TesselationEvalStream.is_open()){
      std::string Line = "";
      while(getline(TesselationEvalStream, Line))
        TesselationEvaluationShaderCode += "\n" + Line;
      TesselationEvalStream.close();
    }
  }

  std::string GeometryShaderCode;
  if (geometry_file_path){
    // Read the Geometry Shader code from the file
    std::ifstream GeomatryShaderStream(geometry_file_path, std::ios::in);
    if(GeomatryShaderStream.is_open()){
      std::string Line = "";
      while(getline(GeomatryShaderStream, Line))
        GeometryShaderCode += "\n" + Line;
      GeomatryShaderStream.close();
    }
  }

  // Read the Fragment Shader code from the file
  std::string FragmentShaderCode;
  std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
  if(FragmentShaderStream.is_open()){
    std::string Line = "";
    while(getline(FragmentShaderStream, Line))
      FragmentShaderCode += "\n" + Line;
    FragmentShaderStream.close();
  }
  
  GLint Result = GL_FALSE;
  int InfoLogLength;
  
  // Compile Vertex Shader
  printf("Compiling shader : %s\n", vertex_file_path);
  char const * VertexSourcePointer = VertexShaderCode.c_str();
  glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
  glCompileShader(VertexShaderID);
  
  // Check Vertex Shader
  glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
  glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
  std::vector<char> VertexShaderErrorMessage(InfoLogLength);
  glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
  fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]);
  


  if (tesselation_control_file_path){
    // Compile Tesselation Control Shader
    printf("Compiling shader : %s\n", tesselation_control_file_path);
    char const * TesselationControlSourcePointer = TesselationControlShaderCode.c_str();
    glShaderSource(TesselationControlShaderID, 1, &TesselationControlSourcePointer , NULL);
    glCompileShader(TesselationControlShaderID);
    
    // Check Tesselation Control Shader
    glGetShaderiv(TesselationControlShaderID, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(TesselationControlShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    std::vector<char> TesselationControlShaderErrorMessage(InfoLogLength);
    glGetShaderInfoLog(TesselationControlShaderID, InfoLogLength, NULL, &TesselationControlShaderErrorMessage[0]);
    fprintf(stdout, "%s\n", &TesselationControlShaderErrorMessage[0]);
  }

  if (tesselation_eval_file_path){
    // Compile Fragment Shader
    printf("Compiling shader : %s\n", tesselation_eval_file_path);
    char const * TesselationEvaluationSourcePointer = TesselationEvaluationShaderCode.c_str();
    glShaderSource(TesselationEvaluationShaderID, 1, &TesselationEvaluationSourcePointer , NULL);
    glCompileShader(TesselationEvaluationShaderID);
    
    // Check TesselationEvaluation Shader
    glGetShaderiv(TesselationEvaluationShaderID, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(TesselationEvaluationShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    std::vector<char> TesselationEvaluationShaderErrorMessage(InfoLogLength);
    glGetShaderInfoLog(TesselationEvaluationShaderID, InfoLogLength, NULL, &TesselationEvaluationShaderErrorMessage[0]);
    fprintf(stdout, "%s\n", &TesselationEvaluationShaderErrorMessage[0]);
  }

  if (geometry_file_path){
    // Compile Fragment Shader
    printf("Compiling shader : %s\n", geometry_file_path);
    char const * GeometrySourcePointer = GeometryShaderCode.c_str();
    glShaderSource(GeometryShaderID, 1, &GeometrySourcePointer , NULL);
    glCompileShader(GeometryShaderID);
    
    // Check Geometry Shader
    glGetShaderiv(GeometryShaderID, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(GeometryShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    std::vector<char> GeometryShaderErrorMessage(InfoLogLength);
    glGetShaderInfoLog(GeometryShaderID, InfoLogLength, NULL, &GeometryShaderErrorMessage[0]);
    fprintf(stdout, "%s\n", &GeometryShaderErrorMessage[0]);
  }

  // Compile Fragment Shader
  printf("Compiling shader : %s\n", fragment_file_path);
  char const * FragmentSourcePointer = FragmentShaderCode.c_str();
  glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
  glCompileShader(FragmentShaderID);
  
  // Check Fragment Shader
  glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
  glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
  std::vector<char> FragmentShaderErrorMessage(InfoLogLength);
  glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
  fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]);
  
  // Link the program
  fprintf(stdout, "Linking program\n");
  GLuint ProgramID = glCreateProgram();
  glAttachShader(ProgramID, VertexShaderID);
  if (tesselation_control_file_path)
    glAttachShader(ProgramID, TesselationControlShaderID);
  if (tesselation_eval_file_path)
    glAttachShader(ProgramID, TesselationEvaluationShaderID);
  if (geometry_file_path)
    glAttachShader(ProgramID, GeometryShaderID);
  glAttachShader(ProgramID, FragmentShaderID);

  glLinkProgram(ProgramID);
  
  // Check the program
  glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
  glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
  std::vector<char> ProgramErrorMessage( std::max(InfoLogLength, int(1)) );
  glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
  fprintf(stdout, "%s\n", &ProgramErrorMessage[0]);
  
  glDeleteShader(VertexShaderID);
  if (tesselation_control_file_path)
    glDeleteShader(TesselationControlShaderID);
  if (tesselation_eval_file_path)
    glDeleteShader(TesselationEvaluationShaderID);
  if (geometry_file_path)
    glDeleteShader(GeometryShaderID);
  glDeleteShader(FragmentShaderID);

  return ProgramID;
}