Couldn't render OpenGLES context in Qt

223 Views Asked by At

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);

}
0

There are 0 best solutions below