[vtkusers] How create an offscreen render window in VTK ?? Please Help

Paul Cochrane paultcochrane at gmail.com
Wed Nov 30 20:19:59 EST 2005


Deepak,

One trap for young players is that often to get off screen rendering
working one needs to set up factories for graphics and image objects
such that you can get Mesa to render offscreen.  The following code
does this for Python but shouldn't be too hard to convert to C++.

factGraphics = vtk.vtkGraphicsFactory()
factGraphics.SetUseMesaClasses(1)
factImage = vtk.vtkImagingFactory()
factImage.SetUseMesaClasses(1)

HTH

Paul


On 12/1/05, Deepak Roy <cdeepakroy at yahoo.com> wrote:
> Hello,
>
> I tried vtkRenderWindow::OffScreenRenderingOn today but it
> does not work.
>
> It would be really helpful if you could provide any examples.
>
> I turned it on and used vtkWindowToImageFilter to save a snapshot of the
> OffScreenRenderWindow to an image file( JPEG ) on disk but the image comes
> out to be a snaphot of the desktop when the code is executed.
>
> I am using the VTK + QT library written by Carsten Kibler. I suspect if that
> is giving the problem. Because My Application is developed with QT and VTK.
> So there is already a QT + VTK render window in which the model is being
> displayed. I am creating the offscreen render window after that, so i
> suspect there are some conflicts.
> Because if i turn the offscreenrendering to off ( which is the default ),
> the render window is not visible, which is not normally expected.
>
> I am using offscreen rendering to find the volume enclosed between two
> surfaces.
>
>  --- First i render the surface behind ---> extract the z-buffer of the
> offscreen window.
>
> ---- Second i remove the surface behind and new render the front surface
> alone ---> extract the z-buffer again
>
> ----- Subtracting both the Z-buffers would give me the volume.
>
> I earlier used vtkMassProperties but it does not give good results. Hence i
> resorted to the z-buffer technique.
>
> Here is the code i used for the offscreen rendering:
>
> ************************************************************************************************
>
> vtkOpenGLRenderer *pOffScreenRenderer = vtkOpenGLRenderer::New();
>
> vtkRenderWindow *pOffScreenRenderWindow = vtkOpenGLRenderWindow::New();
> pOffScreenRenderWindow->OffScreenRenderingOn();
> pOffScreenRenderWindow->AddRenderer( pOffScreenRenderer );
> pOffScreenRenderWindow->Start();
> pOffScreenRenderWindow->SetSize( wx , wy );
> pOffScreenRenderWindow->Render();
>
> // render a surface now
> pOffScreenRenderer->AddActor( pSurfaceActor );
> pOffScreenRenderer->Render();
> pOffScreenRenderWindow->Render();
>
> // save a snapshot to disk
> vtkWindowToImageFilter *pWindowImageFilter = vtkWindowToImageFilter::New();
> pWindowImageFilter->SetInput( pOffScreenRenderWindow );
>
> vtkJPEGWriter *pImageWriter = vtkJPEGWriter::New();
> pImageWriter->SetInput( pWindowImageFilter->GetOutput() );
> pImageWriter->SetQuality( 100 );
> pImageWriter->SetFileName( "coons_image.jpg" );
> pImageWriter->ProgressiveOff();
> pImageWriter->Write();
> pImageWriter->Delete();
>
> *************************************************************************************************
>
> Is there anything wrong with the code ?
>
> Please Help !!!!!
>
> Thanks in Advance.
>
> Regards
>
> Deepak Roy
>
>
> Sylvain Jaume <sylvain.jaume at kitware.com> wrote:
> Hi Deepak,
>
> Have you tried vtkRenderWindow::OffScreenRenderingOn?
> http://www.vtk.org/doc/nightly/html/classvtkWindow.html#803e4f1aba85b796a0f17b0ec84093f9
>
> Cheers,
> Sylvain
>
> Deepak Roy wrote:
>
> > hello everybody,
> >
> > Do you know how to create an offscreen vtk render window in VTK ?
> >
> > I want to render into the off screen render window and then get its
> > z-buffer using GetZbufferData
> >
> > () and work on its z-buffer.
> >
> > Or is there an offscreen buffer similar to vtkRenderWindow.
> >
> > Please Help.
> >
> > Thanks in advance.
> >
> > Regards,
> >
> > Deepak
> >
> >
> ------------------------------------------------------------------------
> > Yahoo! DSL
> >
> > Something to write home about. Just $16.99/mo. or less
> >
> >------------------------------------------------------------------------
> >
> >_______________________________________________
> >This is the private VTK discussion list.
> >Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> >Follow this link to subscribe/unsubscribe:
> >http://www.vtk.org/mailman/listinfo/vtkusers
> >
> >
>
>
>
>
>  ________________________________
>  Yahoo! Music Unlimited - Access over 1 million songs. Try it free.
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
>


More information about the vtkusers mailing list