[Interest] QGLWidget::drawTexture transparency woes

Matthew Woehlke mw_triad at users.sourceforge.net
Tue May 12 18:18:50 CEST 2015


I'm trying to use QGLWidget::drawTexture to draw a texture with an alpha
channel, but it is not working; the areas that should be transparent are
instead black, as if the alpha channel is missing in the GL texture.

Here's a quick sketch of what I am doing:

  MyWidget::initializeGL()
  {
    d->tex = bindTexture(QImage{":/images/texture"});
    glEnable(GL_TEXTURE_2D);
  }

  MyWidget::paintGL()
  {
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    drawTexture(QRectF{128, 128, 128, 128}, d->tex);
  }

If I inspect the loaded QImage::format(), it is ARGB, as expected. (I've
also tried with QOpenGLTexture instead of QGLWidget::bindTexture, with
the same results. This does, however, let me confirm that the GL texture
format is GL_RGBA8, again as expected.) Inspecting the image file in an
external editor or Designer, the alpha channel is as expected.

Am I missing something?

-- 
Matthew




More information about the Interest mailing list