5.2.2. Launching DirectViz from the API

This example is equivalent to the Open Inventor Mentor’s HelloCone program (see Section 2.1, ““Hello, Cone””) – a cone is created and rendered in an SoXtExaminerViewer using DirectViz:

#include <Inventor/nodes/SoCone.h>
#include <Inventor/Xt/viewers/SoXtExaminerViewer.h>

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

  Widget myWindow = SoXt::init(argv[0]);
    if(!myWindow)
    exit(1);

    SoXtExaminerViewer *viewer = new SoXtExaminerViewer(myWindow);
    SoCone *cone = new SoCone;
    viewer->setSceneGraph(cone);

    viewer->enableDirectViz(TRUE);

    SoXt::show(myWindow);
    SoXt::mainLoop();
    SoXt::finish();

    return 0;
      }

The method enableDirectViz() sets the DirectViz manager object – SoDirectVizManager SoDirectVizManager SoDirectVizManager – to render in that viewer using ray-tracing.

SoDirectVizManager SoDirectVizManager SoDirectVizManager derives from SoNode SoNode SoNode and has fields useful for controlling various settings of DirectViz. However it should not be inserted in the scene graph. You can get the SoDirectVizManager SoDirectVizManager SoDirectVizManager associated with a given viewer by calling:

SoDirectVizManager *mgr =
      SoDirectVizManager::getInstance(viewer->getSceneManager());

As only one viewer can use DirectViz at once, if DirectViz was already activated in another viewer, it will be deactivated in that viewer and rendering will switch back to OpenGL.

Only one camera in the scene can be used by DirectViz to render a whole frame. For viewers, it’s the camera controlled by the viewer, which can be retrieved by SoXtViewer::getCamera(). By default, it is the first camera encountered in the scene graph. In the case of simple render areas – which do not manage cameras – the camera must be specified to DirectViz by SoDirectVizManager::setCamera().

See $OIVHOME/src/DirectViz/examples for source code showing how to use DirectViz with viewers, render areas, and offscreen rendering.

[Important]

The OpenRTRT renderer writes various diagnostic messages to “stdout”. In some environments these messages may not be visible. For example on Windows these messages will only be visible if the application is built as a console application. Also the OpenRTRT renderer may exit immediately when some errors occur. If your application behaves unexpectedly after enabling DirectViz, try running the application from a command line. On Windows try running a simple application built as a console application.