本文整理汇总了C++中QOpenGLShaderProgram::addShaderFromSourceFile方法的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLShaderProgram::addShaderFromSourceFile方法的具体用法?C++ QOpenGLShaderProgram::addShaderFromSourceFile怎么用?C++ QOpenGLShaderProgram::addShaderFromSourceFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QOpenGLShaderProgram
的用法示例。
在下文中一共展示了QOpenGLShaderProgram::addShaderFromSourceFile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initShaders
bool AnimeGLWidget::initShaders(QOpenGLShaderProgram &program, QString prefix)
{
if (!program.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/root/Resources/shaders/" + prefix + "_v.glsl"))
{
qDebug() << "failed add shader vertex";
return false;
}
if (!program.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/root/Resources/shaders/" + prefix + "_f.glsl"))
{
qDebug() << "failed add shader fragment";
return false;
}
if (!program.link())
{
qDebug() << "failed link";
return false;
}
if (!program.bind())
{
qDebug() << "failed bind";
return false;
}
return true;
}
示例2: loadShader
void DVWindow::loadShader(QOpenGLShaderProgram& shader, const char* vshader, const char* fshader) {
/* Load the shaders from the qrc. */
shader.addShaderFromSourceFile(QOpenGLShader::Vertex, vshader);
QFile res(fshader);
res.open(QIODevice::ReadOnly | QIODevice::Text);
QString fshaderSrc = res.readAll();
if (!context()->isOpenGLES())
fshaderSrc.prepend("#version 130\n");
shader.addShaderFromSourceCode(QOpenGLShader::Fragment, fshaderSrc);
/* Bind the attribute handles. */
shader.bindAttributeLocation("vertex", vertex);
shader.bindAttributeLocation("uv", uv);
shader.link();
/* Bind so we set the texture sampler uniform values. */
shader.bind();
/* Left image is TEXTURE0. */
shader.setUniformValue("textureL", 0);
/* Right image is TEXTURE1. */
shader.setUniformValue("textureR", 1);
}
示例3: declare_program
QOpenGLShaderProgram* Viewer::declare_program(int name,
const char* v_shader,
const char* f_shader) const
{
// workaround constness issues in Qt
Viewer* viewer = const_cast<Viewer*>(this);
if(d->shader_programs[name])
{
return d->shader_programs[name];
}
else
{
QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer);
if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,v_shader))
{
std::cerr<<"adding vertex shader FAILED"<<std::endl;
}
if(!program->addShaderFromSourceFile(QOpenGLShader::Fragment,f_shader))
{
std::cerr<<"adding fragment shader FAILED"<<std::endl;
}
if(isOpenGL_4_3())
{
if(strcmp(f_shader,":/cgal/Polyhedron_3/resources/shader_flat.f" ) == 0)
{
if(!program->addShaderFromSourceFile(QOpenGLShader::Geometry,":/cgal/Polyhedron_3/resources/shader_flat.g" ))
{
std::cerr<<"adding geometry shader FAILED"<<std::endl;
}
}
if(strcmp(f_shader,":/cgal/Polyhedron_3/resources/solid_wireframe_shader.f" ) == 0)
{
if(!program->addShaderFromSourceFile(QOpenGLShader::Geometry,":/cgal/Polyhedron_3/resources/solid_wireframe_shader.g" ))
{
std::cerr<<"adding geometry shader FAILED"<<std::endl;
}
}
}
program->bindAttributeLocation("colors", 1);
program->link();
d->shader_programs[name] = program;
return program;
}
}
示例4:
QOpenGLShaderProgram *
GLView::erstelleShaderProgramAusDateien( QString const & p_filenameVertexShader, QString const & p_filenameFragmentShader ) {
QOpenGLShaderProgram
* shaderProgram = new QOpenGLShaderProgram( this );
if( !shaderProgram ) {
qWarning( ) << "Shader Programm konnte nicht erzeugt werden.\n";
return 0;
}
if( !shaderProgram->addShaderFromSourceFile( QOpenGLShader::Vertex, shadersPath + "/" + p_filenameVertexShader ) ){
shaderProgram->removeAllShaders( );
delete shaderProgram;
shaderProgram = 0;
qWarning( ) << "Vertex Shader konnte nicht geladen oder kompiliert werden.\n";
return 0;
}
if( !shaderProgram->addShaderFromSourceFile( QOpenGLShader::Fragment, shadersPath + "/" + p_filenameFragmentShader ) ){
shaderProgram->removeAllShaders( );
delete shaderProgram;
shaderProgram = 0;
qWarning( ) << "Fragment Shader konnte nicht geladen oder kompiliert werden.\n";
return 0;
}
if( !shaderProgram->link( ) ){
qWarning( ) << "Shader Programm konnte nicht gelinkt werden.\n";
return 0;
}
return shaderProgram;
}
示例5: getShaderProgram
QOpenGLShaderProgram* Scene_item::getShaderProgram(int name, Viewer_interface * viewer) const
{
switch(name)
{
case PROGRAM_WITH_LIGHT:
if(shader_programs[PROGRAM_WITH_LIGHT])
{
return shader_programs[PROGRAM_WITH_LIGHT];
}
else
{
QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer);
if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_with_light.v"))
{
std::cerr<<"adding vertex shader FAILED"<<std::endl;
}
if(!program->addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_with_light.f"))
{
std::cerr<<"adding fragment shader FAILED"<<std::endl;
}
program->link();
shader_programs[PROGRAM_WITH_LIGHT] = program;
return program;
}
break;
case PROGRAM_WITHOUT_LIGHT:
if( shader_programs[PROGRAM_WITHOUT_LIGHT])
{
return shader_programs[PROGRAM_WITHOUT_LIGHT];
}
else
{
QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer);
if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_without_light.v"))
{
std::cerr<<"adding vertex shader FAILED"<<std::endl;
}
if(!program->addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_without_light.f"))
{
std::cerr<<"adding fragment shader FAILED"<<std::endl;
}
program->link();
shader_programs[PROGRAM_WITHOUT_LIGHT] = program;
return program;
}
break;
case PROGRAM_WITH_TEXTURE:
if( shader_programs[PROGRAM_WITH_TEXTURE])
{
return shader_programs[PROGRAM_WITH_TEXTURE];
}
else
{
QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer);
if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_with_texture.v"))
{
std::cerr<<"adding vertex shader FAILED"<<std::endl;
}
if(!program->addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_with_texture.f"))
{
std::cerr<<"adding fragment shader FAILED"<<std::endl;
}
program->link();
shader_programs[PROGRAM_WITH_TEXTURE] = program;
return program;
}
break;
case PROGRAM_WITH_TEXTURED_EDGES:
if( shader_programs[PROGRAM_WITH_TEXTURED_EDGES])
{
return shader_programs[PROGRAM_WITH_TEXTURED_EDGES];
}
else
{
QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer);
if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_with_textured_edges.v" ))
{
std::cerr<<"adding vertex shader FAILED"<<std::endl;
}
if(!program->addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_with_textured_edges.f" ))
{
std::cerr<<"adding fragment shader FAILED"<<std::endl;
}
program->link();
shader_programs[PROGRAM_WITH_TEXTURED_EDGES] = program;
return program;
}
break;
case PROGRAM_INSTANCED:
if( shader_programs[PROGRAM_INSTANCED])
{
return shader_programs[PROGRAM_INSTANCED];
}
else
{
QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer);
if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_instanced.v" ))
//.........这里部分代码省略.........