I just recently got “The OpenGL Superbible” as my first opengl book and am starting to learn opengl 3.x+. Anyway, between that and the examples at mechcore.net i have written my first program, but I can’t get any shader errors. Here is my shader loading code:
void setupShaders()
{
GLint testval;
GLint abort = 0;
//Set Filenames
string vertexFName = "vertex.shader";
string fragFName = "fragment.shader";
//create variables needed
string source;
const char* source_c; //cstr version for OGL
const char* sour;
//create shaders and the program
vertexShader = glCreateShader(GL_VERTEX_SHADER);
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
shaderProg = glCreateProgram();
//load vertex shader
source = loadFromFile(vertexFName);
source_c = source.c_str();
sour = source_c;
glShaderSource(vertexShader, 1, &source_c, NULL);
//load fragment shader
source = loadFromFile(fragFName);
source_c = source.c_str();
glShaderSource(fragShader, 1, &source_c, NULL);
//compile and link
glCompileShader(vertexShader);
glCompileShader(fragShader);
glAttachShader(shaderProg, vertexShader);
glAttachShader(shaderProg, fragShader);
glLinkProgram(shaderProg);
//catch any errors
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &testval);
if(testval == GL_FALSE)
{
abort = 1;
char infolog[1024];
glGetShaderInfoLog(vertexShader,1024,NULL,infolog);
cout << "The vertex shader failed to compile with the error:" << endl << infolog << endl;
}
glGetShaderiv(fragShader, GL_COMPILE_STATUS, &testval);
if(testval == GL_FALSE)
{
abort = 1;
char infolog[1024];
glGetShaderInfoLog(fragShader,1024,NULL,infolog);
cout << "The fragment shader failed to compile with the error:" << endl << infolog << endl;
}
glGetProgramiv(shaderProg, GL_LINK_STATUS, &testval);
if(testval == GL_FALSE)
{
abort = 1;
char infolog[1024];
glGetProgramInfoLog(shaderProg,1024,NULL,infolog);
cout << "The program failed to compile with the error:" << endl << infolog << endl;
}
if(abort)
{
cout << "errors occured, cannot continue, aborting." << endl;
exit(-1);
}
Sorry about the length,
EDIT: oh, the output may help, it outputs
The vertex shader failed to compile with the error:
The fragment shader failed to compile with the error:
The program failed to compile with the error:
errors occured, cannot continue, aborting.