#include <osgViewer/Viewer>
#include <osg/Group>
#include <osg/Light>
#include <osg/LightSource>
#include <osg/Material>
#include <osg/StateSet>
int main(int argc, char** argv)
{
// 创建一个OSG查看器
osgViewer::Viewer viewer;
// 创建一个根节点
osg::ref_ptr<osg::Group> root = new osg::Group;
// 创建一个光源
osg::ref_ptr<osg::Light> light = new osg::Light;
light->setLightNum(0);
light->setPosition(osg::Vec4(0.0f, 0.0f, 1000.0f, 1.0f));
light->setAmbient(osg::Vec4(0.1f, 0.1f, 0.1f, 1.0f));
light->setDiffuse(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
light->setSpecular(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
// 创建光源节点
osg::ref_ptr<osg::LightSource> lightSource = new osg::LightSource;
lightSource->setLight(light.get());
// 创建材质
osg::ref_ptr<osg::Material> material = new osg::Material;
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
// 创建状态集
osg::ref_ptr<osg::StateSet> stateSet = root->getOrCreateStateSet();
stateSet->setAttributeAndModes(material);
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);
// 加载城市模型
osg::ref_ptr<osg::Node> cityModel = osgDB::readNodeFile("path/to/your/city_model.osg");
// 将光源节点和城市模型添加到根节点
root->addChild(lightSource);
root->addChild(cityModel);
// 将根节点设置为查看器的场景数据
viewer.setSceneData(root);
// 开始查看器的主循环
return viewer.run();
}