QOpenGLTextureBlitter Class

The QOpenGLTextureBlitter class provides a convenient way to draw textured quads via OpenGL. More...

Header: #include <QOpenGLTextureBlitter>
qmake: QT += gui
Since: Qt 5.8

This class was introduced in Qt 5.8.

Public Types

enum Origin { OriginBottomLeft, OriginTopLeft }

Detailed Description

Drawing textured quads, in order to get the contents of a texture onto the screen, is a common operation when developing 2D user interfaces. QOpenGLTextureBlitter provides a convenience class to avoid repeating vertex data, shader sources, buffer and program management and matrix calculations.

For example, a QOpenGLWidget subclass can do the following to draw the contents rendered into a framebuffer at the pixel position (x, y):

 void OpenGLWidget::initializeGL()
 {
     m_blitter.create();
     m_fbo = new QOpenGLFramebufferObject(size);
 }

 void OpenGLWidget::paintGL()
 {
     m_fbo->bind();
     // update offscreen content
     m_fbo->release();

     m_blitter.bind();
     const QRect targetRect(QPoint(x, y), m_fbo->size());
     const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), m_fbo->size()));
     m_blitter.blit(m_fbo->texture(), target, QOpenGLTextureBlitter::OriginBottomLeft);
     m_blitter.release();
 }

The blitter implements GLSL shaders both for GLSL 1.00 (suitable for OpenGL (ES) 2.x and compatibility profiles of newer OpenGL versions) and version 150 (suitable for core profile contexts with OpenGL 3.2 and newer).

Member Type Documentation

enum QOpenGLTextureBlitter::Origin

ConstantValueDescription
QOpenGLTextureBlitter::OriginBottomLeft0Indicates that the data in the texture follows the OpenGL convention of coordinate systems, meaning Y is running from bottom to top.
QOpenGLTextureBlitter::OriginTopLeft1Indicates that the data in the texture has Y running from top to bottom, which is typical with regular, unflipped image data.

See also blit().