本文整理汇总了C++中QOpenGLShaderProgram::link方法的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLShaderProgram::link方法的具体用法?C++ QOpenGLShaderProgram::link怎么用?C++ QOpenGLShaderProgram::link使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QOpenGLShaderProgram
的用法示例。
在下文中一共展示了QOpenGLShaderProgram::link方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: load
void load() {
shader.addShaderFromSourceCode(QOpenGLShader::Vertex,
shaderWithHeader(":/shaders/mvp.vert"));
shader.addShaderFromSourceCode(QOpenGLShader::Fragment,
shaderWithHeader(":/shaders/flat.frag"));
shader.link();
cube.load(shader);
}
示例4: initialize
//! [4]
void TriangleWindow::initialize()
{
m_program = new QOpenGLShaderProgram(this);
m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
m_program->link();
m_posAttr = m_program->attributeLocation("posAttr");
m_colAttr = m_program->attributeLocation("colAttr");
m_matrixUniform = m_program->uniformLocation("matrix");
}
示例5: initShader
void initShader(QOpenGLShaderProgram& _s, const char *_filename) {
QString _vertSrc =
ShaderCompiler::compile(":/shaders/" + QString(_filename) + ".vert");
QString _fragmentSrc =
ShaderCompiler::compile(":/shaders/" + QString(_filename) + ".frag");
_s.addShaderFromSourceCode(QOpenGLShader::Vertex,
_vertSrc);
_s.addShaderFromSourceCode(QOpenGLShader::Fragment,
_fragmentSrc);
_s.link();
}
示例6: createBasicShaderProgram
QOpenGLShaderProgram* Painter::createBasicShaderProgram(const QString &vertexShaderFileName, const QString &fragmentShaderFileName)
{
QOpenGLShaderProgram * program = new QOpenGLShaderProgram();
m_shaders << FileAssociatedShader::getOrCreate(
QOpenGLShader::Vertex, vertexShaderFileName, *program);
m_shaders << FileAssociatedShader::getOrCreate(
QOpenGLShader::Fragment, fragmentShaderFileName, *program);
program->bindAttributeLocation("position", 0);
program->link();
return program;
}
示例7: createBasicShaderProgram
QOpenGLShaderProgram* AbstractPainter::createBasicShaderProgram(const QString &vertexShaderFileName, const QString &fragmentShaderFileName)
{
QOpenGLShaderProgram * program = new QOpenGLShaderProgram();
program->create();
m_shaders << FileAssociatedShader::getOrCreate(
QOpenGLShader::Vertex, vertexShaderFileName, *program);
m_shaders << FileAssociatedShader::getOrCreate(
QOpenGLShader::Fragment, fragmentShaderFileName, *program);
program->link();
return program;
}
示例8: 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;
}
}
示例9: loadShader
void LightSources::loadShader()
{
// Standardshader
QOpenGLShaderProgram* standardShaderProg = new QOpenGLShaderProgram();
QOpenGLShader vertShader(QOpenGLShader::Vertex);
vertShader.compileSourceFile(":/shader/lightsource.vert");
standardShaderProg->addShader(&vertShader);
QOpenGLShader fragShader(QOpenGLShader::Fragment);
fragShader.compileSourceFile(":/shader/lightsource.frag");
standardShaderProg->addShader(&fragShader);
standardShaderProg->link();
// Sonnenshader
this->shaderProgram = standardShaderProg;
glEnable(GL_TEXTURE_2D);
}
示例10:
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;
}
示例11: QOpenGLShaderProgram
QOpenGLShaderProgram *generateShaderProgram(QObject *parent, QByteArray vsrc, QByteArray fsrc)
{
QOpenGLShaderProgram *program = new QOpenGLShaderProgram(parent);
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, program);
vshader->compileSourceCode(vsrc);
if (!vshader->compileSourceCode(vsrc))
qFatal("Error in vertex src:\n%s\n", vsrc.constData());
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, program);
if (!fshader->compileSourceCode(fsrc))
qFatal("Error in fragment src:\n%s\n", fsrc.constData());
program->addShader(vshader);
program->addShader(fshader);
if (!program->link())
qFatal("Error linking:\n%s\n%s\n", vsrc.constData(), fsrc.constData());
return program;
}
示例12: buildPassthorughProgram
// Build a passthrough glsl program
QOpenGLShaderProgram* GLImageProcessor::buildPassthorughProgram() const
{
QOpenGLShaderProgram* prog = new QOpenGLShaderProgram();
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, prog);
const char *vsrc =
"attribute highp vec4 in_Vertex;\n"
"attribute mediump vec4 in_TexCoord;\n"
"varying mediump vec4 texCoord;\n"
"void main(void)\n"
"{\n"
" gl_Position = in_Vertex;\n"
" texCoord = in_TexCoord;\n"
"}\n";
vshader->compileSourceCode(vsrc);
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, prog);
const char *fsrc =
"uniform sampler2D in_Texture;\n"
"varying mediump vec4 texCoord;\n"
"void main(void)\n"
"{\n"
" gl_FragColor = texture2D(in_Texture, texCoord.st);\n"
"}\n";
fshader->compileSourceCode(fsrc);
prog->addShader(vshader);
prog->addShader(fshader);
prog->bindAttributeLocation("in_Vertex", 0);
prog->bindAttributeLocation("in_TexCoord", 1);
prog->link();
prog->bind();
prog->setUniformValue("in_Texture", 0);
prog->release();
return prog;
}
示例13: 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" ))
//.........这里部分代码省略.........
示例14: initialize
bool Painter::initialize()
{
initializeOpenGLFunctions();
// Note: As always, feel free to change/modify parameters .. as long as its possible to
// see the terrain and navigation basically works, everything is ok.
glClearColor(1.f, 1.f, 1.f, 0.f);
m_quad = new ScreenAlignedQuad(*this);
m_light = QVector3D(2.f, 3.f, 2.f);
QOpenGLShaderProgram * program;
// setup default assimp scene shader (rendering the meshes...)
// ToDo: If you render your own scene (e.g., a terrain, keep in mind
// to extend your shaders for supporting shadowmaps as well as in assimp shaders...
program = createBasicShaderProgram("data/assimp.vert", "data/assimp.frag");
m_programs[PaintMode1] = program;
program->bindAttributeLocation("a_vertex", 0);
program->bindAttributeLocation("a_normal", 1);
program->bindAttributeLocation("a_texc", 2);
program->link();
// load labeling shaders and resources
m_programs[LabelAlphaMappingProgram] = createBasicShaderProgram("data/label.vert", "data/labelAM.frag");
m_programs[LabelDistanceMapProgram] = createBasicShaderProgram("data/label.vert", "data/labelDM.frag");
m_hpicgsLabelAM = FileAssociatedTexture::getOrCreate2D("data/hpicgs_label.png", *this);
m_portccLabelAM = FileAssociatedTexture::getOrCreate2D("data/companion_cube_label.png", *this);
// load and position 3d models in the scene
// Note: feel free to modify / add / remove here... there should be at least
// a few scene objects visible ;)
m_hpicgs = new AssimpScene(*this, "data/hpicgs.obj", true);
m_hpicgs->transform().scale(0.7f, 0.7f, 0.7f);
m_hpicgs->transform().translate(-0.9f, 0.8f, -0.3f);
m_hpicgs->transform().rotate( 56.0f, 0.f, 1.0f, 0.f);
m_hpicgs->transform().rotate(0.0f, 1.f, 0.0f, 0.f);
m_plane = new AssimpScene(*this, "data/plane.obj", false);
m_plane->transform().translate(0.f, -0.1f, 0.f);
m_portcc = new AssimpScene(*this, "data/companion_cube.obj", true);
m_portcc->transform().scale(0.5f, 0.5f, 0.5f);
m_portcc->transform().translate(1.1f, 0.73f, 1.2f);
m_portcc->transform().rotate(8.0f, 0.f, 1.0f, 0.f);
// initialize label positions
// Task_3_1 - ToDo Begin
// Modify the transformation matrix T to position, scale, and orient
// the labels to appropriate places, based on the initial view! No
// interaction should be required to be able to see both labels.
m_hpicgsLabel = new ScreenAlignedQuad(*this, 0);
QMatrix4x4 T;
T.translate(0.5, 0.5, -1.0);
T.scale(1.0, 0.3);
// ToDo: use T.translate/scale/rotate ...
m_transforms << T;
m_portccLabel = new ScreenAlignedQuad(*this, 0);
T.translate(-1.5, 0.0, 2.0);
// ToDo: use T.translate/scale/rotate ...
m_transforms << T;
// Task_3_1 - ToDo End
// initialize shader program attribute input
program = m_programs[LabelAlphaMappingProgram];
program->bind();
program->bindAttributeLocation("a_vertex", 0);
program->release();
program = m_programs[LabelDistanceMapProgram];
program->bind();
program->bindAttributeLocation("a_vertex", 0);
program->release();
// create distance transforms of label images
glGenTextures(1, &m_hpicgsLabelDM);
glBindTexture(GL_TEXTURE_2D, m_hpicgsLabelDM);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
{
QImage image("data/hpicgs_label_bitmask.png");
//.........这里部分代码省略.........