本文整理汇总了C++中QOpenGLShader::compileSourceFile方法的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLShader::compileSourceFile方法的具体用法?C++ QOpenGLShader::compileSourceFile怎么用?C++ QOpenGLShader::compileSourceFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QOpenGLShader
的用法示例。
在下文中一共展示了QOpenGLShader::compileSourceFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: carregaShaders
void MyGLWidget::carregaShaders()
{
// Creem els shaders per al fragment shader i el vertex shader
QOpenGLShader fs (QOpenGLShader::Fragment, this);
QOpenGLShader vs (QOpenGLShader::Vertex, this);
// Carreguem el codi dels fitxers i els compilem
fs.compileSourceFile("shaders/fragshad.frag");
vs.compileSourceFile("shaders/vertshad.vert");
// Creem el program
program = new QOpenGLShaderProgram(this);
// Li afegim els shaders corresponents
program->addShader(&fs);
program->addShader(&vs);
// Linkem el program
program->link();
// Indiquem que aquest és el program que volem usar
program->bind();
// Obtenim identificador per a l'atribut “vertex” del vertex shader
vertexLoc = glGetAttribLocation (program->programId(), "vertex");
// Obtenim identificador per a l'atribut “normal” del vertex shader
normalLoc = glGetAttribLocation (program->programId(), "normal");
// Obtenim identificador per a l'atribut “matamb” del vertex shader
matambLoc = glGetAttribLocation (program->programId(), "matamb");
// Obtenim identificador per a l'atribut “matdiff” del vertex shader
matdiffLoc = glGetAttribLocation (program->programId(), "matdiff");
// Obtenim identificador per a l'atribut “matspec” del vertex shader
matspecLoc = glGetAttribLocation (program->programId(), "matspec");
// Obtenim identificador per a l'atribut “matshin” del vertex shader
matshinLoc = glGetAttribLocation (program->programId(), "matshin");
// Demanem identificadors per als uniforms del vertex shader
transLoc = glGetUniformLocation (program->programId(), "TG");
projLoc = glGetUniformLocation (program->programId(), "proj");
viewLoc = glGetUniformLocation (program->programId(), "view");
//COLOR
posFocus = glGetUniformLocation (program->programId(), "posFocus");
colFocus = glGetUniformLocation (program->programId(), "colFocus");
llumAmbient = glGetUniformLocation (program->programId(), "llumAmbient");
franges = glGetUniformLocation (program->programId(), "franges");
}
示例2: carregaShaders
void MyGLWidget::carregaShaders()
{
// Creem els shaders per al fragment shader i el vertex shader
QOpenGLShader fs (QOpenGLShader::Fragment, this);
QOpenGLShader vs (QOpenGLShader::Vertex, this);
// Carreguem el codi dels fitxers i els compilem
fs.compileSourceFile("shaders/fragshad.frag");
vs.compileSourceFile("shaders/vertshad.vert");
// Creem el program
program = new QOpenGLShaderProgram(this);
// Li afegim els shaders corresponents
program->addShader(&fs);
program->addShader(&vs);
// Linkem el program
program->link();
// Indiquem que aquest és el program que volem usar
program->bind();
// Obtenim identificador per a l'atribut “vertex” del vertex shader
vertexLoc = glGetAttribLocation (program->programId(), "vertex");
// Obtenim identificador per a l'atribut “color” del vertex shader
colorLoc = glGetAttribLocation (program->programId(), "color");
// Uniform locations
transLoc = glGetUniformLocation(program->programId(), "TG");
//Uniform projection
projLoc = glGetUniformLocation(program->programId(), "proj");
//Uniform view
viewLoc = glGetUniformLocation(program->programId(), "view");
glEnable(GL_DEPTH_TEST);
}
示例3: initializeGL
void GLWidget::initializeGL()
{
initializeOpenGLFunctions();
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
makeCurrent();
qglClearColor(QColor::fromCmykF(0.79, 0.79, 0.79, 0.0).dark());
glEnable(GL_DEPTH_TEST);
glEnable(GL_MULTISAMPLE);
glEnable(GL_DEPTH_TEST);
qDebug() << "Loading quad (vertex shader)";
QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
vshader->compileSourceFile(":/resources/plane.vert");
if (!vshader->log().isEmpty()) qDebug() << vshader->log();
else qDebug() << "done";
qDebug() << "Loading quad (fragment shader)";
QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
fshader->compileSourceFile(":/resources/plane.frag");
if (!fshader->log().isEmpty()) qDebug() << fshader->log();
else qDebug() << "done";
qDebug() << "Loading quad (tessellation control shader)";
QOpenGLShader *tcshader = new QOpenGLShader(QOpenGLShader::TessellationControl, this);
tcshader->compileSourceFile(":/resources/plane.tcs.vert");
if (!tcshader->log().isEmpty()) qDebug() << tcshader->log();
else qDebug() << "done";
qDebug() << "Loading quad (tessellation evaluation shader)";
QOpenGLShader *teshader = new QOpenGLShader(QOpenGLShader::TessellationEvaluation, this);
teshader->compileSourceFile(":/resources/plane.tes.vert");
if (!teshader->log().isEmpty()) qDebug() << teshader->log();
else qDebug() << "done";
qDebug() << "Loading quad (geometry shader)";
QOpenGLShader *gshader = new QOpenGLShader(QOpenGLShader::Geometry, this);
QFile gFile(":/resources/plane.geom");
gFile.open(QFile::ReadOnly);
qDebug() << gFile.isOpen() << " File";
QTextStream in(&gFile);
QString preambule = "#version 400 core\n"
"layout(triangle_strip, max_vertices = 3) out;\n" ;
QString shaderCode = in.readAll();
gshader->compileSourceCode(preambule+shaderCode);
//gshader->compileSourceFile(in.readAll());
if (!gshader->log().isEmpty()) qDebug() << gshader->log();
else qDebug() << "done";
program = new QOpenGLShaderProgram(this);
program->addShader(vshader);
program->addShader(fshader);
program->addShader(tcshader);
program->addShader(teshader);
program->addShader(gshader);
program->bindAttributeLocation("FragColor",0);
program->bindAttributeLocation("FragNormal",1);
program->bindAttributeLocation("FragGlowColor",2);
program->bindAttributeLocation("FragPosition",3);
GLCHK(program->link());
GLCHK(program->bind());
program->setUniformValue("texDiffuse" , 0);
program->setUniformValue("texNormal" , 1);
program->setUniformValue("texSpecular" , 2);
program->setUniformValue("texHeight" , 3);
program->setUniformValue("texSSAO" , 4);
program->setUniformValue("texRoughness", 5);
program->setUniformValue("texMetallic", 6);
program->setUniformValue("texMaterial", 7);
program->setUniformValue("texDiffuseEnvMap", 8);
program->setUniformValue("texEnvMap" , 9);
// lines shader
qDebug() << "Compiling lines program...";
preambule = QString("#version 400 core\n")+
"layout(line_strip, max_vertices = 3) out;\n" ;
gshader->compileSourceCode(preambule+shaderCode);
line_program = new QOpenGLShaderProgram(this);
line_program->addShader(vshader);
line_program->addShader(fshader);
line_program->addShader(tcshader);
line_program->addShader(teshader);
line_program->addShader(gshader);
line_program->bindAttributeLocation("FragColor",0);
line_program->bindAttributeLocation("FragNormal",1);
line_program->bindAttributeLocation("FragGlowColor",2);
line_program->bindAttributeLocation("FragPosition",3);
GLCHK(line_program->link());
GLCHK(line_program->bind());
line_program->setUniformValue("texDiffuse" , 0);
line_program->setUniformValue("texNormal" , 1);
line_program->setUniformValue("texSpecular" , 2);
line_program->setUniformValue("texHeight" , 3);
//.........这里部分代码省略.........