in roboschool/cpp-household/render-simple.cpp [80:115]
shared_ptr<QGLShaderProgram> load_program(
const std::string& vert_fn, const std::string& geom_fn, const std::string& frag_fn,
const char* vert_defines, const char* geom_defines, const char* frag_defines)
{
shared_ptr<QGLShaderProgram> prog(new QGLShaderProgram);
std::string common_header;
if (!vert_fn.empty()) {
std::string vert_prog_text = read_file(glsl_path + "/" + vert_fn);
common_header = "";
if (vert_defines) common_header += vert_defines;
prog->addShaderFromSourceCode(QGLShader::Vertex, (common_header + vert_prog_text).c_str());
if (!prog->log().isEmpty())
fprintf(stderr, "%s LOG: '%s'\n", vert_fn.c_str(), prog->log().toUtf8().data());
}
if (!geom_fn.empty()) {
std::string geom_prog_text = read_file(glsl_path + "/" + geom_fn);
common_header = "";
if (geom_defines) common_header += geom_defines;
prog->addShaderFromSourceCode(QGLShader::Geometry, (common_header + geom_prog_text).c_str());
if (!prog->log().isEmpty())
fprintf(stderr, "%s LOG: '%s'\n", geom_fn.c_str(), prog->log().toUtf8().data());
}
if (!frag_fn.empty()) {
std::string frag_prog_text = read_file(glsl_path + "/" + frag_fn);
common_header = "";
if (frag_defines) common_header += frag_defines;
prog->addShaderFromSourceCode(QGLShader::Fragment, (common_header + frag_prog_text).c_str());
if (!prog->log().isEmpty())
fprintf(stderr, "%s LOG: '%s'\n", frag_fn.c_str(), prog->log().toUtf8().data());
}
return prog;
}