#include #include #include #include #include #include #include #include #include #include class MyGLWidget : public QOpenGLWidget, protected QOpenGLFunctions { public: MyGLWidget(QWidget *parent) : QOpenGLWidget(parent) { } protected: void initializeGL() { initializeOpenGLFunctions(); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); } void resizeGL(int w, int h) { glViewport(0, 0, w, h); } void paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); QPainter painter(this); painter.setPen(qRgb(0, 0, 0)); painter.drawText(this->rect(), "TEST", QTextOption(Qt::AlignCenter | Qt::AlignHCenter)); } }; int main(int argc, char **argv) { QApplication app(argc, argv); app.setAttribute(Qt::AA_ShareOpenGLContexts); // Do we need this? QWidget *widget = new QWidget; QHBoxLayout *hLayout = new QHBoxLayout(widget); //MyGLWidget *myGlWidget = new MyGLWidget(widget); // Showing text. Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow(); MyGLWidget *myGlWidget = new MyGLWidget(widget); // Not showing text. We need to create MyGLWidget at the runtime. QGLWidget works fine. view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f))); QWidget *container = QWidget::createWindowContainer(view); hLayout->addWidget(myGlWidget, 1); hLayout->addWidget(container, 2); widget->show(); widget->resize(1200, 800); return app.exec(); }