QOpenGLWindow with 16 bit QSurfaceFormat is brighter that should be on primary display



  • I have two displays and want to write a program in Qt 5.5 that should do the next:

    1. on start: run main program window (MyMainWindow) on secondary display with button.
    2. on that button press: run second window (My16BitWindow) on the primary display (specified in the NVIDIA Control Panel as primary) in fullscreen mode. This window should have pixel format with 16 bits for all color channels: red, green, blue and alpha.

    I wrote such minimal program and its code is given below. But this program has the next problem that I cannot solve by myself.
    If I start the program and click on the button, then My16BitWindow starts and picture in this window is brighter that should be. If then I click on the MyMainWindow title, then the picture brighness becomes normal. If then I click again on the My16BitWindow, it may or may not become brighter again. And if I continue click on different windows including MyMainWindow and My16BitWindow, then sometimes My16BitWindow becomes brighter or becomes normal.

    The problem occurs only under all the following conditions:

    1. the My16BitWindow is running in the fullscreen mode
    2. the My16BitWindow is running on the primary display
    3. the My16BitWindow is running with the specified in its constructor 16 bit QSurfaceFormat.
    4. in the end of My16BitWindow::paintGL code 'update' method is always requested
      All of these conditions are essential and important for me.

    What I'm doing wrong?
    I compile this using Visual Studio 2010 compiler and QT Add-in extension for Visual studio.

    main.cpp

    #include "MyMainWindow.h"
    #include <QtWidgets/QApplication>
    
    int main(int argc, char *argv[])
    {
      QApplication a(argc, argv);
      MyMainWindow w;
      w.show();
      return a.exec();
    }
    

    MyMainWindow.h

    #pragma once
    #include <QtWidgets/QMainWindow>
    
    class MyMainWindow : public QMainWindow
    {
      Q_OBJECT;
    public:
      MyMainWindow(QWidget *parent = 0);
    
    private slots:
      void onFullScreen();
    };
    

    MyMainWindow.cpp

    #include "MyMainWindow.h"
    #include "My16bitWindow.h"
    #include <QPushButton>
    #include <QDesktopWidget>
    #include <QApplication>
    
    MyMainWindow::MyMainWindow(QWidget *parent) : QMainWindow(parent)
    {
      QPushButton* pButton = new QPushButton("Fullscreen");
      setCentralWidget(pButton);
      QObject::connect(pButton, SIGNAL(released()), this, SLOT(onFullScreen()));
    }
    
    void MyMainWindow::onFullScreen()
    {
      int iScreen = 0; // primary display number
      QRect rect = qApp->desktop()->screenGeometry(iScreen);
    
      My16BitWindow* pWindow = new My16BitWindow;
      pWindow->setGeometry(rect);
      pWindow->setScreen(qApp->screens().at(iScreen));
      pWindow->show();
      pWindow->showFullScreen();
    }
    

    My16bitWindow.h

    #pragma once
    #include <QOpenGLWindow>
    
    class My16BitWindow : public QOpenGLWindow
    {
      Q_OBJECT;
    public:
    
      My16BitWindow();
    
      void initializeGL() override;
      void paintGL() override;
    };
    

    My16bitWindow.cpp

    #include "My16bitWindow.h"
    #include <QOpenGLFunctions>
    
    My16BitWindow::My16BitWindow() : QOpenGLWindow()
    {
      int bits = 16;
      QSurfaceFormat glFormat;
      glFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
      glFormat.setRedBufferSize(bits);
      glFormat.setBlueBufferSize(bits);
      glFormat.setGreenBufferSize(bits);
      glFormat.setAlphaBufferSize(bits);
      setFormat(glFormat);
    }
    
    void My16BitWindow::initializeGL()
    {
      QOpenGLFunctions* f = context()->functions();
      f->glClearColor(0.5, 0.0, 0.0, 1.0);
    }
    
    void My16BitWindow::paintGL()
    {
      QOpenGLFunctions* f = context()->functions();
      f->glClear(GL_COLOR_BUFFER_BIT);
    
      requestUpdate(); // Schedule an update
    }
    

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Any reason to stay with such an old version of Qt ? The current is 5.9, you should check with it if you still experience the same behaviour.



  • Thank you for you answer, SGaist!
    I've just tried qt 5.9 with the v140 Visual Studio compiler, it still does not work properly.


  • Lifetime Qt Champion

    Which backend are you using ? Desktop OpenGL or ANGLE ?



  • I use Desktop OpenGL. My environment: Windows 10 build 14393 (RS1 Anniversary Update), GeForce GTX980 and last Geforce driver for it (382.33).
    Now I think that is not an QOpenGLWindow problem , because I have the same problem if I create a window and its context using WinAPI directly.


  • Lifetime Qt Champion

    Then there might be something going on with the driver.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.