void NightModeGraphicsEffect::draw(QPainter* painter) { int pixelRatio = painter->device()->devicePixelRatio(); QSize size(painter->device()->width() * pixelRatio, painter->device()->height() * pixelRatio); if (fbo && fbo->size() != size) { delete fbo; fbo = NULL; } if (!fbo) { QGLFramebufferObjectFormat format; format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); format.setInternalTextureFormat(GL_RGBA); fbo = new NightModeGraphicsEffectFbo(size, format, pixelRatio); } QPainter fboPainter(fbo); drawSource(&fboPainter); painter->save(); painter->beginNativePainting(); program->bind(); const GLfloat pos[] = {-1, -1, +1, -1, -1, +1, +1, +1}; const GLfloat texCoord[] = {0, 0, 1, 0, 0, 1, 1, 1}; program->setUniformValue(vars.source, 0); program->setAttributeArray(vars.pos, pos, 2); program->setAttributeArray(vars.texCoord, texCoord, 2); program->enableAttributeArray(vars.pos); program->enableAttributeArray(vars.texCoord); glBindTexture(GL_TEXTURE_2D, fbo->texture()); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); program->release(); painter->endNativePainting(); painter->restore(); }
void VideoView::paintGL(QGLPainter *painter) { QGLFramebufferObject *fbo = fboSurface->framebufferObject(); if (fbo) { painter->setStandardEffect(QGL::FlatReplaceTexture2D); painter->setTexture(QGLTexture2D::fromTextureId(fbo->texture(), fbo->size())); } else { painter->setStandardEffect(QGL::LitMaterial); } teapot.draw(painter); }
Selection* Sketcher::createSelection(int width, int height) { Selection *selection = new Selection(); //selection->setParameters(parameters, parameterNames); QGLFramebufferObject *fbo = new QGLFramebufferObject(width, height); glBindTexture(GL_TEXTURE_2D, fbo->texture()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); selection->setSelectionMask(fbo); this->selections << selection; return selection; }
// -------------------------------------------------------- void TouchWidgetRenderer::drawMagnifyingGlass( GLResourceContainer * container, const MagnifyingGlass * mg, float alpha ) const { // draw contents to fbo QGLFramebufferObject * fbo = container->framebufferObject("mg_fbo"); drawSceneToFbo(fbo, mg->srcCenter(), mg->srcSize(), mg->angle()); //qDebug() << "drawing mg " << mg << mg->dstCenter() << mg->dstSize(); // draw magnifying glass including contents QGLShaderProgram * shader = container->shaderProgram("mglass"); shader->bind(); shader->setUniformValue("mglass_tex", 0); shader->setUniformValue("content_tex", 1); shader->setUniformValue("alpha", this->alpha()*alpha); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, container->texture("mglass")); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, fbo->texture()); drawQuad(mg->dstCenter(), mg->dstSize(), -mg->angle(), this->alpha()*alpha); shader->release(); }
void paintGL() { const SbViewportRegion vp = view->getSoRenderManager()->getViewportRegion(); SbVec2s size = vp.getViewportSizePixels(); glDisable(GL_LIGHTING); glViewport(0, 0, size[0], size[1]); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, fbObject->texture()); glColor3f(1.0, 1.0, 1.0); GLfloat s = size[0] / GLfloat(fbObject->size().width()); GLfloat t = size[1] / GLfloat(fbObject->size().height()); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, -1.0); glTexCoord2f(s, 0.0); glVertex2f(1.0, -1.0); glTexCoord2f(s, t); glVertex2f(1.0, 1.0); glTexCoord2f(0.0, t); glVertex2f(-1.0, 1.0); glEnd(); if (rubberBandIsShown) { glMatrixMode(GL_PROJECTION); glOrtho(0, size[0], size[1], 0, 0, 100); glMatrixMode(GL_MODELVIEW); glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glLineWidth(4.0); glColor4f(1.0f, 1.0f, 1.0f, 0.2f); glRecti(rubberBandCorner1.x(), rubberBandCorner1.y(), rubberBandCorner2.x(), rubberBandCorner2.y()); glColor4f(1.0, 1.0, 0.0, 0.5); glLineStipple(3, 0xAAAA); glEnable(GL_LINE_STIPPLE); glBegin(GL_LINE_LOOP); glVertex2i(rubberBandCorner1.x(), rubberBandCorner1.y()); glVertex2i(rubberBandCorner2.x(), rubberBandCorner1.y()); glVertex2i(rubberBandCorner2.x(), rubberBandCorner2.y()); glVertex2i(rubberBandCorner1.x(), rubberBandCorner2.y()); glEnd(); glLineWidth(1.0); glDisable(GL_LINE_STIPPLE); glDisable(GL_BLEND); } glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); }