osg没有像提供windows、ios等操作系统专用窗口创建接口一样来提供Android系统的,而是直接使用自己的osgViewer::GraphicsWindowEmbedded
osg::ref_ptr<osgViewer::Viewer> _viewer;
_viewer = new osgViewer::Viewer();
_viewer->setUpViewerAsEmbeddedInWindow(x, y, width, height);
_viewer->realize();
osgViewer/Viewer.cpp
GraphicsWindowEmbedded* Viewer::setUpViewerAsEmbeddedInWindow(int x, int y, int width, int height)
{
setThreadingModel(SingleThreaded);
osgViewer::GraphicsWindowEmbedded* gw = new osgViewer::GraphicsWindowEmbedded(x,y,width,height);
getCamera()->setViewport(new osg::Viewport(0,0,width,height));
getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(width)/static_cast<double>(height), 1.0f, 10000.0f);
getCamera()->setGraphicsContext(gw);
return gw;
}
osgViewer/GraphicsWindow