1

I am trying to use OpenGLES in a desktop platform. I have a class whose name is GraphicsViewer which is derived from QOpenGLWidget. When I set the QSurfaceFormat::renderableType to QSurfaceFormat::OpenGLES, I get the following errors and nothing is drawn on the widget. Can you help me to create an OpenGLES context in a desktop platform? My OS is Windows 10 and my Qt version is 5.12.3.

Errors:

QOpenGLWidget: Failed to create context
QOpenGLWidget: Failed to create context
qt.qpa.backingstore: composeAndFlush: QOpenGLContext creation failed
QOpenGLWidget: Failed to create context
qt.qpa.backingstore: composeAndFlush: makeCurrent() failed
qt.qpa.backingstore: composeAndFlush: makeCurrent() failed

Here is my codes...

main.cpp

#include "QtOpenGLES.h"
#include <QApplication>
#include <QSurfaceFormat>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QSurfaceFormat f;
    f.setVersion(2, 0);
    f.setRenderableType(QSurfaceFormat::OpenGLES);

    QSurfaceFormat::setDefaultFormat(f);

    QtOpenGLES w;
    w.show();

    return a.exec();
}

QtOpenGLES.h

#ifndef QTOPENGLES_H
#define QTOPENGLES_H

#include <QMainWindow>

namespace Ui {
class QtOpenGLES;
}

class QtOpenGLES : public QMainWindow
{
    Q_OBJECT

public:
    explicit QtOpenGLES(QWidget *parent = nullptr);
    ~QtOpenGLES();

private:
    Ui::QtOpenGLES *ui;
};

#endif // QTOPENGLES_H

QtOpenGLES.cpp

#include "QtOpenGLES.h"
#include "ui_QtOpenGLES.h"

QtOpenGLES::QtOpenGLES(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::QtOpenGLES)
{
    ui->setupUi(this);
}

QtOpenGLES::~QtOpenGLES()
{
    delete ui;
}

GraphicsViewer.h

#ifndef GRAPHICSVIEWER_H
#define GRAPHICSVIEWER_H

#include <QOpenGLWidget>
#include <QOpenGLFunctions>

class GraphicsViewer : public QOpenGLWidget, protected QOpenGLFunctions
{
    Q_OBJECT

public:
    GraphicsViewer(QWidget* parent = nullptr);

// QOpenGLWidget interface
protected:
    void initializeGL();
    void paintGL();
};

GraphicsViewer.cpp

#include "GraphicsViewer.h"

#include <QtOpenGL>


GraphicsViewer::GraphicsViewer(QWidget *parent) :
    QOpenGLWidget (parent)
{

}

void GraphicsViewer::initializeGL()
{
    initializeOpenGLFunctions();
}

void GraphicsViewer::paintGL()
{
    glClearColor(1, 0, 0, 1);

}
iammetehan
  • 11
  • 3
  • Note that the code shown never actually creates an instance of `GraphicsViewer`. Does your computer definitely support OpenGL ES2.0? You might also want to try putting the call `QSurfaceFormat::setDefaultFormat(f);` *before* `QApplication a(argc, argv);` as per the note [here](https://doc.qt.io/qt-6/qsurfaceformat.html#setDefaultFormat). – G.M. Aug 12 '22 at 07:50
  • Instance of GraphicsViewer is created in UI. Yes, I can create an OpenGL ES2.0 context using GLFW. I tried adding QSurfaceFormat::setDefaultFormat(f) before QApplication a(argc, argv) but it didn't work too. – iammetehan Aug 12 '22 at 11:37

0 Answers0