oups forget the file :-)

2007/10/23, David Callu <[EMAIL PROTECTED]>:
>
> Hi Riccardo
>
> Linux Fedora 7
> OSG 2.2
> NVidia GeForce 8800
>
>
> All work fine for me.
> I just do "osglight_modified cow.osg"
>
> I join the osglight_modified.cpp simplified and updated to OSG2.2 .
>
> Many bug has be fix and feature added since the OSG 1.2 Version.
> Perhaps an update to OSG 2.2 will be a good choice for you.
>
> HTH
> David
>
>
>
> 2007/10/23, Riccardo Corsi < [EMAIL PROTECTED]>:
> >
> > Hi all,
> >
> > I'm try to get a specular highlights effect by using the
> > osg::LightModel::SEPARATE_SPECULAR_COLOR mode.
> >
> > If I got it straight, this should compute a second color for the
> > specular component to be added after lighting and texturing.
> > So for instance, by using a light with white specular component and on a
> > material with white specular color, I'd expect a white highlight in the
> > final result. Instead what I get is the highlight modulated by the
> > texture, as if I were using osg::LightModel::SINGLE_COLOR mode.
> >
> > Any suggestion on where I might be wrong?
> >
> > Find attached a modified osgLight example to reproduce the problem with
> > a sample model.
> > I basically removed the model animation, set a white specular on the
> > light number 2, and added these lines of code:
> >
> > osg::StateSet* pSS = rootnode->getOrCreateStateSet();
> > // set separate specular color
> > osg::LightModel* pLightModel =new osg::LightModel;
> > pLightModel->setLocalViewer(true);
> > pLightModel->setColorControl(osg::LightModel::SEPARATE_SPECULAR_COLOR);
> > pSS->setAttributeAndModes(pLightModel, osg::StateAttribute::ON
> > |osg::StateAttribute::OVERRIDE);
> >
> > I'm on
> > osg 1.2
> > WinXP
> > nVidia 7900 GTX (tried both older and latest drivers)
> >
> > Thank you
> > Ricky
> >
> >
> >
> > _______________________________________________
> > osg-users mailing list
> > osg-users@lists.openscenegraph.org
> >
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
> >
> >
>
#include <osgViewer/Viewer>

#include <osg/Group>
#include <osg/Node>

#include <osg/Material>
#include <osg/Light>
#include <osg/LightSource>
#include <osg/StateAttribute>
#include <osg/Geometry>
#include <osg/Point>

#include <osg/MatrixTransform>
#include <osg/PositionAttitudeTransform>

#include <osgDB/Registry>
#include <osgDB/ReadFile>

#include <osgUtil/Optimizer>
#include <osgUtil/SmoothingVisitor>

#include <osgViewer/ViewerEventHandlers>

#include <osgGA/TrackballManipulator>
#include <osgGA/StateSetManipulator>


#include <iostream>

// rigky
#include <osg/LightModel>






osg::Node* createLights(osg::StateSet* rootStateSet)
{
    osg::Group* lightGroup = new osg::Group;
    

    // create a spot light.
    osg::Light* myLight1 = new osg::Light;
    myLight1->setLightNum(0);
    myLight1->setPosition(osg::Vec4(10.0f, 10.0f, 10.0f, 1.0f));
    myLight1->setAmbient(osg::Vec4(1.0f,0.0f,0.0f,1.0f));
    myLight1->setDiffuse(osg::Vec4(1.0f,0.0f,0.0f,1.0f));
    myLight1->setSpecular(osg::Vec4(1.0f,1.0f,1.0f,1.0f));

    //    myLight1->setSpotCutoff(20.0f);
    //    myLight1->setSpotExponent(50.0f);
    myLight1->setDirection(osg::Vec3(-1.0f,-1.0f,-1.0f));

    osg::LightSource* lightS1 = new osg::LightSource;    
    lightS1->setLight(myLight1);
    lightS1->setLocalStateSetModes(osg::StateAttribute::ON); 
    lightS1->setStateSetModes(*rootStateSet,osg::StateAttribute::ON);

    lightGroup->addChild(lightS1);

    
    // create marker for point light.
    osg::Geometry* marker = new osg::Geometry;
    osg::Vec3Array* vertices = new osg::Vec3Array;
    vertices->push_back(osg::Vec3(0.0,0.0,0.0));
    marker->setVertexArray(vertices);
    marker->addPrimitiveSet(new osg::DrawArrays(GL_POINTS,0,1));
    
    osg::StateSet* stateset = new osg::StateSet;
    osg::Point* point = new osg::Point;
    point->setSize(4.0f);
    stateset->setAttribute(point);
    
    marker->setStateSet(stateset);
    
    osg::Geode* markerGeode = new osg::Geode;
    markerGeode->addDrawable(marker);
    
    //    lightGroup->addChild(markerGeode);

    return lightGroup;
}


int main( int argc, char **argv )
{
    // use an ArgumentParser object to manage the program arguments.
    osg::ArgumentParser arguments(&argc,argv);

    // set up the usage document, in case we need to print out how to use this program.
    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of OpenGL vertex lighting.");
    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");

    // construct the viewer.
    osgViewer::Viewer viewer(arguments);

    // set up the value with sensible default event handlers.
    //    viewer.setUpViewer(osgViewer::Viewer::STANDARD_SETTINGS);

    // get details on keyboard and mouse bindings used by the viewer.
    viewer.getUsage(*arguments.getApplicationUsage());

    // if user request help write it out to cout.
    if (arguments.read("-h") || arguments.read("--help"))
    {
        arguments.getApplicationUsage()->write(std::cout);
        return 1;
    }

    // any option left unread are converted into errors to write out later.
    arguments.reportRemainingOptionsAsUnrecognized();

    // report any errors if they have occured when parsing the program aguments.
    if (arguments.errors())
    {
        arguments.writeErrorMessages(std::cout);
        return 1;
    }

    // load the nodes from the commandline arguments.
    osg::Node* loadedModel = osgDB::readNodeFiles(arguments);

    // create a room made of foor walls, a floor, a roof, and swinging light fitting.
    osg::Group* rootnode = new osg::Group;
    osg::StateSet* pSS = rootnode->getOrCreateStateSet();

    rootnode->addChild(loadedModel);
    rootnode->addChild(createLights(pSS));

    // run optimization over the scene graph
    osgUtil::Optimizer optimzer;
    optimzer.optimize(rootnode);


    // ricky

#if 1
    // set separate specular color
    osg::LightModel* pLightModel =new osg::LightModel;
    pLightModel->setLocalViewer(true);
    pLightModel->setColorControl(osg::LightModel::SEPARATE_SPECULAR_COLOR);
    pSS->setAttributeAndModes(pLightModel, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
#endif
    // end ricky
     
    // add a viewport to the viewer and attach the scene graph.
    viewer.setSceneData(rootnode);

    

    // add the state manipulator
    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );

    // add the state manipulator
    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
    
    // add the thread model handler
    viewer.addEventHandler(new osgViewer::ThreadingHandler);

    // add the window size toggle handler
    viewer.addEventHandler(new osgViewer::WindowSizeHandler);
        
    // add the stats handler
    viewer.addEventHandler(new osgViewer::StatsHandler);




    viewer.run();

    return 0;
}
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to