[osg-users] porting from osg-3.4.0 to osg-3.6.3

Herman Varma hermanvarma at eastlink.ca
Tue Oct 9 06:49:43 PDT 2018

Hi Robert

Yes  VTP calls  setEventVisitor


bool vtScene::Init(int argc, char** argv, bool bStereo, int iStereoMode)

Code is listed below marked as //*******CALLED HERE

 * Initialize the vtlib library, including the display and scene graph.
 * You should call this function only once, before any other vtlib calls.
 * \param argc, argv Command-line arguments.
 * \param bStereo True for a stereo display output.
 * \param iStereoMode Currently for vtosg, supported values are 0 for
 *		Anaglyphic (red-blue) and 1 for Quad-buffer (shutter glasses).
bool vtScene::Init(int argc, char** argv, bool bStereo, int iStereoMode)

	// Redirect cout messages (where OSG sends its messages) to our own log
	previous_cout =  std::cout.rdbuf(&g_Trap);
	previous_cerr = std::cerr.rdbuf(&g_Trap);

#if 0
	// If you encounter trouble in OSG that you want to debug, enable this
	//  to get a LOT of diagnostic messages from OSG.

	m_pDefaultCamera = new vtCamera;
	m_pDefaultWindow = new vtWindow;

    // use an ArgumentParser object to manage the program arguments.
    osg::ArgumentParser arguments(&argc,argv);

	m_pOsgViewer = new osgViewer::Viewer(arguments);

	if (bStereo)
		osg::DisplaySettings* displaySettings = m_pOsgViewer->getDisplaySettings();
		osg::DisplaySettings::StereoMode mode;
		if (iStereoMode == 0) mode = osg::DisplaySettings::ANAGLYPHIC;
		if (iStereoMode == 1) mode = osg::DisplaySettings::QUAD_BUFFER;
		if (iStereoMode == 2) mode = osg::DisplaySettings::HORIZONTAL_SPLIT;
		if (iStereoMode == 3) mode = osg::DisplaySettings::VERTICAL_SPLIT;
#ifdef __DARWIN_OSX__
	// Kill multi-threading on OSX until wxGLContext properly implemented on that platform

	// We can't use displaySettings->setNumMultiSamples here to enable anti-
	// aliasing, because it has to be done eariler (at the time the OpenGL
	// context is made).

	osgViewer::StatsHandler* pStatsHandler = new osgViewer::StatsHandler;
	pStatsHandler->setKeyEventTogglesOnScreenStats('x'); // I dont think this is used for anything else at the moment

	// Kill the event visitor (saves a scenegraph traversal)
	// This will need to be restored if we need to use FRAME events etc. in the scenegraph
	m_pOsgViewer->setEventVisitor(NULL);//*******CALLED HERE

	if (bStereo)
		// displaySettings->getScreenDistance(); default is 0.5
		// m_pOsgSceneView->getFusionDistanceMode(); default is PROPORTIONAL_TO_SCREEN_DISTANCE
		// m_pOsgSceneView->getFusionDistanceValue(); default is 1.0
		// The FusionDistanceValue is only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.

		// We use real-world units for fusion distance value
		m_pOsgViewer->setFusionDistance(osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE, 100.0f);

	// From the OSG mailing list: You must specify the lighting mode in
	// setDefaults() and override the default options. If you call
	// setDefaults() with the default options, a headlight is added to the
	// global state set of the SceneView.  With the default options applied,
	// I have tried subsequently calling setLightingMode(NO_SCENE_LIGHT)
	// and setLight(NULL), but I still get a headlight.
	m_pOsgViewer->getCamera()->setCullingMode(m_pOsgViewer->getCamera()->getCullingMode() & ~osg::CullSettings::SMALL_FEATURE_CULLING);

	// We maintain a node between OSG's viewer/camera and the vtlib Root, to
	//  control global state
	m_StateRoot = new osg::Group;

	// By default, things are lit, unless they ask not to be
	m_StateRoot->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::ON);

	//m_StateRoot->addCullCallback(new MyCull);
	//m_StateRoot->setUpdateCallback(new MyUpdate);
	//m_StateRoot->setEventCallback(new MyEvent);

	m_bInitialized = true;

	_initialTick = _timer.tick();
	_frameTick = _initialTick;

	return true;

Thank you!


Read this topic online here:

More information about the osg-users mailing list