PDA

View Full Version : QOpenGLWindow with 16 bit QSurfaceFormat is brighter that should be on primary displa



zorro5101
7th June 2017, 19:41
I have two displays and want to write a program in Qt 5.5 that should do the next:

on start: run main program window (MyMainWindow) on secondary display with button.
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:

the My16BitWindow is running in the fullscreen mode
the My16BitWindow is running on the primary display
the My16BitWindow is running with the specified in its constructor 16 bit QSurfaceFormat.
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::DoubleBuf fer);
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
}