Thanks a lot for detailed explanation!
I rewrote my example to show OpenGL version on the window. I was build from one code base for Desktop, Redmi 4X, and Android Emulator:
Window 10:
[image: 51214084-7db1-406e-8928-6ff49d24a10b.png]
Android on the physical device Redmi 4X. The device is connected by USB. It is faster way to run and debug than to run on Emulator. I use scrcpy to show a screen of device on laptop:
[image: 4a55439a-7f7f-4b29-b44c-34cea11795ef.png]
Android Emulator:
[image: 67566240-5fcc-42a3-a174-434dfac4a000.png]
main.cpp
// #ifdef _WIN32
// #include <windows.h>
// extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
// extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
// #endif
#include <QtGui/QOpenGLFunctions>
#include <QtGui/QSurfaceFormat>
#include <QtOpenGLWidgets/QOpenGLWidget>
#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
class OpenGLWidget : public QOpenGLWidget, private QOpenGLFunctions
{
Q_OBJECT
signals:
void showInfoSignal(const QString &openGLVersion, const QString &shadingVersion, const QString &vendor);
private:
void initializeGL() override
{
initializeOpenGLFunctions();
glClearColor(0.f, 1.f, 0.f, 1.f);
QString version(QString("OpenGL version: %1").arg((const char*) glGetString(GL_VERSION)));
QString shadingLanguageVersion(QString("GLSL version: %1").arg((const char*) glGetString(GL_SHADING_LANGUAGE_VERSION)));
QString vendor(QString("Vendor: %1").arg((const char*) glGetString(GL_VENDOR)));
emit showInfoSignal(version, shadingLanguageVersion, vendor);
}
void paintGL() override
{
glClear(GL_COLOR_BUFFER_BIT);
}
};
class MainWindow : public QWidget
{
Q_OBJECT
public:
MainWindow()
{
setWindowTitle("OpenGL Version");
resize(300, 300);
m_openGLVersionLabel = new QLabel();
m_shadingLanguageVersionLabel = new QLabel();
m_vendorLabel = new QLabel();
OpenGLWidget *openGLWidget = new OpenGLWidget();
m_openGLVersionLabel->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
m_shadingLanguageVersionLabel->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
m_vendorLabel->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(m_openGLVersionLabel);
layout->addWidget(m_shadingLanguageVersionLabel);
layout->addWidget(m_vendorLabel);
layout->addWidget(openGLWidget);
setLayout(layout);
connect(openGLWidget, &OpenGLWidget::showInfoSignal, this, &MainWindow::showInfoSlot);
}
private slots:
void showInfoSlot(const QString &openGLVersion, const QString &shadingVersion, const QString &vendor)
{
m_openGLVersionLabel->setText(openGLVersion);
m_shadingLanguageVersionLabel->setText(shadingVersion);
m_vendorLabel->setText(vendor);
}
private:
QLabel *m_openGLVersionLabel;
QLabel *m_shadingLanguageVersionLabel;
QLabel *m_vendorLabel;
};
#include "main.moc"
int main(int argc, char *argv[])
{
// QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseDesktopOpenGL);
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
pro
QT += core gui openglwidgets widgets
win32: LIBS += -lopengl32
CONFIG += c++17
SOURCES += \
main.cpp
TARGET = app