Bind attribute location
Realized that attribute locations were not bound for the geometry pass. Fixed that and renamed variables to be camelCase
This commit is contained in:
parent
944f98243c
commit
f638a2f1f8
|
@ -1,7 +1,7 @@
|
|||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec2 inTexCoord;
|
||||
layout(location = 0) in vec3 posAttrib;
|
||||
layout(location = 1) in vec2 texCoordAttrib;
|
||||
|
||||
out VS_OUT {
|
||||
vec3 position;
|
||||
|
@ -9,6 +9,6 @@ out VS_OUT {
|
|||
} vs_out;
|
||||
|
||||
void main() {
|
||||
vs_out.position = (vec4(inPosition, 1.0f)).xyz;
|
||||
vs_out.texCoord = inTexCoord;
|
||||
vs_out.position = (vec4(posAttrib, 1.0f)).xyz;
|
||||
vs_out.texCoord = texCoordAttrib;
|
||||
}
|
|
@ -10,106 +10,106 @@ using namespace std;
|
|||
// Create a NULL-terminated string by reading the provided file
|
||||
static char* readShaderSource(const char* shaderFile)
|
||||
{
|
||||
ifstream ifs(shaderFile, ios::in | ios::binary | ios::ate);
|
||||
if (ifs.is_open())
|
||||
{
|
||||
unsigned int filesize = static_cast<unsigned int>(ifs.tellg());
|
||||
ifs.seekg(0, ios::beg);
|
||||
char* bytes = new char[filesize + 1];
|
||||
memset(bytes, 0, filesize + 1);
|
||||
ifs.read(bytes, filesize);
|
||||
ifs.close();
|
||||
return bytes;
|
||||
}
|
||||
return NULL;
|
||||
ifstream ifs(shaderFile, ios::in | ios::binary | ios::ate);
|
||||
if (ifs.is_open())
|
||||
{
|
||||
unsigned int filesize = static_cast<unsigned int>(ifs.tellg());
|
||||
ifs.seekg(0, ios::beg);
|
||||
char* bytes = new char[filesize + 1];
|
||||
memset(bytes, 0, filesize + 1);
|
||||
ifs.read(bytes, filesize);
|
||||
ifs.close();
|
||||
return bytes;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void printShaderCompileError(GLuint shader)
|
||||
{
|
||||
GLint logSize;
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logSize);
|
||||
char* logMsg = new char[logSize];
|
||||
glGetShaderInfoLog(shader, logSize, NULL, logMsg);
|
||||
std::cerr << logMsg << std::endl;
|
||||
delete[] logMsg;
|
||||
GLint logSize;
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logSize);
|
||||
char* logMsg = new char[logSize];
|
||||
glGetShaderInfoLog(shader, logSize, NULL, logMsg);
|
||||
std::cerr << logMsg << std::endl;
|
||||
delete[] logMsg;
|
||||
|
||||
}
|
||||
|
||||
void printProgramLinkError(GLuint program)
|
||||
{
|
||||
GLint logSize;
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logSize);
|
||||
char* logMsg = new char[logSize];
|
||||
glGetProgramInfoLog(program, logSize, NULL, logMsg);
|
||||
std::cerr << logMsg << std::endl;
|
||||
delete[] logMsg;
|
||||
GLint logSize;
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logSize);
|
||||
char* logMsg = new char[logSize];
|
||||
glGetProgramInfoLog(program, logSize, NULL, logMsg);
|
||||
std::cerr << logMsg << std::endl;
|
||||
delete[] logMsg;
|
||||
}
|
||||
|
||||
GLuint InitShader(const char* computeShaderFile)
|
||||
{
|
||||
bool error = false;
|
||||
struct Shader
|
||||
{
|
||||
const char* filename;
|
||||
GLenum type;
|
||||
GLchar* source;
|
||||
} shaders[1] =
|
||||
{
|
||||
{ computeShaderFile, GL_COMPUTE_SHADER, NULL }
|
||||
};
|
||||
bool error = false;
|
||||
struct Shader
|
||||
{
|
||||
const char* filename;
|
||||
GLenum type;
|
||||
GLchar* source;
|
||||
} shaders[1] =
|
||||
{
|
||||
{ computeShaderFile, GL_COMPUTE_SHADER, NULL }
|
||||
};
|
||||
|
||||
GLuint program = glCreateProgram();
|
||||
GLuint program = glCreateProgram();
|
||||
|
||||
for (int i = 0; i < 1; ++i)
|
||||
{
|
||||
Shader& s = shaders[i];
|
||||
s.source = readShaderSource(s.filename);
|
||||
if (shaders[i].source == NULL)
|
||||
{
|
||||
std::cerr << "Failed to read " << s.filename << std::endl;
|
||||
error = true;
|
||||
}
|
||||
for (int i = 0; i < 1; ++i)
|
||||
{
|
||||
Shader& s = shaders[i];
|
||||
s.source = readShaderSource(s.filename);
|
||||
if (shaders[i].source == NULL)
|
||||
{
|
||||
std::cerr << "Failed to read " << s.filename << std::endl;
|
||||
error = true;
|
||||
}
|
||||
|
||||
GLuint shader = glCreateShader(s.type);
|
||||
glShaderSource(shader, 1, (const GLchar**)&s.source, NULL);
|
||||
glCompileShader(shader);
|
||||
GLuint shader = glCreateShader(s.type);
|
||||
glShaderSource(shader, 1, (const GLchar**)&s.source, NULL);
|
||||
glCompileShader(shader);
|
||||
|
||||
GLint compiled;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
|
||||
if (!compiled)
|
||||
{
|
||||
std::cerr << s.filename << " failed to compile:" << std::endl;
|
||||
printShaderCompileError(shader);
|
||||
error = true;
|
||||
}
|
||||
GLint compiled;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
|
||||
if (!compiled)
|
||||
{
|
||||
std::cerr << s.filename << " failed to compile:" << std::endl;
|
||||
printShaderCompileError(shader);
|
||||
error = true;
|
||||
}
|
||||
|
||||
delete[] s.source;
|
||||
delete[] s.source;
|
||||
|
||||
glAttachShader(program, shader);
|
||||
}
|
||||
glAttachShader(program, shader);
|
||||
}
|
||||
|
||||
/* link and error check */
|
||||
glLinkProgram(program);
|
||||
/* link and error check */
|
||||
glLinkProgram(program);
|
||||
|
||||
GLint linked;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &linked);
|
||||
if (!linked)
|
||||
{
|
||||
std::cerr << "Shader program failed to link" << std::endl;
|
||||
printProgramLinkError(program);
|
||||
GLint linked;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &linked);
|
||||
if (!linked)
|
||||
{
|
||||
std::cerr << "Shader program failed to link" << std::endl;
|
||||
printProgramLinkError(program);
|
||||
|
||||
error = true;
|
||||
}
|
||||
error = true;
|
||||
}
|
||||
|
||||
if (error == true)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (error == true)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* use program object */
|
||||
glUseProgram(program);
|
||||
/* use program object */
|
||||
glUseProgram(program);
|
||||
|
||||
return program;
|
||||
return program;
|
||||
}
|
||||
|
||||
|
||||
|
@ -117,294 +117,301 @@ GLuint InitShader(const char* computeShaderFile)
|
|||
GLuint InitShader(const char* vShaderFile, const char* fShaderFile)
|
||||
{
|
||||
|
||||
bool error = false;
|
||||
struct Shader
|
||||
{
|
||||
const char* filename;
|
||||
GLenum type;
|
||||
GLchar* source;
|
||||
} shaders[2] =
|
||||
{
|
||||
{ vShaderFile, GL_VERTEX_SHADER, NULL },
|
||||
{ fShaderFile, GL_FRAGMENT_SHADER, NULL }
|
||||
};
|
||||
bool error = false;
|
||||
struct Shader
|
||||
{
|
||||
const char* filename;
|
||||
GLenum type;
|
||||
GLchar* source;
|
||||
} shaders[2] =
|
||||
{
|
||||
{ vShaderFile, GL_VERTEX_SHADER, NULL },
|
||||
{ fShaderFile, GL_FRAGMENT_SHADER, NULL }
|
||||
};
|
||||
|
||||
GLuint program = glCreateProgram();
|
||||
GLuint program = glCreateProgram();
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
Shader& s = shaders[i];
|
||||
s.source = readShaderSource(s.filename);
|
||||
if (shaders[i].source == NULL)
|
||||
{
|
||||
std::cerr << "Failed to read " << s.filename << std::endl;
|
||||
error = true;
|
||||
}
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
Shader& s = shaders[i];
|
||||
s.source = readShaderSource(s.filename);
|
||||
if (shaders[i].source == NULL)
|
||||
{
|
||||
std::cerr << "Failed to read " << s.filename << std::endl;
|
||||
error = true;
|
||||
}
|
||||
|
||||
GLuint shader = glCreateShader(s.type);
|
||||
glShaderSource(shader, 1, (const GLchar**)&s.source, NULL);
|
||||
glCompileShader(shader);
|
||||
GLuint shader = glCreateShader(s.type);
|
||||
glShaderSource(shader, 1, (const GLchar**)&s.source, NULL);
|
||||
glCompileShader(shader);
|
||||
|
||||
GLint compiled;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
|
||||
if (!compiled)
|
||||
{
|
||||
std::cerr << s.filename << " failed to compile:" << std::endl;
|
||||
printShaderCompileError(shader);
|
||||
error = true;
|
||||
}
|
||||
GLint compiled;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
|
||||
if (!compiled)
|
||||
{
|
||||
std::cerr << s.filename << " failed to compile:" << std::endl;
|
||||
printShaderCompileError(shader);
|
||||
error = true;
|
||||
}
|
||||
|
||||
delete[] s.source;
|
||||
delete[] s.source;
|
||||
|
||||
glAttachShader(program, shader);
|
||||
}
|
||||
glAttachShader(program, shader);
|
||||
}
|
||||
|
||||
//set shader attrib locations
|
||||
const int pos_loc = 0;
|
||||
const int tex_coord_loc = 1;
|
||||
const int normal_loc = 2;
|
||||
//set shader attrib locations
|
||||
const int posLoc = 0;
|
||||
const int texCoordLoc = 1;
|
||||
const int normalLoc = 2;
|
||||
|
||||
glBindAttribLocation(program, pos_loc, "pos_attrib");
|
||||
glBindAttribLocation(program, tex_coord_loc, "tex_coord_attrib");
|
||||
glBindAttribLocation(program, normal_loc, "normal_attrib");
|
||||
glBindAttribLocation(program, posLoc, "posAttrib");
|
||||
glBindAttribLocation(program, texCoordLoc, "texCoordAttrib");
|
||||
glBindAttribLocation(program, normalLoc, "normalAttrib");
|
||||
|
||||
/* link and error check */
|
||||
glLinkProgram(program);
|
||||
/* link and error check */
|
||||
glLinkProgram(program);
|
||||
|
||||
GLint linked;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &linked);
|
||||
if (!linked)
|
||||
{
|
||||
std::cerr << "Shader program failed to link" << std::endl;
|
||||
printProgramLinkError(program);
|
||||
GLint linked;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &linked);
|
||||
if (!linked)
|
||||
{
|
||||
std::cerr << "Shader program failed to link" << std::endl;
|
||||
printProgramLinkError(program);
|
||||
|
||||
error = true;
|
||||
}
|
||||
error = true;
|
||||
}
|
||||
|
||||
if (error == true)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (error == true)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* use program object */
|
||||
glUseProgram(program);
|
||||
return program;
|
||||
/* use program object */
|
||||
glUseProgram(program);
|
||||
return program;
|
||||
}
|
||||
|
||||
// Create a GLSL program object from vertex and fragment shader files
|
||||
GLuint InitShader(const char* vShaderFile, const char* gShaderFile, const char* fShaderFile)
|
||||
{
|
||||
bool error = false;
|
||||
struct Shader
|
||||
{
|
||||
const char* filename;
|
||||
GLenum type;
|
||||
GLchar* source;
|
||||
} shaders[3] =
|
||||
{
|
||||
{ vShaderFile, GL_VERTEX_SHADER, NULL },
|
||||
{ gShaderFile, GL_GEOMETRY_SHADER, NULL },
|
||||
{ fShaderFile, GL_FRAGMENT_SHADER, NULL }
|
||||
};
|
||||
bool error = false;
|
||||
struct Shader
|
||||
{
|
||||
const char* filename;
|
||||
GLenum type;
|
||||
GLchar* source;
|
||||
} shaders[3] =
|
||||
{
|
||||
{ vShaderFile, GL_VERTEX_SHADER, NULL },
|
||||
{ gShaderFile, GL_GEOMETRY_SHADER, NULL },
|
||||
{ fShaderFile, GL_FRAGMENT_SHADER, NULL }
|
||||
};
|
||||
|
||||
GLuint program = glCreateProgram();
|
||||
GLuint program = glCreateProgram();
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
Shader& s = shaders[i];
|
||||
s.source = readShaderSource(s.filename);
|
||||
if (shaders[i].source == NULL)
|
||||
{
|
||||
std::cerr << "Failed to read " << s.filename << std::endl;
|
||||
error = true;
|
||||
}
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
Shader& s = shaders[i];
|
||||
s.source = readShaderSource(s.filename);
|
||||
if (shaders[i].source == NULL)
|
||||
{
|
||||
std::cerr << "Failed to read " << s.filename << std::endl;
|
||||
error = true;
|
||||
}
|
||||
|
||||
GLuint shader = glCreateShader(s.type);
|
||||
glShaderSource(shader, 1, (const GLchar**)&s.source, NULL);
|
||||
glCompileShader(shader);
|
||||
GLuint shader = glCreateShader(s.type);
|
||||
glShaderSource(shader, 1, (const GLchar**)&s.source, NULL);
|
||||
glCompileShader(shader);
|
||||
|
||||
GLint compiled;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
|
||||
if (!compiled)
|
||||
{
|
||||
std::cerr << s.filename << " failed to compile:" << std::endl;
|
||||
printShaderCompileError(shader);
|
||||
error = true;
|
||||
}
|
||||
GLint compiled;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
|
||||
if (!compiled)
|
||||
{
|
||||
std::cerr << s.filename << " failed to compile:" << std::endl;
|
||||
printShaderCompileError(shader);
|
||||
error = true;
|
||||
}
|
||||
|
||||
delete[] s.source;
|
||||
delete[] s.source;
|
||||
|
||||
glAttachShader(program, shader);
|
||||
}
|
||||
glAttachShader(program, shader);
|
||||
}
|
||||
|
||||
//set shader attrib locations
|
||||
const int pos_loc = 0;
|
||||
const int tex_coord_loc = 1;
|
||||
const int normal_loc = 2;
|
||||
//set shader attrib locations
|
||||
const int posLoc = 0;
|
||||
const int texCoordLoc = 1;
|
||||
const int normalLoc = 2;
|
||||
|
||||
glBindAttribLocation(program, pos_loc, "pos_attrib");
|
||||
glBindAttribLocation(program, tex_coord_loc, "tex_coord_attrib");
|
||||
glBindAttribLocation(program, normal_loc, "normal_attrib");
|
||||
glBindAttribLocation(program, posLoc, "posAttrib");
|
||||
glBindAttribLocation(program, texCoordLoc, "texCoordAttrib");
|
||||
glBindAttribLocation(program, normalLoc, "normalAttrib");
|
||||
|
||||
/* link and error check */
|
||||
glLinkProgram(program);
|
||||
/* link and error check */
|
||||
glLinkProgram(program);
|
||||
|
||||
GLint linked;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &linked);
|
||||
if (!linked)
|
||||
{
|
||||
std::cerr << "Shader program failed to link" << std::endl;
|
||||
printProgramLinkError(program);
|
||||
GLint linked;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &linked);
|
||||
if (!linked)
|
||||
{
|
||||
std::cerr << "Shader program failed to link" << std::endl;
|
||||
printProgramLinkError(program);
|
||||
|
||||
error = true;
|
||||
}
|
||||
error = true;
|
||||
}
|
||||
|
||||
if (error == true)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (error == true)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* use program object */
|
||||
glUseProgram(program);
|
||||
/* use program object */
|
||||
glUseProgram(program);
|
||||
|
||||
return program;
|
||||
return program;
|
||||
}
|
||||
|
||||
GLuint InitShader( const char* vShaderFile, const char* tcShader, const char* teShader, const char* fShaderFile )
|
||||
{
|
||||
bool error = false;
|
||||
struct Shader
|
||||
{
|
||||
const char* filename;
|
||||
GLenum type;
|
||||
std::string source;
|
||||
} shaders[4] =
|
||||
{
|
||||
{ vShaderFile, GL_VERTEX_SHADER, "" },
|
||||
{ tcShader, GL_TESS_CONTROL_SHADER, "" },
|
||||
{ teShader, GL_TESS_EVALUATION_SHADER, "" },
|
||||
{ fShaderFile, GL_FRAGMENT_SHADER, "" }
|
||||
};
|
||||
bool error = false;
|
||||
struct Shader
|
||||
{
|
||||
const char* filename;
|
||||
GLenum type;
|
||||
std::string source;
|
||||
} shaders[4] =
|
||||
{
|
||||
{ vShaderFile, GL_VERTEX_SHADER, "" },
|
||||
{ tcShader, GL_TESS_CONTROL_SHADER, "" },
|
||||
{ teShader, GL_TESS_EVALUATION_SHADER, "" },
|
||||
{ fShaderFile, GL_FRAGMENT_SHADER, "" }
|
||||
};
|
||||
|
||||
GLuint program = glCreateProgram();
|
||||
GLuint program = glCreateProgram();
|
||||
|
||||
for ( int i = 0; i < 4; ++i )
|
||||
{
|
||||
Shader& s = shaders[i];
|
||||
s.source = readShaderSource(s.filename);
|
||||
if ( shaders[i].source.length() == 0 )
|
||||
{
|
||||
std::cerr << "Failed to read " << s.filename << std::endl;
|
||||
error = true;
|
||||
}
|
||||
for ( int i = 0; i < 4; ++i )
|
||||
{
|
||||
Shader& s = shaders[i];
|
||||
s.source = readShaderSource(s.filename);
|
||||
if ( shaders[i].source.length() == 0 )
|
||||
{
|
||||
std::cerr << "Failed to read " << s.filename << std::endl;
|
||||
error = true;
|
||||
}
|
||||
|
||||
GLuint shader = glCreateShader( s.type );
|
||||
const char *c_str = s.source.c_str();
|
||||
glShaderSource(shader, 1, (const GLchar**)&c_str, NULL);
|
||||
glCompileShader( shader );
|
||||
GLuint shader = glCreateShader( s.type );
|
||||
const char *c_str = s.source.c_str();
|
||||
glShaderSource(shader, 1, (const GLchar**)&c_str, NULL);
|
||||
glCompileShader( shader );
|
||||
|
||||
GLint compiled;
|
||||
glGetShaderiv( shader, GL_COMPILE_STATUS, &compiled );
|
||||
if ( !compiled )
|
||||
{
|
||||
std::cerr << s.filename << " failed to compile:" << std::endl;
|
||||
printShaderCompileError(shader);
|
||||
error = true;
|
||||
}
|
||||
GLint compiled;
|
||||
glGetShaderiv( shader, GL_COMPILE_STATUS, &compiled );
|
||||
if ( !compiled )
|
||||
{
|
||||
std::cerr << s.filename << " failed to compile:" << std::endl;
|
||||
printShaderCompileError(shader);
|
||||
error = true;
|
||||
}
|
||||
|
||||
glAttachShader( program, shader );
|
||||
}
|
||||
glAttachShader( program, shader );
|
||||
}
|
||||
|
||||
/* link and error check */
|
||||
glLinkProgram(program);
|
||||
//set shader attrib locations
|
||||
const int posLoc = 0;
|
||||
const int texCoordLoc = 1;
|
||||
|
||||
GLint linked;
|
||||
glGetProgramiv( program, GL_LINK_STATUS, &linked );
|
||||
if ( !linked )
|
||||
{
|
||||
std::cerr << "Shader program failed to link" << std::endl;
|
||||
printProgramLinkError(program);
|
||||
glBindAttribLocation(program, posLoc, "posAttrib");
|
||||
glBindAttribLocation(program, texCoordLoc, "texCoordAttrib");
|
||||
|
||||
error = true;
|
||||
}
|
||||
/* link and error check */
|
||||
glLinkProgram(program);
|
||||
|
||||
if(error == true)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
GLint linked;
|
||||
glGetProgramiv( program, GL_LINK_STATUS, &linked );
|
||||
if ( !linked )
|
||||
{
|
||||
std::cerr << "Shader program failed to link" << std::endl;
|
||||
printProgramLinkError(program);
|
||||
|
||||
/* use program object */
|
||||
glUseProgram(program);
|
||||
error = true;
|
||||
}
|
||||
|
||||
return program;
|
||||
if(error == true)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* use program object */
|
||||
glUseProgram(program);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
GLuint InitShader( const char* vShaderFile, const char* tcShader, const char* teShader, const char* gShaderFile, const char* fShaderFile )
|
||||
{
|
||||
bool error = false;
|
||||
struct Shader
|
||||
{
|
||||
const char* filename;
|
||||
GLenum type;
|
||||
std::string source;
|
||||
} shaders[5] =
|
||||
{
|
||||
{ vShaderFile, GL_VERTEX_SHADER, "" },
|
||||
{ tcShader, GL_TESS_CONTROL_SHADER, "" },
|
||||
{ teShader, GL_TESS_EVALUATION_SHADER, "" },
|
||||
{ gShaderFile, GL_GEOMETRY_SHADER, "" },
|
||||
{ fShaderFile, GL_FRAGMENT_SHADER, "" }
|
||||
};
|
||||
bool error = false;
|
||||
struct Shader
|
||||
{
|
||||
const char* filename;
|
||||
GLenum type;
|
||||
std::string source;
|
||||
} shaders[5] =
|
||||
{
|
||||
{ vShaderFile, GL_VERTEX_SHADER, "" },
|
||||
{ tcShader, GL_TESS_CONTROL_SHADER, "" },
|
||||
{ teShader, GL_TESS_EVALUATION_SHADER, "" },
|
||||
{ gShaderFile, GL_GEOMETRY_SHADER, "" },
|
||||
{ fShaderFile, GL_FRAGMENT_SHADER, "" }
|
||||
};
|
||||
|
||||
GLuint program = glCreateProgram();
|
||||
|
||||
for ( int i = 0; i < 5; ++i )
|
||||
{
|
||||
Shader& s = shaders[i];
|
||||
s.source = readShaderSource(s.filename);
|
||||
if ( shaders[i].source.length() == 0 )
|
||||
{
|
||||
std::cerr << "Failed to read " << s.filename << std::endl;
|
||||
error = true;
|
||||
}
|
||||
GLuint program = glCreateProgram();
|
||||
|
||||
for ( int i = 0; i < 5; ++i )
|
||||
{
|
||||
Shader& s = shaders[i];
|
||||
s.source = readShaderSource(s.filename);
|
||||
if ( shaders[i].source.length() == 0 )
|
||||
{
|
||||
std::cerr << "Failed to read " << s.filename << std::endl;
|
||||
error = true;
|
||||
}
|
||||
|
||||
GLuint shader = glCreateShader( s.type );
|
||||
const char *c_str = s.source.c_str();
|
||||
glShaderSource( shader, 1, (const GLchar**) &c_str, NULL );
|
||||
glCompileShader( shader );
|
||||
GLuint shader = glCreateShader( s.type );
|
||||
const char *c_str = s.source.c_str();
|
||||
glShaderSource( shader, 1, (const GLchar**) &c_str, NULL );
|
||||
glCompileShader( shader );
|
||||
|
||||
GLint compiled;
|
||||
glGetShaderiv( shader, GL_COMPILE_STATUS, &compiled );
|
||||
if ( !compiled )
|
||||
{
|
||||
std::cerr << s.filename << " failed to compile:" << std::endl;
|
||||
printShaderCompileError(shader);
|
||||
error = true;
|
||||
}
|
||||
GLint compiled;
|
||||
glGetShaderiv( shader, GL_COMPILE_STATUS, &compiled );
|
||||
if ( !compiled )
|
||||
{
|
||||
std::cerr << s.filename << " failed to compile:" << std::endl;
|
||||
printShaderCompileError(shader);
|
||||
error = true;
|
||||
}
|
||||
|
||||
glAttachShader( program, shader );
|
||||
}
|
||||
glAttachShader( program, shader );
|
||||
}
|
||||
|
||||
/* link and error check */
|
||||
glLinkProgram(program);
|
||||
/* link and error check */
|
||||
glLinkProgram(program);
|
||||
|
||||
GLint linked;
|
||||
glGetProgramiv( program, GL_LINK_STATUS, &linked );
|
||||
if ( !linked )
|
||||
{
|
||||
std::cerr << "Shader program failed to link" << std::endl;
|
||||
printProgramLinkError(program);
|
||||
GLint linked;
|
||||
glGetProgramiv( program, GL_LINK_STATUS, &linked );
|
||||
if ( !linked )
|
||||
{
|
||||
std::cerr << "Shader program failed to link" << std::endl;
|
||||
printProgramLinkError(program);
|
||||
|
||||
error = true;
|
||||
}
|
||||
error = true;
|
||||
}
|
||||
|
||||
if(error == true)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(error == true)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* use program object */
|
||||
glUseProgram(program);
|
||||
/* use program object */
|
||||
glUseProgram(program);
|
||||
|
||||
return program;
|
||||
return program;
|
||||
}
|
Loading…
Reference in New Issue