3

I am programming a VR app in Qt and need to show QWidget on the desktop and also inside VR.

So far I am rendering like this:

QOpenGLPaintDevice device(QSize(w12,h12));
QPainter painter(&device);


gl_functions->glBindFramebuffer(GL_FRAMEBUFFER, fbo);

//painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
gl_functions->glClearColor(0.0, 0.0, 0.0, 0.0);
gl_functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

//QPixmap pixmap(widget2->size());
//widget2->render(&pixmap);
//pixmap.save("pic.jpg");


widget2->render(&painter);

This is called from paintGL() of the main QOpenGLWidget.

In Vr this texture is used on a quad. So far only the text gets rendered. If QPixmap is used as device the widget renders fine.

My Widget is very complex with 4k lines of code for connnections between all spinboxes, labels, ...

Widget look

pazduha
  • 147
  • 3
  • 17
  • Are you sure that [`QPainter::end()`](http://doc.qt.io/qt-5/qpainter.html#end) has been called (either directly or via the `QPainter` dtor) *before* you use the result of the rendering? If not then the rendering may be incomplete. – G.M. Dec 12 '17 at 10:55
  • painter.end(); after widget2->render(&painter); same problem – pazduha Dec 12 '17 at 11:02

1 Answers1

1

I found solution, maybe not the best one.

Overlay needs its own context so in init:

overlayGLcontext = new QOpenGLContext();
overlayGLcontext->setFormat( format );
overlayGLcontext->setShareContext(widgetGLcontext);
overlayGLcontext->create();

offscreen_surface = new QOffscreenSurface();
offscreen_surface->create();

...

overlayGLcontext->makeCurrent(offscreen_surface);
fbo = new QOpenGLFramebufferObject( w12, h12, GL_TEXTURE_2D);

...

overlayGLcontext->makeCurrent(offscreen_surface);
fbo->bind();

QOpenGLPaintDevice device(QSize(w12,h12));
QPainter painter(&device);

painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);

painter.beginNativePainting();

gl_functions->glClearColor(0.0, 0.0, 0.0, 0.0);
gl_functions->glClear(GL_COLOR_BUFFER_BIT);

painter.endNativePainting();

widget1->render(&painter);
widget2->render(&painter,QPoint(widget1->width(),0),QRegion());

painter.end();

fbo->release();

texture = fbo->texture();
pazduha
  • 147
  • 3
  • 17