UrbanLegend Site Admin

Joined: 11 Apr 2005 Posts: 1133
|
Posted: Sun Apr 22, 2007 8:35 pm Post subject: (35)With multiple rendering windows, I get weird results |
|
|
Q : With multiple rendering windows, I get weird results & textures display incorrectly
A : Each rendering window has its own OpenGL context which is separate from all other contexts. OSG doesn't know how you set up your windowing environment, you thus need to ensure that each osg::State object is tied to a unique OpenGL context.
To do that you do something along the lines of:
1. for each window, get the associated osgUtil::SceneView object
2. for each SceneView object, get the associated osg::State object
3. call State::setContextID() on each State, passing a unique number to identify that context
| Code: |
osgProducer::OsgSceneHandler *m_shandle = NULL;
osgUtil::SceneView *m_sceneview_one = NULL;
osgUtil::SceneView *m_sceneview_two = NULL;
//
// Grab the SceneViews
//
m_shandle = dynamic_cast<osgProducer>( camera_one->getSceneHandler() );
m_sceneview_one = m_shandle->getSceneView();
m_shandle = dynamic_cast<osgProducer>( camera_two->getSceneHandler());
m_sceneview_two = m_shandle->getSceneView();
//
// Create the default osg::State and the reset of the First Sceneviews defaults
//
m_sceneview_one->setDefatults();
//
// now set the ID to 0 ,this is the default
//
m_sceneview_one->getState()->setContextID(0);
//
// Create the default osg::State and the reset of the Second Sceneviews defaults
//
m_sceneview_two->setDefatults();
//
// now set the ID to 1, on the next sceneview
//
m_sceneview_two->getState()->setContextID(1);
|
Note, that context ID's are used as indices in to vectors that grow automatically, so avoid setting large numbers, start counting from 0 and then increment by one each time |
|