本文整理汇总了C++中QOpenGLShaderProgram类的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLShaderProgram类的具体用法?C++ QOpenGLShaderProgram怎么用?C++ QOpenGLShaderProgram使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QOpenGLShaderProgram类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:
void
Scene_polylines_item_private::initializeBuffers(CGAL::Three::Viewer_interface *viewer = 0) const
{
float lineWidth[2];
viewer->glGetFloatv(GL_LINE_WIDTH_RANGE, lineWidth);
line_Slider->setMaximum(lineWidth[1]);
QOpenGLShaderProgram *program;
//vao for the lines
{
program = item->getShaderProgram(Scene_polylines_item::PROGRAM_NO_SELECTION, viewer);
program->bind();
item->vaos[Edges]->bind();
item->buffers[Edges_Vertices].bind();
item->buffers[Edges_Vertices].allocate(positions_lines.data(),
static_cast<int>(positions_lines.size()*sizeof(float)));
program->enableAttributeArray("vertex");
program->setAttributeBuffer("vertex",GL_FLOAT,0,4);
item->buffers[Edges_Vertices].release();
item->vaos[Edges]->release();
program->release();
nb_lines = positions_lines.size();
positions_lines.clear();
positions_lines.swap(positions_lines);
}
item->are_buffers_filled = true;
}
示例3: glEnable
void Painter::paint_3_2_label(
const QMatrix4x4 & viewProjection
, float timef)
{
QOpenGLShaderProgram * program;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glActiveTexture(GL_TEXTURE0);
program = m_programs[LabelDistanceMapProgram];
program->bind();
glBindTexture(GL_TEXTURE_2D, m_hpicgsLabelDM);
program->setUniformValue("mvp", viewProjection * m_transforms[0]);
m_hpicgsLabel->draw(*this);
glBindTexture(GL_TEXTURE_2D, m_portccLabelDM);
program->setUniformValue("mvp", viewProjection * m_transforms[1]);
m_portccLabel->draw(*this);
program->release();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_BLEND);
}
示例4: getShaderProgram
void
Scene_polylines_item::initializeBuffers(CGAL::Three::Viewer_interface *viewer = 0) const
{
QOpenGLShaderProgram *program;
//vao for the lines
{
program = getShaderProgram(PROGRAM_NO_SELECTION, viewer);
program->bind();
vaos[Edges]->bind();
buffers[Edges_Vertices].bind();
buffers[Edges_Vertices].allocate(positions_lines.data(),
static_cast<int>(positions_lines.size()*sizeof(float)));
program->enableAttributeArray("vertex");
program->setAttributeBuffer("vertex",GL_FLOAT,0,4);
buffers[Edges_Vertices].release();
vaos[Edges]->release();
program->release();
nb_lines = positions_lines.size();
positions_lines.clear();
positions_lines.swap(positions_lines);
}
are_buffers_filled = true;
}
示例5: setUniforms
void AbstractKernel::setUniforms(QOpenGLShaderProgram& program, unsigned int pass)
{
program.setUniformValue("size", m_size);
if(pass == Pass::Second)
{
program.setUniformValue("factor", m_factor);
}
}
示例6: program
void QQuickShapeConicalGradientShader::initialize()
{
QOpenGLShaderProgram *prog = program();
m_opacityLoc = prog->uniformLocation("opacity");
m_matrixLoc = prog->uniformLocation("matrix");
m_angleLoc = prog->uniformLocation("angle");
m_translationPointLoc = prog->uniformLocation("translationPoint");
}
示例7: exposeEvent
void exposeEvent(QExposeEvent *)
{
if (!isExposed())
return;
if (!gl) {
gl = new QOpenGLContext();
gl->setFormat(requestedFormat());
gl->create();
}
gl->makeCurrent(this);
QOpenGLShaderProgram prog;
prog.addShaderFromSourceCode(QOpenGLShader::Vertex,
"attribute highp vec4 a_Pos;"
"attribute lowp vec4 a_Color;"
"varying lowp vec4 v_Color;"
"void main() {"
" gl_Position = a_Pos;"
" v_Color = a_Color;"
"}");
prog.addShaderFromSourceCode(QOpenGLShader::Fragment,
"varying lowp vec4 v_Color;"
"void main() {"
" gl_FragColor = v_Color;"
"}");
prog.bind();
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, width(), height());
prog.enableAttributeArray("a_Pos");
prog.enableAttributeArray("a_Color");
float coords[] = { -0.7f, 0.7f,
0.8f, 0.8f,
-0.8f, -0.8f,
0.7f, -0.7f
};
float colors[] = { 1, 0, 0, 1,
0, 1, 0, 1,
0, 0, 1, 1,
0, 0, 0, 0
};
prog.setAttributeArray("a_Pos", GL_FLOAT, coords, 2, 0);
prog.setAttributeArray("a_Color", GL_FLOAT, colors, 4, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
prog.disableAttributeArray("a_Pos");
prog.disableAttributeArray("a_Color");
gl->swapBuffers(this);
}
示例8: QOpenGLShaderProgram
//! [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");
}
示例9: 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();
}
示例10: QOpenGLShaderProgram
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;
}
示例11: QOpenGLShaderProgram
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;
}
示例12: useShader
void useShader(QOpenGLShaderProgram& _s,
std::function<void(UniformHandler&)>f) {
withCurrentContext([&](QOpenGLFunctions& _gl) {
_s.bind();
{
UniformHandler _handler(_gl, _s);
f(_handler);
// Destructor of handler is called here implicitly
// by RAII to unbind all textures
}
_s.release();
});
}
示例13: 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);
}
示例14: OVITO_STATIC_ASSERT
/******************************************************************************
* Renders a 2d polyline in the viewport.
******************************************************************************/
void ViewportSceneRenderer::render2DPolyline(const Point2* points, int count, const ColorA& color, bool closed)
{
OVITO_STATIC_ASSERT(sizeof(points[0]) == 2*sizeof(GLfloat));
// Load OpenGL shader.
QOpenGLShaderProgram* shader = loadShaderProgram("line", ":/core/glsl/lines/line.vs", ":/core/glsl/lines/line.fs");
if(!shader->bind())
throw Exception(tr("Failed to bind OpenGL shader."));
bool wasDepthTestEnabled = glIsEnabled(GL_DEPTH_TEST);
glDisable(GL_DEPTH_TEST);
GLint vc[4];
glGetIntegerv(GL_VIEWPORT, vc);
QMatrix4x4 tm;
tm.ortho(vc[0], vc[0] + vc[2], vc[1] + vc[3], vc[1], -1, 1);
OVITO_CHECK_OPENGL(shader->setUniformValue("modelview_projection_matrix", tm));
QOpenGLBuffer vertexBuffer;
if(glformat().majorVersion() >= 3) {
if(!vertexBuffer.create())
throw Exception(tr("Failed to create OpenGL vertex buffer."));
if(!vertexBuffer.bind())
throw Exception(tr("Failed to bind OpenGL vertex buffer."));
vertexBuffer.allocate(points, 2 * sizeof(GLfloat) * count);
OVITO_CHECK_OPENGL(shader->enableAttributeArray("position"));
OVITO_CHECK_OPENGL(shader->setAttributeBuffer("position", GL_FLOAT, 0, 2));
vertexBuffer.release();
}
else {
OVITO_CHECK_OPENGL(glEnableClientState(GL_VERTEX_ARRAY));
OVITO_CHECK_OPENGL(glVertexPointer(2, GL_FLOAT, 0, points));
}
if(glformat().majorVersion() >= 3) {
OVITO_CHECK_OPENGL(shader->disableAttributeArray("color"));
OVITO_CHECK_OPENGL(shader->setAttributeValue("color", color.r(), color.g(), color.b(), color.a()));
}
else {
OVITO_CHECK_OPENGL(glColor4(color));
}
OVITO_CHECK_OPENGL(glDrawArrays(closed ? GL_LINE_LOOP : GL_LINE_STRIP, 0, count));
if(glformat().majorVersion() >= 3) {
shader->disableAttributeArray("position");
}
else {
OVITO_CHECK_OPENGL(glDisableClientState(GL_VERTEX_ARRAY));
}
shader->release();
if(wasDepthTestEnabled) glEnable(GL_DEPTH_TEST);
}
示例15: QOpenGLShaderProgram
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);
}