|
代码如下,如果用一个普通的房子是可以改变颜色的,但是用vpb做的地形不能改变颜色,不知为何,
请大家帮助一下
#include "stdafx.h"
#include <osg/ref_ptr>
#include <osg/node>
#include <osgdb/ReadFile>
#include <osg/Material>
#include <osgViewer/viewer>int _tmain(int argc, _TCHAR* argv[])
{
osg::ref_ptr<osg::Node>pNode = osgDB::readNodeFile("Terrain.ive");
osg::ref_ptr<osg::StateSet> pStateSet = pNode->getOrCreateStateSet();// osg::Material *pMaterial = new osg::Material();//
pMaterial->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
const osg::Vec4 color(1.0, 0, 0, 1.0);
pMaterial->setAmbient(osg::Material::FRONT_AND_BACK,color);
pMaterial->setDiffuse(osg::Material::FRONT_AND_BACK,color * 0.8);
pStateSet->setAttribute(pMaterial,osg::StateAttribute::OVERRIDE);
pStateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);
osg:ight *pLight = new osg::Light(0);
pLight->setAmbient(osg::Vec4(1.0, 1.0, 1.0, 1.0));
pLight->setDiffuse(osg::Vec4(1.0, 1.0, 1.0, 1.0));
pStateSet->setAttribute(pLight, osg::StateAttribute::OVERRIDE);
osgViewer::Viewer viewer;
viewer.setSceneData(pNode);
viewer.run();
return 0;
} |
|