当前位置: 首页>>代码示例>>C++>>正文


C++ QOpenGLShaderProgram::addShaderFromSourceFile方法代码示例

本文整理汇总了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;
}
开发者ID:chocoball,项目名称:AnimationCreator,代码行数:27,代码来源:glwidget.cpp

示例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);
}
开发者ID:chipgw,项目名称:depthview2,代码行数:27,代码来源:dvwindow.cpp

示例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;
  }
}
开发者ID:myluoxz,项目名称:cgal,代码行数:47,代码来源:Viewer.cpp

示例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;
}
开发者ID:samuelohterion,项目名称:SehenMitAndererAugen_ViewingWithOthersEyes,代码行数:42,代码来源:glview.cpp

示例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" ))
//.........这里部分代码省略.........
开发者ID:Huanglihan,项目名称:cgal,代码行数:101,代码来源:Scene_item.cpp


注:本文中的QOpenGLShaderProgram::addShaderFromSourceFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。