/usr/share/vtk/MangledMesa/Tcl/OffScreenPrinting.tcl is in vtk-examples 5.8.0-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | package require vtk
package require vtkinteraction
# This script demonstrates the use of mangled Mesa to generate an
# off-screen copy of the OpenGL render window. A cone is created
# and added to the OpenGL renderer. When the user press the Print
# button, a copy of the scene is rendered on the Mesa window
# (which is set to render in memory) and then the scene is save to
# a png file using the png writer.
# Create the pipeline
# Note that an equivalent Mesa object has to be created for each
# OpenGL object.
# Turn on the use of the Mesa classes in the graphics factory.
vtkGraphicsFactory gf
gf SetUseMesaClasses 1
# The OpenGL render window
vtkRenderWindow rw
# The Mesa equivalent
vtkXMesaRenderWindow mrw
mrw OffScreenRenderingOn
# OpenGL
vtkRenderer ren
rw AddRenderer ren
# Mesa
vtkMesaRenderer mren
mrw AddRenderer mren
vtkConeSource cone
# OpenGL
vtkPolyDataMapper map
map SetInputConnection [cone GetOutputPort]
# Mesa
vtkMesaPolyDataMapper mmap
mmap SetInputConnection [cone GetOutputPort]
# OpenGL
vtkActor actor
actor SetMapper map
# Mesa
vtkMesaActor mactor
mactor SetMapper mmap
# Add the actor to the renderer
ren AddActor actor
mren AddActor mactor
# These are for creating an image from the Mesa render window
vtkWindowToImageFilter w2if
w2if SetInput mrw
vtkPNGWriter writer
writer SetInputConnection [w2if GetOutputPort]
writer SetFileName "MesaPrintout.png"
set mesaCamera [mren GetActiveCamera]
set openGLCamera [ren GetActiveCamera]
proc PrintWithMesa {} {
global mesaCamera openGLCamera
# This is needed to create a default mesa light
mrw Render
set mesaLights [mren GetLights]
eval $mesaLights InitTraversal
set mesaLight [$mesaLights GetNextItem]
set openGLLights [ren GetLights]
eval $openGLLights InitTraversal
set openGLLight [$openGLLights GetNextItem]
eval $mesaCamera SetPosition [$openGLCamera GetPosition]
eval $mesaCamera SetFocalPoint [$openGLCamera GetFocalPoint]
eval $mesaCamera SetViewUp [$openGLCamera GetViewUp]
eval $mesaCamera SetClippingRange [$openGLCamera GetClippingRange]
eval $mesaLight DeepCopy $openGLLight
mrw Render
# This is here to force the window to image filter to
# update it's image. Required.
w2if Modified
writer Write
}
# ------------------- Create the UI ---------------------
wm withdraw .
# Create the toplevel window
toplevel .top
wm title .top {Printing with Mesa Offscreen Demo}
# Create two frames
frame .top.f1
frame .top.f2
pack .top.f1 .top.f2 -side top -expand 1 -fill both
vtkTkRenderWidget .top.f1.rw -width 400 -height 400 -rw rw
::vtk::bind_tk_render_widget .top.f1.rw
pack .top.f1.rw -expand 1 -fill both
button .top.f2.b0 -text "Print" -command {PrintWithMesa}
button .top.f2.b1 -text "Quit" -command ::vtk::cb_exit
pack .top.f2.b0 -expand 1 -fill x
pack .top.f2.b1 -expand 1 -fill x
|