//if the context was created correctly then attach to our viewer
if(graphicsContext)
{
//suppress annoying opengl warnings //attention please, you can comment the lines to debug
graphicsContext->getState()->setCheckForGLErrors(osg::State::NEVER_CHECK_GL_ERRORS);
_viewer->getCamera()->setGraphicsContext(graphicsContext);
_viewer->getCamera()->setViewport(new osg::Viewport(0, 0, graphicsContext->getTraits()->width, graphicsContext->getTraits()->height));
}
else
{
std::cout << "ERROR: I can't create graphic context" <<std::endl;
}
//create root of the scenegraph tree
_root = new osg::MatrixTransform();
//what I do here is simply create new nodes representing what i want to draw and add them as child of _root
[self initModels];
//YOU PROBABLY DON'T NEED TO DO THIS part about shaders
std::cout << "initing shaders" <<std::endl;
//initialize the shaders and attach them to _root
[self initShaders];
std::cout << "setting scene data to root" <<std::endl;
//create scene and attach it to _viewer
_viewer->setSceneData(_root.get());
//Set the threading model for the viewer,
//Possible options are: SingleThreaded || DrawThreadPerContext
_viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
std::cout << "setup camera" <<std::endl;
//I setup the camera parameters such as clear color, clear mask, render order ...
[self setupCamera];
_viewer->frame();
Then you call back _viewer->frame in a way I think you know.
- (void)setupCamera
{
//set the clear color of the camera to be semitransparent
_viewer->getCamera()->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f, 0.75f));
//set the clear mask for the camera
_viewer->getCamera()->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
_viewer->getCamera()->setRenderOrder(osg::CameraNode::PRE_RENDER);
_viewer->getCamera()->setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR);
}
I personally tried the semi-transparency (with that value of 0.75) and it is working.
I hope this helps.