Tysen, If you suspect that your problem is due to lighting, I would suggest that you take a close look at the osglight example. It has code in there to properly set up and render with a light source.
Looking at your code below in method 2, it appears that you're setting up a spot light since you're calling both setPosition() (with w = 1.0) AND setDirection(). setDirection() applies to spotlights. I doubt this is what you wanted to do. If you want a directional light source, use setPosition with the w component set to 0.0. If you want a positional light, specify the x,y,z and set w = 1.0. Don't use setDirection(). Hope this gives you some direction (pun intended)... -Shayne -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Tysen Chan Sent: Friday, January 28, 2011 2:22 AM To: [email protected] Subject: [osg-users] about osg light Hi, I load a 3ds file into osg viewer, but the color of the model is very dark, it is very different from the original model in sketchup. I guess that it is due to light config. So I use two methods, but they are not well. please help me. thankyou! I just want to the global light which color is (1,1,1,1) as nature world. How to config the light source. method1: osg::ref_ptr<osg::Node> spModelNode=osgDB::readNodeFile("1.3ds"); osg::ref_ptr<osg::StateSet> stateset=new osg::StateSet; stateset=spModelNode->getOrCreateStateSet (); stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON); stateset->setMode(GL_NORMALIZE, osg::StateAttribute::ON); spGroup->addChild(spModelNode); m_pOSG->getViewer()->setCameraManipulator(new osgGA::TrackballManipulator()); method2: osg::ref_ptr<osg::Node> spModelNode=osgDB::readNodeFile("1.3ds"); spGroup->addChild(CreateLight(spModelNode)); osg::ref_ptr<osg::Group> CreateLight(osg::ref_ptr<osg::Node> node) { osg::ref_ptr<osg::Group> lightRoot=new osg::Group(); lightRoot->addChild(node); osg::ref_ptr<osg::StateSet> stateset=new osg::StateSet; stateset=lightRoot->getOrCreateStateSet (); stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON); stateset->setMode(GL_LIGHT0, osg::StateAttribute::ON); stateset->setMode(GL_NORMALIZE, osg::StateAttribute::ON); osg::BoundingSphere bs; node->computeBound(); bs=node->getBound(); osg::ref_ptr<osg:ight> light=new osg:light; light->setLightNum(0); light->setDirection(osg::Vec3(0.0f, 0.0f, 1.0f)); light->setPosition(osg::Vec4(bs.center().x(), bs.center().y(), bs.center().z()-bs.radius(), 1.0f)); light->setAmbient(osg::Vec4(1.0f,1.0f,1.0f,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:ightSource> lightSource=new osg:ightSource; lightSource->setLight(light.get()); lightRoot->addChild(lightSource); return lightRoot.get(); } ... Thank you! Cheers, Tysen ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=36079#36079
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

