[vtkusers] How to draw the scene in the off-screen?

Kevin H. Hobbs hobbsk at ohiou.edu
Thu Aug 16 08:21:02 EDT 2007


On Thu, 2007-08-09 at 09:44 -0400, liu jianfei wrote:
> Dear all
> 
>     I'm using 'vtkrenderwindow' to hold and display all renders, and
> grabbing z-buffer and frame buffer from it. But I want to put all
> these processing in off-screen rather than display them directly. How
> can I implement it? Thanks. 

A program using offscreen rendering will look something like this:

#include "vtkGraphicsFactory.h"
#include "vtkImagingFactory.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkWindowToImageFilter.h"
#include "vtkPNGWriter.h"

int main( int argc, char * argv[] )
{

        // Graphics Factory
        vtkGraphicsFactory * graphics_factory
                = vtkGraphicsFactory::New();
        graphics_factory->SetOffScreenOnlyMode( 1);
        graphics_factory->SetUseMesaClasses( 1 );

        // Imaging Factory
        vtkImagingFactory * imaging_factory
                = vtkImagingFactory::New();
        imaging_factory->SetUseMesaClasses( 1 );

        vtkSphereSource* sphere = vtkSphereSource::New();

        vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
        mapper -> SetInputConnection( sphere -> GetOutputPort() );

        vtkActor* actor = vtkActor::New();
        actor -> SetMapper( mapper );

        vtkRenderer* renderer = vtkRenderer::New();
        renderer -> AddActor( actor );

        vtkRenderWindow* window = vtkRenderWindow::New();
        window -> AddRenderer( window );

        // Window to Image
        vtkWindowToImageFilter * win_2_image
                = vtkWindowToImageFilter::New();
        win_2_image -> SetInput( window );

        // PNG Writer
        vtkPNGWriter * writer = vtkPNGWriter::New();
        writer -> SetFileName( "out_file.png" );
        writer -> SetInputConnection( win_2_image->GetOutputPort() );

        window -> Render();

        writer -> Write();

        return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070816/8110604e/attachment.pgp>


More information about the vtkusers mailing list