| 43 | | class MyGraphicsContext { |
| 44 | | public: |
| 45 | | MyGraphicsContext() |
| 46 | | { |
| 47 | | osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; |
| 48 | | traits->x = 0; |
| 49 | | traits->y = 0; |
| 50 | | traits->width = 1; |
| 51 | | traits->height = 1; |
| 52 | | traits->windowDecoration = false; |
| 53 | | traits->doubleBuffer = false; |
| 54 | | traits->sharedContext = 0; |
| 55 | | traits->pbuffer = true; |
| 56 | | |
| 57 | | _gc = osg::GraphicsContext::createGraphicsContext(traits.get()); |
| 58 | | |
| 59 | | if (!_gc) |
| 60 | | { |
| 61 | | osg::notify(osg::NOTICE)<<"Failed to create pbuffer, failing back to normal graphics window."<<std::endl; |
| 62 | | |
| 63 | | traits->pbuffer = false; |
| 64 | | _gc = osg::GraphicsContext::createGraphicsContext(traits.get()); |
| 65 | | } |
| 66 | | |
| 67 | | if (_gc.valid()) |
| 68 | | |
| 69 | | |
| 70 | | { |
| 71 | | _gc->realize(); |
| 72 | | _gc->makeCurrent(); |
| 73 | | std::cout<<"Realized window"<<std::endl; |
| 74 | | } |
| 75 | | } |
| 76 | | |
| 77 | | bool valid() const { return _gc.valid() && _gc->isRealized(); } |
| 78 | | |
| 79 | | private: |
| 80 | | osg::ref_ptr<osg::GraphicsContext> _gc; |
| 81 | | }; |
| 82 | | |
| 85 | | osg::ref_ptr<osg::Node> scene; |
| 86 | | |
| 87 | | { |
| 88 | | std::string filename = osgDB::findDataFile("Images/land_shallow_topo_2048.jpg"); |
| 89 | | |
| 90 | | // make osgTerrain::DataSet quieter.. |
| 91 | | osgTerrain::DataSet::setNotifyOffset(1); |
| 92 | | |
| 93 | | osg::ref_ptr<osgTerrain::DataSet> dataSet = new osgTerrain::DataSet; |
| 94 | | |
| 95 | | // register the source imagery |
| 96 | | { |
| 97 | | osgTerrain::DataSet::Source* source = new osgTerrain::DataSet::Source(osgTerrain::DataSet::Source::IMAGE, filename); |
| 98 | | |
| 99 | | source->setCoordinateSystemPolicy(osgTerrain::DataSet::Source::PREFER_CONFIG_SETTINGS); |
| 100 | | source->setCoordinateSystem(osgTerrain::DataSet::coordinateSystemStringToWTK("WGS84")); |
| 101 | | |
| 102 | | source->setGeoTransformPolicy(osgTerrain::DataSet::Source::PREFER_CONFIG_SETTINGS_BUT_SCALE_BY_FILE_RESOLUTION); |
| 103 | | source->setGeoTransformFromRange(-180.0, 180.0, -90.0, 90.0); |
| 104 | | |
| 105 | | dataSet->addSource(source); |
| 106 | | } |
| 107 | | |
| 108 | | // set up destination database paramters. |
| 109 | | dataSet->setDatabaseType(osgTerrain::DataSet::LOD_DATABASE); |
| 110 | | dataSet->setConvertFromGeographicToGeocentric(true); |
| 111 | | dataSet->setDestinationName("test.osg"); |
| 112 | | |
| 113 | | // load the source data and record sizes. |
| 114 | | dataSet->loadSources(); |
| 115 | | |
| 116 | | MyGraphicsContext context; |
| 117 | | dataSet->createDestination(30); |
| 118 | | |
| 119 | | if (dataSet->getDatabaseType()==osgTerrain::DataSet::LOD_DATABASE) dataSet->buildDestination(); |
| 120 | | else dataSet->writeDestination(); |
| 121 | | |
| 122 | | scene = dataSet->getDestinationRootNode(); |
| 123 | | |
| 124 | | // now we must get rid of all the old OpenGL objects before we start using the scene graph again |
| 125 | | // otherwise it'll end up in an inconsistent state. |
| 126 | | scene->releaseGLObjects(dataSet->getState()); |
| 127 | | osg::Texture::flushAllDeletedTextureObjects(0); |
| 128 | | osg::Drawable::flushAllDeletedDisplayLists(0); |
| 129 | | } |
| 130 | | |
| 131 | | return scene.release(); |
| | 45 | osg::TessellationHints* hints = new osg::TessellationHints; |
| | 46 | hints->setDetailRatio(5.0f); |
| | 47 | |
| | 48 | |
| | 49 | osg::ShapeDrawable* sd = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0,0.0,0.0), osg::WGS_84_RADIUS_POLAR), hints); |
| | 50 | |
| | 51 | osg::Geode* geode = new osg::Geode; |
| | 52 | geode->addDrawable(sd); |
| | 53 | |
| | 54 | std::string filename = osgDB::findDataFile("Images/land_shallow_topo_2048.jpg"); |
| | 55 | geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, new osg::Texture2D(osgDB::readImageFile(filename))); |
| | 56 | |
| | 57 | osg::CoordinateSystemNode* csn = new osg::CoordinateSystemNode; |
| | 58 | csn->setEllipsoidModel(new osg::EllipsoidModel()); |
| | 59 | csn->addChild(geode); |
| | 60 | |
| | 61 | return csn; |