|
osg::Node* createClouds(double maxRange)
{
//Try to read from the WorldWind server
osg::ref_ptr<osg::Image> image = osgDB::readImageFile("E:\\OpenSceneGraph\\Data\\Images\\1.bmp");
if (!image.valid())
{
//OE_NOTICE << "Could not read clouds image " << std::endl;
return NULL;
}
double min_lon = -180.0;
double min_lat = -90.0;
double max_lon = 180.0;
double max_lat = 90;
osgTerrain::TerrainTile* tile = new osgTerrain::TerrainTile();
osgTerrain:ocator* locator = new osgTerrain::Locator();
locator->setCoordinateSystemType( osgTerrain::Locator::GEOCENTRIC );
locator->setTransformAsExtents(
osg:egreesToRadians( min_lon ),
osg::DegreesToRadians( min_lat ),
osg::DegreesToRadians( max_lon ),
osg::DegreesToRadians( max_lat ));
osg::HeightField *hf = new osg::HeightField();
hf->allocate(64,64);
for(unsigned int i=0; i<hf->getHeightList().size(); i++ ) hf->getHeightList()[i] = 0.0;
hf->setOrigin( osg::Vec3d( min_lon, min_lat, 0.0 ) );
hf->setXInterval( (max_lon - min_lon)/(double)(hf->getNumColumns()-1) );
hf->setYInterval( (max_lat - min_lat)/(double)(hf->getNumRows()-1) );
hf->setBorderWidth( 0 );
osgTerrain::HeightFieldLayer* hf_layer = new osgTerrain::HeightFieldLayer();
hf_layer->setLocator( locator );
hf_layer->setHeightField( hf );
osgTerrain::ImageLayer* img_layer = new osgTerrain::ImageLayer( image.get() );
img_layer->setLocator( locator );
tile->setColorLayer( 0, img_layer );
tile->setLocator( locator );
tile->setTerrainTechnique( new osgTerrain::GeometryTechnique() );
tile->setElevationLayer( hf_layer );
tile->setRequiresNormals( true );
tile->getOrCreateStateSet()->setAttributeAndModes(new CullFace(CullFace::BACK), StateAttribute::ON);
tile->getOrCreateStateSet()->setMode(GL_LIGHTING, StateAttribute::OFF);
double scale = 1.01;
osg::MatrixTransform* mt = new osg::MatrixTransform;
mt->setMatrix(osg::Matrixd::scale(scale, scale, scale));
mt->addChild(tile);
osg::LOD *lod = new LOD;
lod->addChild(mt, maxRange, FLT_MAX);
return lod;
}
int _tmain(int argc, _TCHAR* argv[])
{
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Group>group = new osg::Group();
group->addChild(createClouds(osg::WGS_84_RADIUS_EQUATOR * 2.0));
osgUtil::Optimizer optimizer;
optimizer.optimize(group.get());
viewer.setSceneData(group.get());
viewer.realize();
return viewer.run();
}
测试代码提示错误:glGenbuffers not supported by openGL driver 怎么改? |
|