Basic Soft wrote on Thursday, December 13, 2007 8:40 AM:
> I have found various resources about setting modes for
> light in OSG. But I do not want to use setMode(), but
> getMode(), which is giving me some problems.
> 
> I want to issue a command like the OpenGL
> "glIsEnabled(GL_LIGHT0)" to see if a certain light is
> already active. This is needed to find a "free" light
> number to enable a new light besides the one already
> in the scene. The thing is, the return value from my
> getMode() command is always "8"! Any help is greatly
> appreciated.

"8" means INHERIT; see the StateAttribute::Values enum. It means that
the mode hasn't been set to ON or OFF, in that StateSet. For the root
StateSet, then INHERIT probably means the OpenGL default value, which
would be OFF (IIRC).

> Here is a code fragment:
> 
> osg::StateSet* rootStateSet = root->getStateSet();
> int lightNum = 0;
> osg::StateAttribute::GLModeValue attr =
> rootStateSet->getMode(GL_LIGHT0);
> if(attr==0) {
>       lightNum = 0;
> } else {
>       attr = rootStateSet->getMode(GL_LIGHT1);
>       if(attr==0) {
>               lightNum = 1;
>       } else {
>               attr = rootStateSet->getMode(GL_LIGHT2);
>               if(attr==0) {
>                       lightNum = 2;
>               } else {
>               attr = rootStateSet->getMode(GL_LIGHT3);
>                       if(attr==0) {
>                               lightNum = 3;
>                       }
>               }
>       }
> }

Note to be a code-style Nazi, but wouldn't be shorter to do something
like the following (untested) code?

osg::StateAttribute::GLMode lightModes[] = { GL_LIGHT0, GL_LIGHT1, ...
};
int numLightModes =
sizeof(lightModes)/sizeof(osg::StateAttribute::GLMode);
int lightNum = -1;
for(int light=0; light<numLightModes; light++)
{
        osgStateAttribute::Value lightVal =
rootStateSet->getMode(lightModes[light]);
        if (lightVal == osg::StateAttribute::OFF
                || lightVal == osg::StateAttribute::INHERIT)
        {
                lightNum = lightModes[light];
                break;
        }
}
if (lightNum == -1)
        // ERROR!


-- 
Bryan Thrall
FlightSafety International
[EMAIL PROTECTED]
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to