RobC
RobC

Reputation: 511

Using Qt5 widgets over a QOpenGLWidget without overdraw?

I have an OpenGL app I am considering porting to Qt5. I rolled by own basic GUI features that are drawn first with an orthographic perspective before drawing the rest of the scene. Fragment shaders are not run on the pixels already covered but the GUI.

I can't find any info on how smart Qt5 is about this. Given you can use the depth buffers however you want in OpenGL I'm guessing Qt is forced to draw overlay widgets after the fact.

Is it possible to direct the widget to render itself to a texture? If I'm rendering to texture on the screen I think I'd also have to capture all input and manually push it to the widget for processing.

Even better would be to let me setup the buffers how I want and then trigger the widget to render itself via OpenGL directly into the QOpenGLWidget. Is that possible?

Upvotes: 0

Views: 752

Answers (1)

RobC
RobC

Reputation: 511

It looks like they have a painter for any OpenGL devices (src code). According to the documentation you can manually draw widgets with the painter and do the rest of the rendering. Their source shows they actively use the stencil buffer.

http://doc.qt.io/qt-5/qopenglwidget.html

It is also possible to draw 2D graphics onto a QOpenGLWidget subclass using QPainter:

  • In paintGL(), instead of issuing OpenGL commands, construct a QPainter object for use on the widget.
  • Draw primitives using QPainter's member functions.
  • Direct OpenGL commands can still be issued. However, you must make sure these are enclosed by a call to the painter's beginNativePainting() and endNativePainting().

Upvotes: 0

Related Questions