Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
5.4.2
-
None
-
MacOS X 10.10.3
MacBookPro retina 750M
Description
I have an example here when I call setSamples of QSurfaceFormat, the refresh of the QOpenGLWidget is not correct anymore.
This simple example displays a rectangle when the users holds on the A key of the keyboard. It goes away if the user releases the key. This behaviour is the expected behaviour but when a value is set for QSurfaceFormat the behaviour is the exact opposite
#include <QApplication> #include <QSurfaceFormat> #include <QOpenGLWidget> #include <QOpenGLFunctions> #include <QKeyEvent> #include <QtDebug> /** * @brief The MyOpenGLWidget class * Simple example to show that there is a bug with QOpenGLWidget and multisample * When the user hits A it displays a rectangle until the key is released * If no sample value is set to QSurfaceFormat, it works properly * If a value is set the behaviour is changed. * When the key is released it displays the rectangle and the rectangle is hidden when the key is pressed */ class MyOpenGLWidget : public QOpenGLWidget, public QOpenGLFunctions { public: MyOpenGLWidget(QWidget *parent) : QOpenGLWidget(parent){ setMouseTracking(true); setFocusPolicy(Qt::StrongFocus); setAutoFillBackground(false); } ~MyOpenGLWidget(){ } void resizeGL(int, int){ } void paintGL(){ glClearColor(0.5, 0.5, 0.5, 1.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, width(), 0, height(), -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (m_draw){ glColor3f(0, 1, 0); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(200, 200); glTexCoord2f(1, 0); glVertex2f(width()-200, 200); glTexCoord2f(1, 1); glVertex2f(width()-200, height()-200); glTexCoord2f(0, 1); glVertex2f(200, height() - 200); glEnd(); } } void initializeGL(){ initializeOpenGLFunctions(); } void keyReleaseEvent(QKeyEvent* e){ if (e->key() == Qt::Key_A){ m_draw = false; update(); } } void keyPressEvent(QKeyEvent* e){ if (e->isAutoRepeat()) return ; if (e->key() == Qt::Key_A){ m_draw = true; update(); } } protected: bool m_draw; }; int main(int argc, char *argv[]) { QApplication a(argc, argv); QSurfaceFormat format; format.setVersion(2, 0); format.setProfile(QSurfaceFormat::NoProfile); format.setDepthBufferSize(24); format.setSamples(2); // <----- Bug here if we activate this line format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); QSurfaceFormat::setDefaultFormat(format); MyOpenGLWidget w(0); w.showMaximized(); return a.exec(); }
Attachments
Issue Links
- duplicates
-
QTBUG-39917 Multisampled QQuickWidget flickers filled with garbage when resizing on OS X
- Closed