create and link program, add getProgramLog()
This commit is contained in:
parent
5a1fed9a41
commit
c6e51524e9
@ -11,7 +11,7 @@ using namespace std;
|
||||
#define WIDTH 800
|
||||
#define HEIGHT 600
|
||||
|
||||
GLuint vs, fs;
|
||||
GLuint program, vs, fs;
|
||||
|
||||
char * loadFile(const char *fname)
|
||||
{
|
||||
@ -38,6 +38,19 @@ char *getShaderLog(GLuint id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *getProgramLog(GLuint id)
|
||||
{
|
||||
GLint log_length;
|
||||
glGetProgramiv(id, GL_INFO_LOG_LENGTH, &log_length);
|
||||
if (log_length > 0)
|
||||
{
|
||||
char *log = new char[log_length];
|
||||
glGetProgramInfoLog(id, log_length, &log_length, log);
|
||||
return log;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GLuint makeShader(GLenum shaderType, const char *fname)
|
||||
{
|
||||
GLuint id;
|
||||
@ -101,6 +114,23 @@ bool init(int width, int height)
|
||||
return false;
|
||||
}
|
||||
|
||||
program = glCreateProgram();
|
||||
glAttachShader(program, vs);
|
||||
glAttachShader(program, fs);
|
||||
glLinkProgram(program);
|
||||
|
||||
GLint link_status;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &link_status);
|
||||
if (link_status != GL_TRUE)
|
||||
{
|
||||
char *log = getProgramLog(program);
|
||||
cerr << "Program log:" << endl << log << endl;
|
||||
delete[] log;
|
||||
glDeleteShader(vs);
|
||||
glDeleteShader(fs);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user