Hi, I have some doubts about my approach to create a GL3 non FFP context.

I have compiled osg with all the cmake settings for GL3 as explained in lots of other posts. When I create an object ( a simple two Vertex line ), usual camera manipulation is working without me having writrten a single shader for the vertex tranform. I expect this not to work, is this wrong ? The geode is a child of a osg::PositionAttitudeTransform with a rotation UpdateCallback. This also works, but it shouldn't without Shaders, right ? Moreover, I create a StateSet for the Transform and give it osg::StateSet::Callback to print all uniforms, no osg_ Uniforms ( e.g. osg_ViewMatrix ) get printed out. Is it possible that all this works without FFP ? I guess not. How do I get these default osg_ Uniforms into the StateSet ? The only place where I find code for creaating them is osgUtil::SceneView, which is marked as deprecated.

As the glContextVersion of the GraphicsContext attached to the default camera in the default viewer is 1.0, I use this way I set up the GL3 Context. Please correct me if there is a better way, and if this does creat the required context at all.

osg::GraphicsContext::Traits * traits = new osg::GraphicsContext::Traits() ;

    int width = 1920 , height = 1200 ;
    traits -> x = 0 ;
    traits -> y = 0 ;
    traits -> width  = width ;
    traits -> height = height ;
    traits -> windowDecoration = false ;
    traits -> doubleBuffer = true ;
    traits -> glContextVersion = std::string( "3.3" ) ;

    osg::Camera * cam = new osg::Camera() ;
cam -> setGraphicsContext( osg::GraphicsContext::createGraphicsContext( traits ) ) ;
    cam -> setViewport( 0 , 0 , width , height ) ;
    cam -> setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
    cam -> setClearColor( osg::Vec4( 0.0 , 0.0 , 0.0 , 1.0 ) ) ;
cam -> setProjectionMatrixAsPerspective( 30.0f , ( float )width / ( float )height , 1.0 , 1000.0 ) ;

    viewer.setCamera( cam ) ;

    // This Line::get() is defined bellow
    viewer.setSceneData( Line::get() ) ;


This is the code for the callbacks and the Geometry, as mentined, no Shaders attached, so why does Transformation work ?

    class CBSS_Line : public osg::StateSet::Callback  {

void operator()( osg::StateSet * stateSet , osg::NodeVisitor * nodeVisitor ) { const osg::StateSet::UniformList & uniformList = stateSet -> getUniformList() ;

for( osg::StateSet::UniformList::const_iterator uitr = uniformList.begin() ;
                uitr != uniformList.end() ; ++uitr )  {

            std::cout << uitr -> first << std::endl ;
        }
    }
} ;



class CBN_Line : public osg::NodeCallback  {

void operator()( osg::Node * node , osg::NodeVisitor * nodeVisitor ) { osg::PositionAttitudeTransform * xform = static_cast < osg::PositionAttitudeTransform * >( node ) ; xform -> setAttitude( osg::Quat( nodeVisitor -> getFrameStamp() -> getSimulationTime() * osg::PI , osg::Z_AXIS ) ) ;
        traverse( node , nodeVisitor ) ;
    }

} ;


class Line  {

public :
    static osg::Node * get()  {

osg::ref_ptr< osg::PositionAttitudeTransform > xformLine = new osg::PositionAttitudeTransform() ;
        xformLine -> addUpdateCallback( new CBN_Line ) ;
xformLine -> getOrCreateStateSet() -> setUpdateCallback( new CBSS_Line ) ;

        osg::ref_ptr< osg::Geode > geodeLine = new osg::Geode() ;
        xformLine -> addChild( geodeLine.get() ) ;

        osg::Geometry * geomLine = new osg::Geometry() ;
        geodeLine -> addDrawable( geomLine ) ;

        osg::Vec3Array * vrts = new osg::Vec3Array() ;
        geomLine -> setVertexArray( vrts ) ;

        osg::Vec4Array * rgba = new osg::Vec4Array() ;
        geomLine -> setColorArray( rgba ) ;
        geomLine -> setColorBinding( osg::Geometry::BIND_OVERALL ) ;

        vrts -> push_back( osg::Vec3( 0.0f , 0.0f , 0.0f ) ) ;
        vrts -> push_back( osg::Vec3( 1.0f , 0.0f , 0.0f ) ) ;
        rgba -> push_back( osg::Vec4( 1.0f , 0.0f , 0.0f , 1.0f ) ) ;

geomLine -> addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINES , 0 , 2 ) ) ;

        osg::StateSet * stateSet = xformLine -> getOrCreateStateSet() ;
        stateSet -> setAttributeAndModes( new osg::LineWidth( 5.0f ) ) ;
        stateSet -> setMode( GL_LIGHTING , osg::StateAttribute::OFF ) ;

// Adding an Uniform to test the osg::StateSet::Callback printing function
        stateSet -> addUniform( new osg::Uniform( "Time" , 0.0f  ) ) ;

        // Not created this shader so far
        //osg::Program * program = new osg::Program ;
//program -> addShader( osgDB::readShaderFile( "shader/Line.vert" ) ) ; //program -> addShader( osgDB::readShaderFile( "shader/Line.frag" ) ) ; //stateSet -> setAttributeAndModes( program , osg::StateAttribute::ON ) ;

        return xformLine.release() ;
    }

} ;


Thank you,

Cheers, PP



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

Reply via email to