I noticed you never apply the stateset referring to the light to any node.

Here's a suggestion:
<after creating the light node>
group->addChild(lightSource);
// grab a pointer to the group's stateset
osg::StateSet* statelightON_OVRD = group->getOrCreateStateSet();
statelightON_OVRD->setAttribute(light, osg::StateAttribute::ON);

This way the light is enabled for the group.

Mihai

ps. also noticed you set the scene data to only the loaded model:

viewer.setSceneData (loadedModel.get());

instead:

viewer.setSceneData (group.get());

[EMAIL PROTECTED] wrote:
Hello!!

Its my first email to the community!

I have been to the website and I foudn the codes examples.
I am trying to adda simple light or spot light to my scene graf!!

However I am not very skilled in coding, and I have an unclean code... 
I dont know where its my mistake or how to adapt the lamp to my code!
Basically I copied:


I attached my code in join file so you can have a look if required!/
I believe the problem is there:


// create the light    

	osg::StateSet* statelightON_OVRD = new osg::StateSet();
    osg::LightSource* lightSource = new osg::LightSource;
   

    osg::Light* light = lightSource->getLight();
  
	light->setLightNum(0);
    light->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); // directional light from above
    light->setAmbient(osg::Vec4(0.8f,0.8f,0.8f,1.0f));
    light->setDiffuse(osg::Vec4(0.2f,0.2f,0.2f,1.0f));
    light->setSpecular(osg::Vec4(0.2f,0.2f,0.2f,1.0f));
	light->setSpotExponent(50.0);
	light->setDirection(osg::Vec3(1,1,-1));
	
	

statelightON_OVRD->setAttribute(light, osg::StateAttribute::ON);
 group->addChild(lightSource);

    





// mtTwo->addChild(loadedModel);
 mtTwo->setStateSet(stateTwoFogON_OVRD);
 loadedModel->setStateSet(stateTwoFogON_OVRD);
// mtTwo->setStateSet(statelightON_OVRD);
 

but Maybve its somewhere else!!!


Cheers!

Jean

  

_______________________________________________ osg-users mailing list [email protected] http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to