Off-screen rendering

Hi all,

I'm wondering whether or not it's possible to create a screenshot from a V3d_View (I did not find any thread related to that topic on the forum).

According to the following code,

gd = new Graphic3d_GraphicDevice(std::getenv("DISPLAY"));
myV3dViewer = new V3d_Viewer( gd , (short* const)"myV3dViewer" );
myV3dView = myV3dViewer->CreateView();

it's not necessary to have a Xw_Window inited to create a V3d_View.

Did anyone here ever try to dump a V3d_View to a jpeg file without anything being displayed to the screen? Is it even possible? I would like to have your feedbacks before investigating this further.

Best regards,


Thomas Paviot's picture

I think I have the answer. Here is how is implemented the Dump method of the V3d_View class (extracted from the V3d_View.cxx file):

Standard_Boolean V3d_View::Dump ( const Standard_CString aFile )
Standard_Boolean isDone;
#ifdef G004
Standard_Real gammaValue = 1.0;
OSD_Environment envGamma("CSF_GAMMA_CORRECTION");
TCollection_AsciiString strGamma(envGamma.Value());
if( !strGamma.IsEmpty() ) gammaValue = strGamma.RealValue();
isDone = MyWindow->Dump ( aFile , gammaValue );
isDone = MyWindow->Dump ( aFile );
return isDone;

The image file is created by the Dump method of MyWindow, pointer initialized by the SetWindow method. I have the answer to my question: to dump a V3d_View to a file, it's necessary to first create and set a window (whether it is a WNT_Window or Xw_Window).

Any other way to perform off-screen rendering?

Fotis Sioutis's picture

Thomas try the following :

(I reposted it on the mail list of pythonocc)

Handle(Aspect_PixMap) aPixMap = myView->ToPixMap(width,height);

Maybe it will work


Thomas Paviot's picture

Hi Fotis,

I guess it won't work: this method also requires a Xw_Window or WNT_Window to be created first (see the code below from V3d_View.cxx)

[... snipped ...]
Handle(Aspect_PixMap) V3d_View::ToPixMap (const Standard_Integer aWidth,
const Standard_Integer aHeight,
const Standard_Integer aCDepth)
Handle(Aspect_PixMap) theBitmap;
#ifdef WNT
theBitmap = new WNT_PixMap ( MyWindow, aWidth, aHeight, aCDepth );
theBitmap = new Xw_PixMap ( MyWindow, aWidth, aHeight, aCDepth );
[... snipped ...]