OpenGLController: moved some code around
shader: throw errors
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
@@ -27,10 +25,12 @@ GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string message("File not found: ");
|
||||
message += std::string(vertex_file_path);
|
||||
throw std::invalid_argument(message.c_str());
|
||||
}
|
||||
|
||||
// Read the Fragment Shader code from the file
|
||||
@@ -42,13 +42,18 @@ GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path
|
||||
FragmentShaderCode += "\n" + Line;
|
||||
FragmentShaderStream.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string message("File not found: ");
|
||||
message += std::string(fragment_file_path);
|
||||
throw std::invalid_argument(message.c_str());
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -59,13 +64,12 @@ GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path
|
||||
if ( InfoLogLength > 0 ){
|
||||
std::vector<char> VertexShaderErrorMessage(InfoLogLength+1);
|
||||
glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
|
||||
printf("%s\n", &VertexShaderErrorMessage[0]);
|
||||
throw std::invalid_argument(VertexShaderErrorMessage.data());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Compile Fragment Shader
|
||||
printf("Compiling shader : %s\n", fragment_file_path);
|
||||
char const * FragmentSourcePointer = FragmentShaderCode.c_str();
|
||||
glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
|
||||
glCompileShader(FragmentShaderID);
|
||||
@@ -76,13 +80,12 @@ GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path
|
||||
if ( InfoLogLength > 0 ){
|
||||
std::vector<char> FragmentShaderErrorMessage(InfoLogLength+1);
|
||||
glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
|
||||
printf("%s\n", &FragmentShaderErrorMessage[0]);
|
||||
throw std::invalid_argument(FragmentShaderErrorMessage.data());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Link the program
|
||||
printf("Linking program\n");
|
||||
GLuint ProgramID = glCreateProgram();
|
||||
glAttachShader(ProgramID, VertexShaderID);
|
||||
glAttachShader(ProgramID, FragmentShaderID);
|
||||
@@ -94,7 +97,7 @@ GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path
|
||||
if ( InfoLogLength > 0 ){
|
||||
std::vector<char> ProgramErrorMessage(InfoLogLength+1);
|
||||
glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
|
||||
printf("%s\n", &ProgramErrorMessage[0]);
|
||||
throw std::invalid_argument(ProgramErrorMessage.data());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user