Fix most important issues issues with using QOpenGLWidget

* Fix constructing QColor when rendering text
* Port code using QGLFormat to use QSurfaceFormat
This commit is contained in:
Martchus 2022-12-20 18:15:47 +01:00 committed by Fabien Givors
parent 25caf8306f
commit 11101bbe91
2 changed files with 8 additions and 12 deletions

View File

@ -435,20 +435,19 @@ void CGLView::mediaTimerEvent(int ticks)
void CGLView::renderText(double x, double y, double z, const QString &str, const QFont & font = QFont()) {
// Identify x and y locations to render text within widget
int height = this->height();
GLdouble textPosX = 0, textPosY = 0, textPosZ = 0;
GLdouble textPosX = 0, textPosY = 0; //, textPosZ = 0;
//project(x, y, 0f, &textPosX, &textPosX, &textPosZ);
textPosX = x;
textPosY = y;
textPosY = height - textPosY; // y is inverted
// Retrieve last OpenGL color to use as a font color
GLdouble glColor[4];
glGetDoublev(GL_CURRENT_COLOR, glColor);
QColor fontColor = Qt::white;// QColor(glColor[0], glColor[1], glColor[2], glColor[3]);
GLfloat glColor[4];
glGetFloatv(GL_CURRENT_COLOR, glColor);
// Render text
QPainter painter(this);
painter.setPen(fontColor);
painter.setPen(QColor::fromRgbF(glColor[0], glColor[1], glColor[2], glColor[3]));
painter.setFont(font);
painter.drawText(textPosX, textPosY, str);
painter.end();

View File

@ -28,6 +28,8 @@
#include "QtWindow.h"
#include "version.h"
#include <QSurfaceFormat>
#ifdef __linux__
#ifndef USE_REALTIME_PRIORITY
#define USE_REALTIME_PRIORITY 0
@ -62,16 +64,13 @@ QtWindow::QtWindow()
decodeCommandLine();
/*
QGLFormat fmt = QGLFormat::defaultFormat();
auto fmt = QSurfaceFormat::defaultFormat();
if (Cfg::experimentalSwapInterval != -1)
{
fmt.setSwapInterval(Cfg::experimentalSwapInterval);
int value = fmt.swapInterval();
ppLogInfo("Open GL Swap Interval %d", value);
}
*/
for (int i = 0; i < MAX_RECENT_FILES; ++i)
m_recentFileActs[i] = nullptr;
@ -82,14 +81,12 @@ QtWindow::QtWindow()
set_realtime_priority(SCHED_FIFO, rt_prio);
#endif
/*
QString antiAliasingSetting = m_settings->value("anti-aliasing").toString();
if (antiAliasingSetting.isEmpty() || antiAliasingSetting=="on"){
fmt.setSamples(4);
}
QGLFormat::setDefaultFormat(fmt);
*/
QSurfaceFormat::setDefaultFormat(fmt);
m_glWidget = new CGLView(this, m_settings);
m_glWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);