Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
None
-
5.2.0
-
None
-
Windows 7 64Bit
Nvidia Quadro K2000 (Driver 311.66)
Qt 5.2.0 msvc2012_64_opengl downloaded from qtproject.org
Description
When creating a QWindow that is to be rendered into using a QOpenGLContext with the format of the QOpenGLContext then the window may become transparent when rendering with alpha blending. A sample that can be used to reproduce the problem is included.
Running the following sample will create a window with a red background and a purplish translucent hole in the middle of it.
Please note that the window is created using the format of the context. If instead I would have used the original format that was used to create the context no problem would have occurred.
This sample works as expected with Qt 5.1.1 (No translucent hole - just regular alpha blending)
#include <QApplication> #include <QWindow> #include <QOpenGLContext> #include <QTimer> #include <QPointer> #include <QOpenGLFunctions_4_1_Compatibility> class CRenderTimer : public QTimer { QPointer<QOpenGLContext> ctx; QPointer<QWindow> wnd; QOpenGLFunctions_4_1_Compatibility *GL; public: CRenderTimer(QPointer<QOpenGLContext> context, QPointer<QWindow> window) : QTimer(), ctx(context), wnd(window) { if(ctx->makeCurrent(wnd)) { GL = ctx->versionFunctions<QOpenGLFunctions_4_1_Compatibility>(); GL->initializeOpenGLFunctions(); GL->glDisable(GL_DEPTH_TEST); GL->glEnable(GL_BLEND); GL->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GL->glClearColor(1,1,1,1); ctx->doneCurrent(); } } ~CRenderTimer() { } protected: void timerEvent(QTimerEvent *) { if(ctx->makeCurrent(wnd)) { GL->glDrawBuffer(GL_BACK); GL->glClear(GL_COLOR_BUFFER_BIT); GL->glViewport(0,0,wnd->width(), wnd->height()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //GL->glOrtho(0,wnd->width(), 0, wnd->height(), -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glBegin(GL_QUADS); glColor4f(1,0,0,1); glVertex3i (-1, -1, -1); glVertex3i (1, -1, -1); glVertex3i (1, 1, -1); glVertex3i (-1, 1, -1); glColor4f(0,0,1,0.5); glVertex3f (-0.5, -0.5, -1); glVertex3f (0.5, -0.5, -1); glVertex3f (0.5, 0.5, -1); glVertex3f (-0.5, 0.5, -1); glEnd(); //ctx->doneCurrent(); ctx->swapBuffers(wnd); } } }; int main(int argc, char *argv[]) { QApplication a(argc, argv); QSurfaceFormat glFormat; glFormat.setVersion(4,1); glFormat.setProfile(QSurfaceFormat::CompatibilityProfile); QPointer<QOpenGLContext> context(new QOpenGLContext()); context->setFormat(glFormat); context->create(); QPointer<QWindow> wnd(new QWindow); wnd->setFormat(context->format());//Calling wnd->setFormat(glFormat) will solve the issue wnd->setSurfaceType(QSurface::OpenGLSurface); wnd->create(); wnd->show(); CRenderTimer * renderTimer = new CRenderTimer(context, wnd); renderTimer->setInterval(20); renderTimer->start(); return a.exec(); }
Attachments
Issue Links
- is replaced by
-
QTBUG-33919 Windows/Desktop OpenGL: QGLWidget has transparent background instead of a full opaque one as in 5.1.1 if configured with QGL::AlphaChannel
- Closed
- resulted from
-
QTBUG-28214 Cannot make transparent (translucent) background for QQuickView
- Closed