0

I want to call the rendering routine out without calling PaintGL, the reason is that I'm trying to render a multipass effect using the modern routines of Qt OpenGL implemementation so the pseudo code should be something like:

for i=0 i<npasses i++
   glwidget->renderlayer i
glwidget->repaint //this calls PaintGL

The problem is that if I call renderlayer out of the PaintGL function everything goes mad and it gets drawn over my entire app instead on my glwidget (that inherits from QOpenGLWidget) in the other hand renderlayer funcion is ok since being called only from inside PaintGL it works like it was expected.

Any tip on this?

Thank you in advance

Frank Escobar
  • 368
  • 4
  • 20
  • Before calling `renderlayer` you need to ensure the correct OpenGL context is active/current and that your `QOpenGLFramebufferObject` is [bound](http://doc.qt.io/qt-5/qopenglframebufferobject.html#bind) to that context. – G.M. Mar 11 '17 at 10:43

1 Answers1

1

You can create a QOffscreenSurface like this:

QOpenGLWidget* widget = ...;
QOpenGLContext* ctx = widget->context();

QOffscreenSurface surface;
surface.setFormat(ctx->format());
surface.setScreen(ctx->screen());
surface.create();

Then re-target your GL context to that offscreen surface, do your FBO rendering, and finally re-target the GL context back.

ctx->makeCurrent(&surface);

// Bind FBO, do the rendering

widget->makeCurrent();
Joseph Artsimovich
  • 1,499
  • 10
  • 13