Hi, I am using a 3rd party lib(QCAR) with OSG on Android. This lib clears OpenGLES graphics context every time after rendering a frame. So the model renders only once (first time) and disappears on the viewer. So to preserve graphics context i did as follows
---> Created Embeded View ---> Captured current Graphics context as follws Code: m_lastStateSet = new osg::StateSet(); _viewer->getCamera()->getGraphicsContext()->getState()->captureCurrentState(*m_lastStateSet.get()); ---> In RendererFrame function ---> Restore graphics context as follows Code: osgState = _viewer->getCamera()->getGraphicsContext()->getState(); osgState->reset(); osgState->apply(m_lastStateSet.get()); ---> render Frame Code ----> Save the current state of the graphics context as follows Code: _viewer->getCamera()->getGraphicsContext()->getState()->captureCurrentState(*m_lastStateSet.get()); This works fine with OpenGLES1. The same is not working if I build the same code with OpenGLES2 version. Can you please help me what could be the mistake. Here is the complete code OSG INIT Function Code: void OsgApp::initOsgWindow(int sW,int sH) { _viewer = new osgViewer::Viewer(); embeddedWindow=_viewer->setUpViewerAsEmbeddedInWindow(x, y, width, height); _root = new osg::Group(); _viewer->realize(); _state = _root->getOrCreateStateSet(); _state->setMode(GL_LIGHTING, osg::StateAttribute::ON); _state->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON); _state->setMode(GL_CULL_FACE, osg::StateAttribute::ON); //_viewer->setSceneData(_root.get()); _viewer->addEventHandler(new osgViewer::StatsHandler); _viewer->addEventHandler(new osgGA::StateSetManipulator(_viewer->getCamera()->getOrCreateStateSet())); _viewer->addEventHandler(new osgViewer::ThreadingHandler); _viewer->addEventHandler(new osgViewer::LODScaleHandler); _manipulator = new osgGA::KeySwitchMatrixManipulator; _manipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); _manipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); _manipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); _manipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); _manipulator->addMatrixManipulator( '5', "Orbit", new osgGA::OrbitManipulator() ); _manipulator->addMatrixManipulator( '6', "FirstPerson", new osgGA::FirstPersonManipulator() ); _manipulator->addMatrixManipulator( '7', "Spherical", new osgGA::SphericalManipulator() ); _viewer->setCameraManipulator( _manipulator.get() ); _viewer->getViewerStats()->collectStats("scene", true); _viewer->getCamera()->setViewport(0,0,sW, sH); _viewer->getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT ); modelSwitch=new osg::Switch; LOG("READING Model_0"); readModels("/mnt/sdcard/test/0.osg",MODEL_1); _root->addChild(modelSwitch.get()); _viewer->setSceneData(NULL); _viewer->setSceneData(_root.get()); _manipulator->getNode(); _viewer->home(); _viewer->getDatabasePager()->clear(); _viewer->getDatabasePager()->registerPagedLODs(_root.get()); _viewer->getDatabasePager()->setUpThreads(3, 1); _viewer->getDatabasePager()->setTargetMaximumNumberOfPageLOD(2); _viewer->getDatabasePager()->setUnrefImageDataAfterApplyPolicy(true, true); [color=red][b]m_lastStateSet = new osg::StateSet(); _viewer->getCamera()->getGraphicsContext()->getState()->captureCurrentState(*m_lastStateSet.get()); [/b][/color] } Renderer Function Code: void OsgApp::renderer(osg::Matrix mat) { [color=red] [b]osgState = _viewer->getCamera()->getGraphicsContext()->getState(); osgState->reset(); osgState->apply(m_lastStateSet.get()); [/b][/color] renderModel_1(mat); _viewer->frame(); [color=red][b]_viewer->getCamera()->getGraphicsContext()->getState()->captureCurrentState(*m_lastStateSet.get()); [/b] [/color] } ... Thank you! Cheers, Koduri ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=51032#51032 _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org