Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QOpenGLWindow with 16 bit QSurfaceFormat is brighter that should be on primary display
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zorro5101
    wrote on last edited by zorro5101
    #1

    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
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zorro5101
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        1
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Which backend are you using ? Desktop OpenGL or ANGLE ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • Z Offline
            Z Offline
            zorro5101
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Then there might be something going on with the driver.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved