查看: 2170|回复: 2

vpb作出的地形不能改变颜色

[复制链接]

该用户从未签到

发表于 2010-7-1 13:58:44 | 显示全部楼层 |阅读模式
代码如下,如果用一个普通的房子是可以改变颜色的,但是用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;
}

该用户从未签到

发表于 2010-7-2 09:35:38 | 显示全部楼层
注释掉下面一行将达到预想效果,但是关于ColorMode的用法不明确。请教高手。
  1. pMaterial->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
复制代码

该用户从未签到

发表于 2010-7-2 10:35:07 | 显示全部楼层
它就是OpenGL中glColorMaterial的实现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表