[vtkusers] Rendering VTK inside a QGLWidget

Clinton Stimpson clinton at elemtech.com
Thu Oct 6 13:05:22 EDT 2011


Do you get anything from glCheckFramebufferStatus() after the 
glBindFramebufferEXT()?
Have you considered using QGLFramebufferObject, if that is simpler?
The GraphicsView example in VTK uses QGLFramebufferObject with 
vtkGenericOpenGLRenderWindow.

If you want to feed events into VTK, you should have a 
vtkRenderWindowInteractor.  But you don't have to call Start() on it.
Have a look at the QVTKInteractorAdapter class.  You may be able to pass your 
QEvent's through there and it'll translate them for you and pass them to VTK.

Clint

On Thursday, October 06, 2011 10:42:18 am Paul Rossi wrote:
> Thank you so much, Clinton
> 
> Just by following your tips i managed to render a sphere inside a qglwidget
> by using the vtkGenericOpenGLRenderWindow
> 
> However, i have a question at this point:
> I kind of do offscreen rendering, and before and after the rendering i
> always call:
> 
> 		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,m_uFramebuffer);
> 		GLenum glError = glGetError();
> 
> 		if (glError != GL_NO_ERROR)
> 			throw Exception("Error binding framebuffer
> (%s).",gluErrorString(glError));
> 
> 
> and
> 
> 		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
> 		const GLenum glError = glGetError();
> 
> 		if (glError != GL_NO_ERROR)
> 			throw Exception("Error releasing framebuffer
> (%s).",gluErrorString(glError));
> 
> to attach and detach the fbo.
> my problem is that this code renders well:
> 
> 			renWin->PushState();
> 			renWin->OpenGLInit();
> 			renWin->Render();
> 			renWin->PopState();
> 
> but after that, if i try to detach the framebuffer i get an error "Invalid
> operation" (even if it renders properly) I will now try to dig a little
> into the vtkGenericOpenGLRenderWindow, but do you know what it could be
> and how it could be fixed?
> 
> I also have a last question: is it possible to skip using the
> RenderWindowInteractor, and somehow feed events to vtk from qt events?
> Otherwise, how should i proceed to get interaction from a qglwidget into a
> vtk interactor?
> 
> thank you so much already
> Paul
> 
> 06 октября 2011, 03:18 от Clinton Stimpson <clinton at elemtech.com>:
> > On Wednesday, October 05, 2011 04:54:40 pm Paul Rossi wrote:
> > > Hi all,
> > > 
> > > I have a problem and i havent been able to fix it.
> > > i want to use VTK from Qt, and i know that there is the
> > > nice QVTK module for that.
> > > My problem is that i  have to do my rendering from within a QGLWidget
> > > (i am using a sort of framework where my views are qglwidgets, and i
> > > cannot use any other viewer class)
> > > 
> > > I know it is possible to render  vtk from within a QGraphicsView, but i
> > > still cannot find if or how to render a  vtkrenderer from within a
> > > qglwidget
> > > 
> > > any suggestion?
> > 
> > Try using the vtkGenericOpenGLRenderWindow in VTK 5.8.
> > You can also see QVTKWidget2 as an example of using it, but depending on
> > what you are doing, it may be simpler.  Or simply use QVTKWidget2 which
> > is derived from QGLWidget, if that'll fit in your framework.
> > 
> > If you do it yourself, you should at least call in the construction,
> > depending on how you are going to use it:
> > renWin->SwapBuffersOff()
> > 
> > in the resize
> > renWin->SetSize()
> > 
> > in the paintGL()
> > renWin->PushState()
> > renWin->OpenGLInit()
> > renWin->Render()
> > renWin->PopState()
> > 
> > If you are also mixing calls to QPainter, make sure to call
> > QPainter::beginNativePainting()/endNativePainting().
> > 
> > There's more to do if you want to use vtkRenderWindowInteractor as well.
> > 
> > --
> > Clinton Stimpson
> > Elemental Technologies, Inc
> > Computational Simulation Software, LLC
> > www.csimsoft.com
> > _______________________________________________
> > Powered by www.kitware.com
> > 
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> > 
> > Please keep messages on-topic and check the VTK FAQ at:
> > http://www.vtk.org/Wiki/VTK_FAQ
> > 
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> 
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers

-- 
Clinton Stimpson
Elemental Technologies, Inc
Computational Simulation Software, LLC
www.csimsoft.com



More information about the vtkusers mailing list